A little while back I heard of WebThings Gateway and it seemed like something fun to try with hosting on my Raspberry Pi B+, and then maybe add some ESP8266 connected temperature sensors.
What I did
I installed the Raspberry Pi version of the WebThings Gateway, which was very straightforward. There’s an option to make it Internet connected with a `.webthings.io` domain, but I decided to keep it local.
Then it came to connecting temperature sensors to the WeMos D1 Mini boards I have. With the first one I made, I opted for the slightly cheaper DHT11 as a proof of concept to see if it would even work as I hoped. For the second iteration, I purchased the slightly more expensive (but also slightly more accurate) DHT22. Both of these sensors provide both temperature and humidity readings.
They are accessible using the WebThings Framework for Arduino and nicely slotted into the Gateway dashboard.
The Gateway also has logging built-in so it’s possible to see trends across a few days.
What problems did I come across?
- Finding a WebThings library for the D1 Mini: This took a lot longer than I had anticipated and was eventually resolved through trial and error using a couple of different libraries.
- Incorrect/Invalid readings on the DHT11: The readings from the DHT11 were frequently weird (e.g., 120%, -12°C), and initially I implemented a software solution to check for these readings and ignore them.
- No readings on the DHT22: When I tried to reuse the code from the DHT11 sensors it didn’t work for the DHT22, so I had to use a different library. (Appears to be a timing issue.) This then also resolved the strange readings from the DHT11 sensor.
Code for the DHT11 and DHT22 sensors
The code for the sensors can be found on GitHub, together with a list of required dependencies.
- WeMos D1 Mini (ESP8266-based board)
- DHT11/22 sensor
- 3 Jumper cables
- 170 tie points mini breadboard (optional)