Week 11: Networking and Communications
Prior Experience: 2/5
I have some experience connecting to WiFi in 6.08, but the WiFi setup/connection code was mostly part of the labs' starter code. I used the WiFi connection to get the live time from the web for a smart clock, to connect to an API for recipes, etc.
The Idea
I decided to work on something that might be useful for my final project, a color changing lamp So, I decided to use my PCB from Week 5 (with a XIAO ESP32C3, a button, and RGB LED), connect it to WiFi, and subsequently connect to a web server that allows you to change the color of the RGB LED. I connected an external antenna to the ESP32C3.
Connecting to WiFi
I followed this guide to set up and connect to WiFi. Specifically, I configured the board to be in Station Mode, since at the moment, there's no need for other microcontrollers to connect to it as an Access Point. First, I went to this link to generate a pre-shared key for the MIT network. Then, I copied the code from the guide above, replacing the SSID and password appropriately. Unsurprisingly, it worked.
Testing the Connection - Adding a Webserver
I added a webserver with a simple dropdown to select the color. Selecting the color changes the color of the RGB LED, communicating over WiFi. On a high level, when a user selects the color, a GET request is sent with the color as a parameter, which then calls a function that takes in the color and writes to the RGB pins to change the color. Here is the code:
The webserver can be accessed by going to the IP address printed in the serial monitor on the web. It works!