Hello,
I've moved ahead with my project last discussed here (http://arduino.cc/forum/index.php/topic,110363.0.html). Special thanks to Zoomkat for providing a template to get started.
Now I need some help with the web portion as I know very little about html. My main loop is posted below.
These are some optimizations I'd like to see:
- I currently have to type Hostname:PortNumber/? to do the action I want to do. While it works correctly, it seems sloppy. I'd rather the web page had a button to press that would bring up an InputBox (most of my programming has been with VBA) where I could enter a password to get the action I want. I'm open to other suggestions as well, but I'd like it to be semi-brute force resistant.
- Is there anything else that is particularly sloppy?
void loop(){
// 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;
}
//if HTTP request has ended
if (c == '\n') {
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("<TITLE>DIY Controller Test</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Controller Home Page</H1>");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
///////////////////// control arduino pin
digitalWrite(9, LOW); // set pin 9 low
if(readString.indexOf("controllerpassword") >0)//checks for matching password
{
digitalWrite(9, HIGH); // set pin 9 high
delay(1000);
digitalWrite(9, LOW); // set pin 9 low
}
//clearing string for next read
readString="";
}
}
}
}
}