I try to find a way to implement a Secure SD webserver for control 4 relays and read 2 ultrasonic sensors.
I am using:
Arduino Uno
SR-04 Sensors
and a simple relay shield
Ethernet shield W5100
SD card
I know that are tons of similar projects around here, but I cant find one that implement secure webserver using the SD card, only direct at the arduino.
I know that are tons of similar projects around here, but I cant find one that implement secure webserver using the SD card, only direct at the arduino.
I don't understand this statement. The SD card is ONLY for storing the files to be served. It has nothing to do with the actual process of being a server. An insecure server and a secure server can get the data from anywhere. Using an SD card as the source of the data has NOTHING to do with being a secure server.
PaulS:
I don't understand this statement. The SD card is ONLY for storing the files to be served. It has nothing to do with the actual process of being a server. An insecure server and a secure server can get the data from anywhere. Using an SD card as the source of the data has NOTHING to do with being a secure server.
I know, I just can't find a sample code with authentication and stored at SD card.
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
int led = 4;
const int trigPin = 2;
const int echoPin = 3;
Servo microservo;
int pos = 0;
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 179 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
String readString;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
pinMode(led, OUTPUT);
microservo.attach(7);
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
//ultrasonic stuff
long duration, cm;
// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
cm = microsecondsToCentimeters(duration);
delay(100);
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100) {
//store characters to string
readString += c;
//Serial.print(c);
}
//if HTTP request has ended
if (c == '\n') {
Serial.println(readString); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("<TITLE>MARTELINE PROJECT 47</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>MARTELINE PROJECT 47</H1>");
client.println("<hr />");
client.println("
");
client.println("
");
client.println("<a href=\"/?button1on\"\">Turn On LED</a>");
client.println("<a href=\"/?button1off\"\">Turn Off LED</a>
");
client.println("
");
client.println("
");
client.println("<a href=\"/?button2on\"\">Rotate Left</a>");
client.println("<a href=\"/?button2off\"\">Rotate Right</a>
");
client.println("
");
client.println(cm);
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//controls the Arduino if you press the buttons
if (readString.indexOf("?button1on") >0){
digitalWrite(led, HIGH);
}
if (readString.indexOf("?button1off") >0){
digitalWrite(led, LOW);
}
if (readString.indexOf("?button2on") >0){
for(pos = 0; pos < 180; pos += 3) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
microservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
if (readString.indexOf("?button2off") >0){
for(pos = 180; pos>=1; pos-=3) // goes from 180 degrees to 0 degrees
{
microservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
//clearing string for next read
readString="";
}
}
}
}
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}
It shows what I need in a simple html.
I have no html skills.
What I need is how to move all html things to SD card and implement authentication…
I don’t know if it helps, I am trying to develop a remote generator control, so I grab the code above on internet and I am trying to reach this features:
3 relays (start, transfer LOAD and cutt-off)
1 ultrasonic sensor (fuel measure)
1 servo (acceleration)
I think there are enough tutorials for reading files from a SD card.
For the authentication part:
Now, your HTML code works with so-called ‘GET requests’.
<a href=\"/?button1on\"\">Turn On LED</a>
The simplest way for authentication are ‘POST’ request which are done within ‘’ tags. It’s really easy to add checkboxes or other controls for your relays.
A simple authentication example is found here: HTML Tutorial - Password
On your server you first check the password. If it’s wrong, you just ignore the request.
The data from your checkboxes/password are encoded quite easy. Something like:
password=abc&relay1=true&relay2=false.
You’ll see in your serial monitor.