Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:espressif_es8266_http_led_control [2023/10/10 08:26] ktokarzen:iot-open:espressif_es8266_http_led_control [2023/11/23 10:46] (current) pczekalski
Line 1: Line 1:
 +====== Controlling LED with Simple Web Server ======
 +{{:en:iot-open:czapka_b.png?50| General audience classification icon }}{{:en:iot-open:czapka_e.png?50| General audience classification icon }}\\
 +A sample Web application hosted on ESP8266 MCU is presented below.\\
 +This application allows it to control the state of the LED remotely, connecting to the ESP8266 board with a web browser. The program presented is based on the example "HelloServer" available in the ''ESP8266WebServer'' library. Some modifications were made to simplify the program and to handle requests to turn the LED on and off. To check if it works, adding WiFi network credentials and setting the ''led'' constant with the number of GPIO to which the LED is connected is required. After a successful connection to the WiFi, ESP8266 would present through the serial monitor the IP address (e.g. 192.168.4.1). Writing in the address bar in the browser "HTTP://192.168.4.1" should return the serial monitor message "hello from esp8266!".\\
 +
 +Assuming the address in the terminal is ''192.168.4.1'' one may use the following URLs to disable and enable the LED, respectively:
 <code> <code>
 +http://192.168.4.1/LED0 
 +http://192.168.4.1/LED1 
 +</code>
 +
 +<code c>
  
 #include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
Line 20: Line 31:
 void handleRoot() { void handleRoot() {
   //Originally LED was controlled for every root request   //Originally LED was controlled for every root request
-  //so we had to comment two lines below+  //so it is required to comment the lines which modify the LED state
   //digitalWrite(led, 1);   //digitalWrite(led, 1);
   server.send(200, "text/plain", "hello from esp8266!\r\n");   server.send(200, "text/plain", "hello from esp8266!\r\n");
Line 27: Line 38:
  
 void handleNotFound() { void handleNotFound() {
-  digitalWrite(led, 1);+  //digitalWrite(led, 1);
   String message = "File Not Found\n\n";   String message = "File Not Found\n\n";
   message += "URI: ";   message += "URI: ";
Line 40: Line 51:
   }   }
   server.send(404, "text/plain", message);   server.send(404, "text/plain", message);
-  digitalWrite(led, 0);+  //digitalWrite(led, 0);
 } }
  
 void setup(void) { void setup(void) {
   pinMode(led, OUTPUT);   pinMode(led, OUTPUT);
-  digitalWrite(led, 0);+  //digitalWrite(led, 0);
   Serial.begin(115200);   Serial.begin(115200);
   WiFi.mode(WIFI_STA);   WiFi.mode(WIFI_STA);
en/iot-open/espressif_es8266_http_led_control.1696926418.txt.gz · Last modified: 2023/10/10 08:26 by ktokarz
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0