X-Git-Url: http://git.piffa.net/web?p=sketchbook_andrea;a=blobdiff_plain;f=iot%2Fblink_iot%2Fblink_iot.ino;fp=iot%2Fblink_iot%2Fblink_iot.ino;h=2172b9dd9cede80271fdd2b9e1d32cd52e22b1f3;hp=0000000000000000000000000000000000000000;hb=b4d82b0010d746f1a0f0b4da698b26d217f1ab1f;hpb=c5a3dc4a9cc7eea224814fee4b00575e726105fa diff --git a/iot/blink_iot/blink_iot.ino b/iot/blink_iot/blink_iot.ino new file mode 100644 index 0000000..2172b9d --- /dev/null +++ b/iot/blink_iot/blink_iot.ino @@ -0,0 +1,77 @@ +/* + * 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()); + +} + +