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

  • Home Assistant with MQTT

    Automating your four walls does not necessarily require commercial solutions. With a little skill, you can develop your own projects on a low budget.

  • Adafruit IO API

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

  • IoT with RabbitMQ

    Connect multiple protocols and servers together on your IoT projects.

  • ESPHome

    With an ESP32 or Raspberry Pi Pico W microcontroller board, you can easily create your own home automation devices. Thanks to ESPHome, you don't even have to be a programmer.

  • Instrumented Garden

    Place long-range wireless sensors in a garden and keep track of ambient conditions with gauges and time-based graphs.

comments powered by Disqus
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.

Learn More

News