ESP-01 WiFi Credential Manager
ESP-01 WiFi Credential Manager
If you've played with an ESP-01(s), you know they can be a huge pain! Pull this pin to low on boot to start in programming mode. Pull that pin high on boot to run the installed sketch. Seriously, if you simply give this device power, it neither runs the installed sketch nor allows flashing a new sketch. Oh, and if you have a different version of the ESP-01, there may be other quirks. But if you have the patience to work through all of the quirks surrounding this device, it can be a lot of fun though!
So the big deal here is the WiFi capability. You can put this little guy on a network and spin up a web server so that you can interface with other devices. All that in something with a footprint smaller than a half-dollar. For my first project, I made a pollution sensor, and I used the ESP-01 to serve measurements over the network. It was pretty cool, but I had the WiFi credentials hard-coded in my Arduino sketch which meant that changing any WiFi settings at all required me to crack open my pollution sensor and flash the ESP with an updated sketch containing the new credentials. NOT FUN!
My second ESP-01 project was a garage door sensor. No one wants to go out in -20F (-29C) at night to check and see if the garage door is still open. This time, I decided to do things a little differently. Rather than baking my WiFi credentials into my sketch, I decided to store them in EEPROM (memory that doesn't get erased when the device is power cycled). Is started working on an interface to manage all of this when I came across a post where someone had already done this (https://how2electronics.com/esp8266-manual-wifi-configuration-without-hard-code-with-eeprom/#ESP8266_Manual_Wifi_Configuration_with_EEPROM). I tried it out and decided it was a good start. I took the code I found there, gave it a major facelift and broke it out into its own library. Then I got permission (since it was a derivative work) to put my library up on GitHub.
So what does my library do? It simplifies the process of managing networks on an ESP-01. When the ESP boots, it tries to connect to the saved network (if there is a saved network). If it is unable to find the network and connect within 15 seconds, it drops to access point (AP) mode and spins up a web server. This allows a user to connect directly to the ESP with a WiFi-capable device and select a network that the ESP should connect to. The user enters the password for the selected network, and the ESP reboots and connects to the network if the password was entered correctly. This is all abstracted nicely away into a class so that you can focus on what you want to do within your sketch. Check it out on GitHub!
Comments
Post a Comment