/* WiFiEsp example: WebServer A simple web server that shows the value of the analog input pins via a web page using an ESP8266 module. This sketch will print the IP address of your ESP8266 module (once connected) to the Serial monitor. From there, you can open that address in a web browser to display the web page. The web page will be automatically refreshed each 20 seconds. For more details see: http://yaab-arduino.blogspot.com/p/wifiesp.html */ #include "WiFiEsp.h" char ssid[] = "GEVAdw"; // your network SSID (name) char pass[] = "********"; // your network password int status = WL_IDLE_STATUS; // the Wifi radio's status int reqCount = 0; // number of requests received WiFiEspServer server(80); void setup() { // initialize serial for debugging SerialUSB.begin(115200); // initialize serial for ESP module Serial.begin(115200); // initialize ESP module WiFi.init(&Serial); // Wait until you open the USB port while(!SerialUSB); // Aspetta che apri la porta USB // check for the presence of the shield if (WiFi.status() == WL_NO_SHIELD) { SerialUSB.println("WiFi shield not present"); // don't continue while (true); } // attempt to connect to WiFi network while ( status != WL_CONNECTED) { SerialUSB.print("Attempting to connect to WPA SSID: "); SerialUSB.println(ssid); // Connect to WPA/WPA2 network status = WiFi.begin(ssid, pass); } SerialUSB.println("You're connected to the network"); printWifiStatus(); // start the web server on port 80 server.begin(); } void loop() { // listen for incoming clients WiFiEspClient client = server.available(); if (client) { SerialUSB.println("New client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); SerialUSB.write(c); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { SerialUSB.println("Sending response"); // send a standard http response header // use \r\n instead of many println statements to speedup data send client.print( "HTTP/1.1 200 OK\r\n" "Content-Type: text/html\r\n" "Connection: close\r\n" // the connection will be closed after completion of the response "Refresh: 20\r\n" // refresh the page automatically every 20 sec "\r\n"); client.print("\r\n"); client.print("\r\n"); client.print("