ESP8266 ESP-01 and IoT of LED — Part 3

Mudassar Tamboli
3 min readJul 2, 2018

--

Series : Part 1, Part 2 , Part 3, Part 4

In Part 2 we implemented ESP-01 as a simple HTTP client and controlled the LED through it. In this article i will show how to implement ESP-01 as HTTP Webserver and get commands from the client directly. We are relieved off polling for commands as was the case in the client implementation in Part 2.

ESP-01 As Station and HTTP Web Server

Here the idea is to implement ESP-01 as a HTTP Web server and take LED commands via URL paths.

Lets go over the Arduino code.

The above code implements the following

  1. ESP8266–01 acts as station and is connected to an access point. See initWifiStation();
  2. ESP8266WebServer “server” C++ object is created to listen on port 80. The Callback functions are registered against the URL paths.

handlePlainRoot() is called on “/plain”. It provides LED status.

handlePlainGpio2On is called to turn LED ON on “/plain/GPIO2/ON”

handlePlainGpio2Off is called to turn LED OFF on “/plain/GPIO2/OFF”

3. WiFi.localIP() is the IP provided by the DHCP server. We can get this ip address by running “arp -a” in the command prompt

Windows arp command shows ip of ESP8266 station
Serial print shows ESP8266 station’s ip address

Web browser client accessing ESP8266 http server

Web Browser fetching ESP8266 http server URL to get and set LED status

Fancy HTML output

Instead of typing the URL, its easier to click on link and set the LED on and off. In the code below, “page not found” error is handled by server.onNotFound;

Fancy HTML output from ESP8266 http server in Station mode

ESP-01 As Access Point and HTTP Web Server

ESP8266 as AP only and HTTP Web server

A few additional code is required to make ESP as access point and still act as a web server

AP IP address 192.168.4.1 as seen in command prompt and serial print

Sources

Project: ESP8266-ESP-01-WebServer

Conclusion

This article demonstrated the working of ESP8266 in Station and AP mode. LED is turned on and off using different URL paths. A fancy html is generated by the ESP web server with HREF links to ease the user’s interface with the LED

Series : Part 1, Part 2 , Part 3, Part 4

--

--

Mudassar Tamboli

AWS Certified Solutions Architect, IoT enthusiast, Entrepreneurial Thinker, Polyglot programmer