This project implements a WebSocket server inside a WiFi network provided via ESP32 access point. With the appropriate (and very polite) messages, it will respond with the current temperature readings and turn on/off a green and a red LEDs every 2s (somewhat arbitrary time, but long enough for the DHT readings to work). It was done as a project for the Distributed & Real Time Systems class from Unisinos' Computer Engineering course, as an exercise of defining and implementing a tiny protocol. As per initial definition, the current protocol doesn't have an acknowledgement (ACK) and retry mechanism, making it very fragile. A good exercise would be implementing it accordingly.
- ESP32 Microcontroller (I use ESP32 DEVKIT V1, but anyone must do)
- DHT22 Temperature and Humidity Sensor (or any other compatible device)
- WebSockets
- AsyncTCP and ESPAsyncWebServer (for non-blocking WiFi and WebSocket server)
There are a few external dependencies to be installed:
- DHT-22: Open the Arduino IDE's
Library Manager
(Tools
>Manage Libraries...
) and installAdafruit Unified Sensor
andDHT sensor library
libraries - AsyncTCP and ESPAsyncWebServer: Download the libraries' ZIP files from Github (AsyncTCP, ESPAsyncWebServer), then add them through Arduino IDE (
Sketch
>Include Library
>Add .ZIP Library...
)
Flowchart made on the awesome Whimsical tool.
This project was a stitch from various tutorials I've found. For the ESP32 as a WebSocket server, I was backed up by this tutorial. For the Access Point, this tutorial made the trick. The temperature measurement I've found on this tutorial, and so I must give huge thanks to the Random Nerd Tutorials team.