Designing Wi-Fi access logic
Imagine taking the hardware prototype we created in the last chapter to a warehouse. Here, you would need to connect the ESP32 to the local Wi-Fi network using the proper SSID and password. After receiving a valid IP address, you would ping a public host to verify internet access and then sync with an NTP server to get accurate clock timing. There are two ways to provide the SSID and password to your device:
- Option 1: Hardcode the SSID and password into the ESP32. This can be accomplished either by including them in the
main.cpp
code or by storing and passing them through thePlatformio.ini
file. - Option 2: Use your mobile phone to assist ESP32 to connect to your local SSID and type in your password.
Option 1 is straightforward and simple but lacks security and flexibility. Option 2 is flexible, secure, and easy to deploy at various sites, but it has a high level of complexity in the code design.
In this project, we’ll use Option...