This week I'm getting back to my OLED clock, and discussing the changes I've made.
Back in late September I made an OLED clock using our OLED Breakout and a ESP32 Thing. At the time, I was able to use the ESP32 to connect to a Network Time Protocol server to get the time, and created an animation of the segments falling off of the display as the time changed.
There were a few things that I didn’t like about where I left the project, though. The main concern was time zones and daylight savings time (DST). Time zones weren’t a big problem, because I only planned on using the clock within the US, and the time zone could be limited to a few selections, but from a global perspective they are not a trivial problem to solve, as Tom Scott explains in this Computerphile episode.
The other problem I had was that I wanted an easy way to configure the WiFi. Originally I had just hard-coded the WiFi, which would have become a problem if I wanted to take it around with me or make more to give away to friends and family. In another clock, I had created a settings webpage where you could connect to the ESP’s access point (AP) and load in the WiFi credentials, but I never bothered to turn off the AP once it was connected to the Internet.
So I turned to you, our customers, to ask your advice on how to solve these problems. And you came through and pointed me to some fantastic libraries. For the time zone issue, Jack Christensen created a time zone library around the TimeLib library, which allows you to define when DST begins and ends. Once it’s defined, the library will look at the date and decide if the time should be standard time or DST.
The other amazing library is the ESP8266/32 WiFi Manager. What I love most about it is how simple it is to use. In your setup function you only need two lines of code:
WiFiManager wifiManager; to initialize the library, and
wifiManager.autoConnect("AP-NAME", "AP-PASSWORD"); to create the AP. Everything else is contained in the library to connect to your AP and save your credentials to the ESP.
If you’d like to build your own, check out the GitHub repository, which has the Arduino code, schematic and .stl files for the case. Oh yeah, did I mention I added a case? It’s not much, just a box really, but it makes it look a bit nicer in my opinion.
Like most projects, there’s still more I’d like to do. One thing I don’t like is that I’m still hard coding the time zone. I’d like to create a simple web page that allows you to select the date or time of the week for DST to begin and end. I also need to adjust the tolerances on the .stl files so the lid and body fit together a little nicer without having to do any sanding, as well as adding a hole for the USB cable to avoid having to take measurements to drill and file the hole.