This is now an on-going project, however I didn’t have a blog when I started it. So I get to play with WordPress now, and write a middling post about what I started!

One night I had an itch to write something in C since I haven’t done so in quite a while and wanted to do something. I ordered some ESP8266s and ESP32s knowing that they were supported in Arduino which would make my life a little easier staying away from platform-specific things as much as possible. I went to MicroCenter and picked up a few sensors since I’d need some kind of input, and I had some OLED SPI screens laying around.

Now that I had some hardware, I wasn’t sure exactly what I wanted to do. I spent a day working with a BME280 Temp/Humidity/Barometric Pressure sensor and an ePaper display. Not having used ePaper before or realizing exactly how annoyingly and excruciatingly slow it was, I decided to switch over to the much smaller monochrome OLEDs I had.

ESP32 wired through SPI to an OLED 64×64 screen, BME280 sensor and HTU31D sensor

So I had working WiFi, sensor readings that displayed on a screen, all wired up to a prototyping board. Not very useful as it was. Years ago I probably would’ve written something custom to move data from A to B, but since I worked with Solace at my last job I decided to go in a similar direction; I’d use MQTT to transmit the data.

It’s a simple formula and apparently a very common one. It makes sense. I fired up my Solace VM, wrote the little bit of code I needed to use the Arduino MQTT library I’d found and used a web browser to see that I was in fact sending the messages.

My messaging protocol built on top of MQTT is extremely simple, text-based and human readable. JSON was an option, but I didn’t want to waste the ESP8266’s meager RAM resources on anything I didn’t actually need. Aside from that JSON isn’t easy to WRITE, so I would’ve had to spend effort on writing a tool to send messages TO the microcontroller.

Source is available at https://github.com/fdimitri/ESPMQTTSensor. I don’t believe there’s anything particularly clever in there, or particularly bad. It took about 5 days to get this far, but it’s about to go further!

In addition to that, there is an extremely small Ruby program which receives the MQTT messages and pops them into MySQL, which I then took a few minutes in Grafana to make a dashboard:

Grafana Dash

Now that there are sensors, I’ll be able to make a thermostat module with adjustable hysteresis.