Why you want it
As you probably know, I am addicted to Diet Coke, every few months I get a delivery of a four month supply of this wonderful drink.
It is a bit of a shlep to get all the Coke into the basement, so I wondered whether I could store it in the garage. Wouldn’t it be too cold in winter? I don’t think we have below freezing temperatures in there, but honestly I never went to check temperatures at 4:00 am in February. Also, wouldn’t it be too hot in summer?
With today’s technical means, these questions should be a piece of cake to solve. A temperature sensor for a few bucks, then hooking it up to power and maybe an ethernet cable… or wifi… — ok, maybe not as simple as I thought.
But then one can buy this stuff ready-made. Nice temperature sensors are out there, often coming with a beautiful casing, an easy to read screen, batteries, wifi — and a rather hefty $70 price tag. What? I the meantime I had devised a ton more options where I might need to measure temperature and had arrived at a point where 10 sensors didn’t suffice. But paying $700+ for all this? Insane!
I looked into Raspberry Pi computers, or even very small Raspberry Pi Zero W computers, coming with WiFi and everything I need. Except that (for the Pi Zero) „due to high demand we’re only selling ONE per customer“ . What a nuisance! Looking further, I found Arduino micro-controllers, essentially little computers that run one program only, could do the job at half price compared to the Pi Zero. And sure enough, there was a solution to my problem right there: https://www.losant.com/blog/getting-started-with-the-esp8266-and-dht22-sensor .
What to watch out for
I bought some of the necessary stuff ( https://shopofthings.ch ) and set to work. Following the instructions accurately is a good idea, but 2 items cost me a bit of time:
As part of the initial setup, the instructions ask you to follow
Environment Setup Instructions
. On that page you’re asked to install additional libraries, the first one being called „PubSubClient“. Don’t install from here — if you already did, simply delete it from the files in the Arduino subfolder on your disk and re-start the Arduino IDE.
Why? Well, you’re being told to make changes to the PubSubClient by following the instructions on https://forums.losant.com/t/sending-commands-with-larger-payloads/135 :
- Open the pubsubclient.h file from the Arduino libraries folder. On a Mac, this will be located at ~/Documents/Arduino/libraries/pubsubclient/src/PubSubClient.h
- Edit the MQTT_MAX_PACKET_SIZE to something larger. Increasing it to 256 seems to work pretty well.
Recompile and reupload the firmware to the device.
However, I had no idea what to do with the final part of these instructions ( „ Recompile and reupload the firmware to the device.“ ). Recompile?
The low-tech solution is to go to https://github.com/knolleary/pubsubclient/releases/tag/v2.7 and download the zipped library there. Then unzip it and make the changes as described, re-zip the package and then add it manually in the Arduino IDE software in Sketch/Include Library/Add .ZIP Library
- The next library you’re supposed to install is „the latest version of ArduinoJson“ . Which I did, installing version 6.4.0-beta. However, in the accompanying picture of the instructions, version 5.13.2 is highlighted — and you have to use a 5.x.x version, otherwise it will not work. (see https://arduino.stackexchange.com/questions/54373/nodemcu-arduino-ide-dynamicjsonbuffer-was-not-declared-in-this-scope
And there I am: Logging temperature and humidity happily for less than $20 per device. (The micro-controller and sensor were $15, but you need a micro-USB cable and a USB charger as well if want to measure temperature elsewhere…)