Wireless thermo-hygrometer
Final Steps
Now you need to integrate the messages of the MQTT server into the Node-RED flow. You can do this directly via the Node-RED interface. To do so, start the input node by typing mqtt and configure it to receive messages from the topic of one sensor (/home/sensor1). To create the input node, you need to define an MQTT server (Figure 6).
So the Node-RED can process the sensor data, the JSON strings need to be converted to JavaScript objects. Because this type of conversion occurs very often, a JSON node does this by default, allowing you to convert back and forth between JSON strings and JavaScript objects.
Before passing on the JavaScript object to the gauge display instrument, you have to separate the values for humidity and temperature. You can do this by using two change nodes (Figure 7), which you will set up to extract the values for temperature and humidity from the message and pack them into new messages:
msg.payload.humidity => msg.payload, msg.payload.temperature => msg.payload
The gauge nodes have to be configured (double-click on the nodes) so that the measured values lie within their display intervals; then, connect the individual nodes (Figure 8). Repeat the described steps for the other two sensors of the encoder trio. Finally, adjust the layout for your dashboard (Figure 9).
Conclusions
The easy-to-use Node-RED tool is ideal for visualizing measured values. Other tasks from the IoT sector can also be implemented easily. When setting up the sensors, you can learn a great deal about the ESP8266 microcontroller, which is also suitable as a basis for your own applications of all kinds.
A small problem remains: The AM2321 works at a level very close to its minimum operating voltage, which is why the measured values are sometimes slightly inaccurate. To solve this problem, you would have to make the power supply of the complete circuit a little more complex by using three batteries and generating the required 3.3V operating voltage with a voltage regulator.
Infos
- MQTT project: https://mqtt.org
- "RaspPi-controlled toy sailboat" by Pete Metcalfe, Linux Magazine, issue 216, November 2018, p. 52, http://www.linuxpromagazine.com/Issues/2018/215/RaspPi-Controlled-Toy-Sailboat
- MQTT app for Chrome: https://chrome.google.com/webstore/detail/mqttbox/kaajoficamnjijhkeomgfljpicifbkaf
- PCB prototyping board: https://www.aliexpress.com/item/32824842884.html
- ESP8266 and breakout board: https://www.sparkfun.com/products/15258
- USB-to-serial: https://www.amazon.com/XCSOURCE-FT232RL-Adapter-Arduino-TE203/dp/B00HSX3CXE
- AM2321: https://www.amazon.com/Quickbuying-Digital-Temperature-Humidity-Replaced/dp/B07H3SSVYL/ref=sr_1_2
- Arduino IDE: https://www.arduino.cc/en/Main/Software
- Code and diagrams for this article: ftp://ftp.linux-magazine.com/pub/listings/linux-magazine.com/226/
« Previous 1 2 3
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.
-
Fedora 41 Released with New Features
If you're a Fedora fan or just looking for a Linux distribution to help you migrate from Windows, Fedora 41 might be just the ticket.
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.