Temperature logger with NodeMCU

arnetemp-6hLast Sunday, Dad called. He wanted to discuss different meters to help him measure the temperature of the heat exchanger’s inlet and outlet, because the efficiency of the heat pump seems to have worsened the last few years. He explained that over time, dirt build up inside the heat exchanger and isolates the circuits from each other. If you would measure the temperature differences between the warm (outside) circuit’s inlet and the cold (inside) circuit’s outlet, a more efficient transfer warms the cold circuit up more, minimizing the difference.

This write-up explains how I built it, and represents my first experience with NodeMCU.

DS18B20A few years ago, I worked a bit with Maxim’s DS18S20 1-wire sensors, so my mind went off in that direction while he sent links to different meters of varying quality and precision. Graphing the temperature over time really helps to spot trends, and I could picture my dad crouching over the pipes for hours waiting for the next cycle of the heat pump with a notepad where he noted measured temperatures.
113990105 1For some time, I’ve been looking for uses of the small WiFi-enabled microcomputer that uses the ESP8266 chip that was dubbed NodeMCU. It’s both a firmware for the ESP8266 chip and a development board. It’s easily available here in Stockholm, sold by kjell.com online and in their stores. While I was there, I also picked up a nifty 0.96″ OLED display that uses the two-wire I2C interface that Philips invented many decades ago.

The idea was now clear to me: I would create a NodeMCU-based temperature logger with a built-in display. It would be connected to the Internet via WiFi and would send the current measured temperature every few seconds to a server, which would log the temperatures to a Round-Robin Database (RRD) called RRDtool. The DS18B20 sensors do the temperature sensing.
IMG_2118I set off searching for places where someone had already used the OLED display with NodeMCU. I found this WiFi scanner blog post and connected the display the same way: I2C SCL on the display, to the D6 pin on the NodeMCU and the SDA pin to D5. I let the display be powered by the 3.3V rail exposed by, and last I connected a three black/red/white wire cable to connect the sensors. The 1-wire sensors are easier to interface with if they are powered, so I let the red wire carry the 3.3V from the NodeMCU to the sensors.

printed boxI downloaded ESPlorer so that I would have a tool to upload code to the NodeMCU (and installed the required drivers). After loading in the WiFi scanner Lua code into my NodeMCU, bam I had a working WiFi scanner! Surprised by the ease of this, I designed a quick box for the display and NodeMCU and printed it. It snapped in tightly so my original plan of melting the pins to permanently install the display into the case was scrapped.

IMG_2120_croppedI learned a few things while trying out Lua on the NodeMCU for the first time. First, I learned that it was a bad idea to create a method that wouldn’t return until it had successfully associated with dad’s WLAN.


I figured the reason it doesn’t work must be that a Lua is single-threaded,
much like JavaScript, and needs to have its internal loop run in order to update the connection status variables. It started working when I changed the code into this, and put it in a separate file:

Later I learned that this code is quite unforgiving of mistakes. An error in your code would throw the NodeMCU in an uninterruptible reboot loop, needing a complete firmware reflash to recover. My current revision of the init.lua thus became:

After evolving the NodeMCU DS18B20 sample code, merging it with the WLAN scanner code, as well as merging in a UDP client, I now have a temperature logger that simultaneously measures any/all connected sensors, gathers the values from each of them, creates a Lua table and uses the CJSON module to convert it into a JSON data format. Then it fires it off to my little Perl script on my server that puts it into an RRD.

This is how it turned out:




3 thoughts on “Temperature logger with NodeMCU”

  1. Hi,

    Very nice project! I am particular interested in the box that you printed. One of the things I am having issues with is finding a well fitting box. Your was printed I understand. Are the design files open source? If so, can you tell me where I can find them?

    Thanks so much!

    Gr. Jos

Leave a Reply

Your email address will not be published. Required fields are marked *