/* * Demonstrate using an http server and an HTML form to control an LED. * The http server runs on the ESP8266. * * Connect to "http://esp8266WebForm.local" or "http://" * to bring up an HTML form to control the LED connected GPIO#0. This works * for the Adafruit ESP8266 HUZZAH but the LED may be on a different pin on * other breakout boards. * * Imperatives to turn the LED on/off using a non-browser http client. * For example, using wget. * $ wget http://esp8266webform.local/ledon * $ wget http://esp8266webform.local/ledoff */ #include #include #include #include // Fill in your WiFi router SSID and password const char* ssid = "18fileyfibre"; const char* password = "Pcpr0pertie5"; MDNSResponder mdns; ESP8266WebServer server(80); const char INDEX_HTML[] = "" "" "" "" "ESP8266 Web Form Demo" "" "" "" "

ESP8266 Web Form Demo

" "
" "

" "LED
" //"Red
" //"Green
" //"Blue
" "" " " "

" "
" "" ""; // GPIO#0 is for Adafruit ESP8266 HUZZAH board. Your board LED might be on 13. const int LEDPIN = 0; void handleRoot() { if (server.hasArg("LED")) { handleSubmit(); } else { server.send(200, "text/html", INDEX_HTML); } } void returnFail(String msg) { server.sendHeader("Connection", "close"); server.sendHeader("Access-Control-Allow-Origin", "*"); server.send(500, "text/plain", msg + "\r\n"); } void handleSubmit() { String LEDvalue; if (!server.hasArg("LED")) return returnFail("BAD ARGS"); /* LEDvalue = server.arg("LED"); analogWrite(0,LEDvalue.toInt()); LEDvalue = server.arg("gre"); analogWrite(16,LEDvalue.toInt()); LEDvalue = server.arg("blu"); analogWrite(5,LEDvalue.toInt()); server.send(200, "text/html", INDEX_HTML); */ LEDvalue = server.arg("LED"); // Get rid of '#' and convert it to integer long number = strtol( &LEDvalue[1], NULL, 16); // Split them up into r, g, b values long r = number >> 16; long g = number >> 8 & 0xFF; long b = number & 0xFF; analogWrite(0,r); analogWrite(16,g); analogWrite(5,b); server.send(200, "text/html", INDEX_HTML); } void returnOK() { server.sendHeader("Connection", "close"); server.sendHeader("Access-Control-Allow-Origin", "*"); server.send(200, "text/plain", "OK\r\n"); } /* * Imperative to turn the LED on using a non-browser http client. * For example, using wget. * $ wget http://esp8266webform/ledon */ /* * Imperative to turn the LED off using a non-browser http client. * For example, using wget. * $ wget http://esp8266webform/ledoff */ void handleNotFound() { String message = "File Not Found\n\n"; message += "URI: "; message += server.uri(); message += "\nMethod: "; message += (server.method() == HTTP_GET)?"GET":"POST"; message += "\nArguments: "; message += server.args(); message += "\n"; for (uint8_t i=0; i