Serving a WiFi hotspot from ESP32
In this homework you will use the ESP32 WiFi capabilities to create a hotspot and serve a HTML webpage from a HTTP server.
Wifi Access Point Sample Code (1 pt)
If you have installed the ESP32 Arduino library, you can open the example code for creating an access point: File -> Examples > Wifi > WifiAccessPoint
Study the code, try to run it, modifying it if necessary. (E.g. change the LED pin number used in the code).
- Note that the baud rate of the Serial printer is different than what we used in the lab. In Serial Monitor, you have to change it accordingly to get output.
- Note how the access point (hotspot) name (SSID) and passwords are configured.
- When changing these values, ensure you use a password with a length of at least 8
The example code will output an IP address to the serial interface. You should be able to connect to the Hotspot created by the ESP32 and access the server from a browser using the IP shown in the serial console (usually 192.168.4.1). Try viewing the webpage from either your laptop or phone. (e.g. http://192.168.4.1)
Displaying Sensor Values
Make the following changes
- Make the code use an external LED (such as the one we used in lab), instead of the boards internal LED. (2 pts)
- Update the HTML that the code outputs to clients:
- In addition to displaying the <a> links for controlling the LED, it also reads the current value of the Photoresistor. (2 pts)
- If the value is updated upon every browser refresh, that's sufficient.
Important:
- Some of the ADC pins of ESP32 are not usable together with WiFi. For example, pin D2, which we used in the lab for the sensor, corresponds to ADC2_2 and will not work together with WiFi.
- For a full overview of pins, you can refer here
- The ADC1_ pins are still usable (such as ADC1_6, marked as D34 on the board), however they are located on the opposite side of the board compared to what we worked with in the lab.
Since space on our breadboard is limited, you can use the following 'trick' to use for example pin D34. The idea is to use the part of the breadboard which is under the ESP32. By bending one of the jumper wire ends, you can run wires underneath without interfering with the microcontroller.
Submission:
- Run the solution and connect to the hotspot (either with phone or laptop).
- Record a video where the ESP32 with LED button is visible, and demonstrate the solution running by:
- Showing that the current sensor value is shown in the webpage, and that the value changes when refreshing the page.
- Showing that the external LED reacts to the webpage link click (not in-built LED!)