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)