]> git.piffa.net Git - sketchbook_andrea/blob - iot/blink_iot/blink_iot.ino
PWM correzione
[sketchbook_andrea] / iot / blink_iot / blink_iot.ino
1 /*
2  * Blink IoT
3
4 This sketch is meant to run on a ESP8266 chip
5 (NodeMCU like), not on a AVR Arduino board.
6
7 */
8
9 #include <ESP8266WiFi.h>
10 #include "html.h"
11 void connessione() ;
12
13 //int ledPin = LED_BUILTIN; // GPIO13
14 int ledPin = 2; // GPIO2 on LoLin Nodemcu
15 WiFiServer server(80);
16
17 void setup() {
18   Serial.begin(115200);
19   delay(10);
20
21   pinMode(ledPin, OUTPUT);
22   digitalWrite(ledPin, HIGH); // OnBoard LED is inverted
23
24   connessione();
25 }
26
27 void loop() {
28   // Check if a client has connected
29   WiFiClient client = server.available();
30   if (!client) {
31     return;
32   }
33
34   // Wait until the client sends some data
35   Serial.println("new client");
36   while (!client.available()) {
37     delay(1);
38   }
39
40   // Read the first line of the request
41   String request = client.readStringUntil('\r');
42   Serial.println(request);
43   client.flush();
44
45   // Match the request
46
47   int value = LOW;
48   if (request.indexOf("/ON") != -1)  {
49     digitalWrite(ledPin, LOW);
50     value = HIGH;
51   }
52   if (request.indexOf("/OFF") != -1)  {
53     digitalWrite(ledPin, HIGH);
54     value = LOW;
55   }
56
57   client.println(head);
58   client.println(body);
59   if (value == HIGH) {
60     client.print("<div class=\"alert alert-info\">Led pin is now: <strong>On </strong></div>");
61   } else {
62     client.print("<div class=\"alert alert-warning\">Led pin is now: <strong>Off </strong></div>");
63   }
64
65
66
67   //client.println(FPSTR(footer)); // This is to damm slow!!
68   // See http://arduino-esp8266.readthedocs.io/en/latest/PROGMEM.html
69    client.println((footer));
70  
71   delay(1);
72   Serial.print("Client disonnected. Millis: ");
73   Serial.println(millis());
74
75 }
76
77