/* * Blink IoT This sketch is meant to run on a ESP8266 chip (NodeMCU like), not on a AVR Arduino board. */ #include #include "html.h" void connessione() ; //int ledPin = LED_BUILTIN; // GPIO13 int ledPin = 2; // GPIO2 on LoLin Nodemcu WiFiServer server(80); void setup() { Serial.begin(115200); delay(10); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); // OnBoard LED is inverted connessione(); } void loop() { // Check if a client has connected WiFiClient client = server.available(); if (!client) { return; } // Wait until the client sends some data Serial.println("new client"); while (!client.available()) { delay(1); } // Read the first line of the request String request = client.readStringUntil('\r'); Serial.println(request); client.flush(); // Match the request int value = LOW; if (request.indexOf("/ON") != -1) { digitalWrite(ledPin, LOW); value = HIGH; } if (request.indexOf("/OFF") != -1) { digitalWrite(ledPin, HIGH); value = LOW; } client.println(head); client.println(body); if (value == HIGH) { client.print("
Led pin is now: On
"); } else { client.print("
Led pin is now: Off
"); } //client.println(FPSTR(footer)); // This is to damm slow!! // See http://arduino-esp8266.readthedocs.io/en/latest/PROGMEM.html client.println((footer)); delay(1); Serial.print("Client disonnected. Millis: "); Serial.println(millis()); }