#include ////////////////////// // WiFi Definitions // ////////////////////// const char WiFiAPPSK[] = "sparkfun"; // Avant la connexion au réseau local // Se connecter au réseau ESP8266 Thing **** Qui apparait dans // la liste des réseau WIFI // sur l'adresse IP http://192.168.4.1/ char* ssid = "Livebox-37cc"; // Le nom de votre réseau Wifi char* pass = "8A6060920A8A86896F770F2C47"; WiFiServer server(80); void setup() { initHardware(); setupWiFi(); server.begin(); } void loop() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Read the first line of the request String req = client.readStringUntil('\r'); Serial.println(req); // client.flush(); // Match the request int val = -1; // We'll use 'val' to keep track of both the // request type (read/set) and value if set. if (req.indexOf("/led/0") != -1) val = 0; // Will write LED low else if (req.indexOf("/led/1") != -1) val = 1; // Will write LED high else if (req.indexOf("/read") != -1) val = -2; // Will print pin reads else if (req.indexOf("/admin") != -1) val = -3; else if (req.indexOf("/ident") != -1) { val = -4; // Return : ident?name=jjjjj&pass=kkkk&H= int Pos_r = req.indexOf("name"); int Pos_g = req.indexOf("pass", Pos_r); //finds a location of a string "g", after the position of "r" int End = req.indexOf("H", Pos_g); if(End < 0){ End = req.length() + 1; } //ssid ssid = getValueFrom(req, Pos_r, Pos_g); //Password pass = getValueFrom(req, Pos_g, End); } // Otherwise req will be invalid. We'll say as much in HTML client.flush(); // Prepare the response. Start with the common header: String s = "HTTP/1.1 200 OK\r\n"; s += "Content-Type: text/html\r\n\r\n"; s += "\r\n\r\n"; if (val == -3) { // client.println("
Set the color and then choose an animation:"); // client.println("

Red: "); //was onchange event // client.println("0"); // client.println("\r\n"); // client.print("

Green: "); // client.print("

Blue: "); // client.println(" 



"); //
// client.println(""); // client.println("\r\n"); // client.println("
"); // client.println(""); client.println(""); client.println("
"); client.println("\r\n"); client.println("
"); client.println(""); client.println(""); client.println("
"); client.println("
"); client.println(" "); client.println(" "); client.println("
"); client.println("
"); client.println(" "); client.println("
"); client.println("
"); client.println(""); } else { s += "Invalid Request.
Try /led/1, /led/0, or /read /admin."; } s += "\n"; // Send the response to the client client.print(s); delay(1); Serial.println("Client disonnected"); // The client will actually be disconnected // when the function returns and 'client' object is detroyed } void setupWiFi() { WiFi.mode(WIFI_AP); // Do a little work to get a unique-ish name. Append the // last two bytes of the MAC (HEX'd) to "Thing-": uint8_t mac[WL_MAC_ADDR_LENGTH]; WiFi.softAPmacAddress(mac); String macID = String(mac[WL_MAC_ADDR_LENGTH - 2], HEX) + String(mac[WL_MAC_ADDR_LENGTH - 1], HEX); macID.toUpperCase(); String AP_NameString = "ESP8266 Thing " + macID; char AP_NameChar[AP_NameString.length() + 1]; memset(AP_NameChar, 0, AP_NameString.length() + 1); for (int i=0; i