Yesterday, I spent a lot of time developing the front end of the thermostat. I was already logging temperature, pressure and humidity to my PC over serial but that doesn't really give me any good use right now.
One of the goals of this project is to display all three sensor values over time. That also meant, knowing what time it actually is.
I ran into a couple hours of issues with one of the functions needed to format time_t until I finally found a clue I might be running an old ESP for Arduino library. I could not use strftime() [String From Time]! It was not defined no matter what I did. The solution was simple: I needed to update to the latest ESP for Arduino libraries. To do that I went to the Library Manager, let it update itself and then select Updatable under Type. This showed me the ESP library can be updated (it was very old). After doing so, my entire compile and flash toolchain changed and strftime() finally worked!
Now that I could connect to my WiFi, I was able to connect to an NTP server to ask for the current time. I modified the response to match my timezone and created a status bar. The status bar also includes a connection quality bar graph based on the current RSSI value from the WiFi modem.
I then went ahead and started displaying some numbers. I must say, I REALLY like the new eTFT library as it also allows to define a background for a font! It's not just extremely fast, but also draws right over existing pixels for the entire block of a character. That means, I don't need to first delete the old character to draw a new one in its place. I can directly draw the new character with a black background. Since this happens really fast, I don't get any flicker at all. On top of that, characters are being drawn one at a time. When I deleted old ones manually, I deleted the entire sentence and then drew the new one! This usually resulted in minimal flicker.
As an added bonus of this environment monitoring feature, I wanted to draw graphs for temperature, pressure and humidity. This is really easy with a display that has its own memory because one can just draw pixels as desired and leave them there.
In my case, I convert each sample for temperature, pressure, and humidity into a range that I find interesting and then break it down into a range of 0 to 60 pixels in height and 0 to 125 pixels in width.
The dotted line is center: 20 degrees C, 50% humidity, 1013mb in pressure.
At midnight, I flush the graph and redraw the visualization. So every day starts with a fresh graph. In a later version, I would like to redraw the sensor values in a darker color kind of as a ghost graph to be able to see changes over time. One or two days in the past should suffice.
At this point, the system was running pretty well. However, I encountered an issue where the WiFi would connect but the time would not be updated. The update function claims to have a new, valid time but it reports 8AM 1970. Also, I wanted to be able to understand what's happening during startup when I don't have a laptop serial console connected to it.
So I created a small ring buffer that allows me to simulated a Linux console. During boot, the console gets filled with debugging information like what it is connected to, if all the sensors (one) are properly detected, and what the first couple sensor values are. With the old Adafruit library, this would have been impossible from a performance point of view. With the new eTFT library, you don't even notice there is any display lag what so ever. In other words, this runs REALLY well for a small console on a 128x160 screen.
As a bonus, I will add word-wrap to the console such that longer console entries are possible without writing off screen. I developed this function for some other project a long time ago but never really got around to using it. It's not strictly necessary but it adds a nice touch to it and makes the console more reusable for other projects.