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).

Figure 6: You can define the MQTT input node quite conveniently in the Node-RED interface.

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:

Figure 7: A change node extracts the temperature specification from the JavaScript object.
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).

Figure 8: The Node-RED flow for a sensor with one display each for temperature and humidity.
Figure 9: The Node-RED dashboard displays the measured values of the different sensors in an attractive graphic.

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.

The Author

Martin Mohr developed a love of everything that flashes at an early age, which was reinforced by training to become an electronics technician. After moving on to study computer science, his field of activity was mainly developing Java applications. The Raspberry Pi rekindled his old love of electronics.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • IoT with RabbitMQ

    Connect multiple protocols and servers together on your IoT projects.

  • Adafruit IO API

    The Adafruit IO API offers a convenient means for network-ready sensors and other components.

  • Monitoring Beehives

    Beekeepers can get to know their colonies better without continuously disturbing the industrious insects. Using a Raspberry Pi and various sensors, two hobby beekeepers monitor the temperature and humidity of their hives, with plans to monitor their weight.

  • Home Assistant

    Home Assistant brings an open standards approach to home automation and control.

  • Tasmota

    Flashing IoT devices with new firmware lets you wield control and keep them out of the cloud.

comments powered by Disqus

Direct Download

Read full article as PDF:

Price $2.95

News