String webdata = ""; class DummyWebServer { public: String arg(String name); // get request argument value by name protected: }; String DummyWebServer::arg(String arg) { #ifdef DEBUG_WEB2 Serial.print("webdata3:"); Serial.println(webdata); #endif arg = "&" + arg; #ifdef DEBUG_WEB2 Serial.print("arg:"); Serial.println(arg); #endif String returnarg = ""; int pos = webdata.indexOf(arg); if (pos >= 0) { returnarg = webdata.substring(pos+1,pos+81); // max field content 80 ? pos = returnarg.indexOf("&"); if (pos > 0) returnarg = returnarg.substring(0, pos); pos = returnarg.indexOf("="); if (pos > 0) returnarg = returnarg.substring(pos + 1); } return returnarg; } DummyWebServer WebServer; void WebServerHandleClient() { EthernetClient client = MyWebServer.available(); if (client) { #if socketdebug ShowSocketStatus(); #endif // an http request ends with a blank line boolean currentLineIsBlank = true; String request = ""; boolean getrequest = true; webdata = ""; webdata.reserve(500); while (client.connected()) { if (client.available()) { char c = client.read(); if (getrequest) request += c; #ifdef DEBUG_WEB Serial.write(c); #endif // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // request is known here, in case of 'rules' we could handle this smarter (save index+6)? while (client.available()) { // post data... char c = client.read(); webdata += c; } if (webdata.length() !=0) webdata = "&" + webdata; #ifdef DEBUG_WEB Serial.print("webdata0:"); Serial.println(webdata); Serial.print("len:"); Serial.println(webdata.length()); #endif int pos = request.indexOf("/"); if (pos > 0) request = request.substring(pos + 1); pos = request.indexOf(" "); if (pos > 0) request = request.substring(0, pos); pos = request.indexOf("?"); if (pos >= 0) { String args = request.substring(pos + 1); webdata += "&" + args; request = request.substring(0, pos); } webdata = URLDecode(webdata.c_str()); #ifdef DEBUG_WEB Serial.print("webdata1:"); Serial.println(webdata); #endif if (request.startsWith(F(" HTTP")) or request.length() == 0) // root page { addHeader(true, client); handle_root(client, webdata); } else if (request.equals(F("control"))) { handle_control(client, webdata); } else if (request.equals(F("config"))) { addHeader(true, client); handle_config(client, webdata); } else if (request.equals(F("hardware"))) { addHeader(true, client); handle_hardware(client, webdata); } else if (request.equals(F("devices"))) { addHeader(true, client); handle_devices(client, webdata); } else if (request.equals(F("rules"))) { addHeader(true, client); handle_rules(client, webdata); } else if (request.equals(F("tools"))) { addHeader(true, client); handle_tools(client, webdata); } else if (request.equals(F("advanced"))) { addHeader(true, client); handle_advanced(client, webdata); } else if (request.equals(F("SDfilelist"))) { addHeader(true, client); handle_SDfilelist(client, webdata); } else if (request.equals(F("i2cscanner"))) { addHeader(true, client); handle_i2cscanner(client, webdata); } else if (request.equals(F("log"))) { addHeader(true, client); handle_log(client, webdata); } else if (request.equals(F("sysinfo"))) { addHeader(true, client); handle_sysinfo(client, webdata); } else handle_unknown(client, request); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; getrequest = false; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(1); client.stop(); webdata = ""; } } //******************************************************************************** // Add top menu //******************************************************************************** void addHeader(boolean showMenu, EthernetClient client) { client.println(F("HTTP/1.1 200 OK")); client.println(F("Content-Type: text/html")); client.println(F("Connection: close")); // the connection will be closed after completion of the response client.println(); String str = ""; boolean cssfile = false; str += F(""); str += F("