Async-Webserver for ESP 01 S devboard
This project demonstrates how to control relays using an ESP 01 S devboard that runs Asynchronous web server. The code allows you to toggle the relays' state through a web interface, making it easy to control devices remotely.
- Arduino IDE
- ESP 01 S devboard
- Two-channel relay module
Access the web server using the IP address shown in the Serial Monitor. The web page will display two toggle switches for each relay. You can toggle the switches to turn the relays on or off.
- Connect your ESP 01 S devboard to your computer.
- Open the Arduino IDE and install the required libraries:
- Arduino Core for ESP8266 (should be installed by default for ESP8266 boards)
- ESP8266WiFi library
- ESPAsyncTCP library
- ESPAsyncWebServer library
- Replace the placeholders in the code with your Wi-Fi credentials (
ssid
andpassword
). - Upload the sketch to your ESP8266 board.
- Open the Serial Monitor to see the connection status and IP address.
- Connect your relays to the respective GPIO pins (Relay1 -> GPIO 2, Relay2 -> GPIO 0).
The code sets up an asynchronous web server on port 80, allowing you to access it through your web browser. The server serves an HTML page with two toggle switches, one for each relay. When you toggle the switches on the web page, it sends a request to the ESP8266 to update the relay state. The relays' output pins are set to either HIGH or LOW, depending on the state received from the web page.
connectify(const char* network, const char* pass)
: Connects the device to the specified Wi-Fi network.outputState(int output)
: Checks the state of the given output (relay) and returns the corresponding "checked" or empty string for HTML rendering.processor(const String& var)
: Custom processor function to render the HTML page with the relay status switches.setup()
: Initializes the output pins, connects to Wi-Fi, and starts the web server to serve the HTML page.loop()
: Empty loop as the server operates asynchronously.
- Aman Shaikh
- Contact: amanshaikhw@gmail.com
This project is licensed under the MIT License.