My dad and I are trying to automate the shop using the arduino Uno and the ethernet shield. I've been trying for two days now to figure out why I can't get a reply from "http://.../?firmver" when we request it from the arduino.
Most of the commands won't need to return a value back to the requesting browser, but the firmver and similar commands have places in our web interface that they need to return data. Can someone help and enlighten me as to why this isn't working when "/?firmver" is requested? I'm really new to using the ethernet networking with arduino, but have a few things under my belt, but this isn't quiet making sense to me.
Code:
//base code from LED ethernet sketch
//modified code by BleedinSarge, customized for ShopMatic application
//NOTE: the web interface is hosted elsewhere due to flash size limits.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 177 }; // ip in lan
byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //http server
String httpRequest;
//string used to parse command from a browser
void setup(){
//am limited on IO due to the network card using 4, 10, 11, 12, and 13
pinMode(2, OUTPUT); //this pin controls central air
pinMode(3, OUTPUT); //this pin controls outside lights
pinMode(5, OUTPUT); //this pin controls inside lights
pinMode(6, OUTPUT); //this pin controls black lights
pinMode(7, OUTPUT); //not used yet, goes to mood lights...speaking of, one needs to buy more halogen bulbs...
pinMode(8, OUTPUT); //not used for now
pinMode(9, OUTPUT); //not used for now
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
//the pin for the servo co
//enable serial data print
Serial.begin(9600);
Serial.println("ShopMatic testing firmware");
//need to know which arduino im using, since two are normally connected to my mech
}
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 (httpRequest.length() < 80) {
}
//if HTTP request has ended
if (c == '\n') {
///////////////
Serial.println(httpRequest); //print to serial monitor for debuging
client.println("HTTP/1.1 200 OK"); //send new page, i keep this page blank for security reasons...no info, boring target to mess with
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE></TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<hr />");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
delay(2);
client.stop();
//give time for receiving..not like im sending alot
///////////////////// control arduino pin
if(httpRequest.indexOf("?lighton") >0)//turn on outside lights
{
digitalWrite(3, HIGH); //9, stand!
httpRequest="";
}
else{
if(httpRequest.indexOf("?lightoff") >0)//turn off outside lights
{
digitalWrite(3, LOW); //9, duck!
httpRequest="";
}
else{
if(httpRequest.indexOf("?firmver") >0)//did we get a firmware version request?
{
client.connected(); //client gotta connect to get data, right?
client.println("HTTP/1.1 200 OK"); //send new page, i keep this page blank for security reasons...no info, boring target to mess with
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE></TITLE>");
client.println("<h2> 0.1.0 </h2>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<hr />");
client.println("
");
client.println("</BODY>");
client.println("</HTML>");
client.stop();
httpRequest=""; //make sure to empty this string
}
}
//clearing string for next read
httpRequest="";
}
}
}
}
}
}