Publish Temperature Data Over MQTT-TLS

  • Overview
  • Resources
  • Transcript

In this video, we will write a NodeJS service that uses UPM and MQTT over TLS to securely publish a temperature sensor’s data to an MQTT broker on the IoT Gateway.


 

Hi, I'm Daniel Holmlund. In this video, we'll write a Node.js service that uses UPM and MQTT over TLS to securely publish a temperature sensor's data to an MQTT broker on the IoT gateway. Getting things to talk on the IoT network is the first step in building our IoT system. 

First, load the raw library and set the serial communications port. Load the MQTT library and load the certificates and key files that are associated with it. Then set the parameters to make a connection to the MQTT broker on the gateway. 

Load the UPM library that contains the temperature sensor and declare an offset because we're using Firmata. Then instantiate the temperature sensor from the UPM library. Use setInterval to run a function to read from the temperature sensor and publish the value over MQTT once per second. Note that we'll be publishing on the MQTT topic sensors/temperature/data. Slash 

Lastly, stringify the JSON object that contains the sensor data so that it can be sent out over MQTT. Now we've built a simple Node.js service that publishes the temperature on the MQTT topic sensor/temperature/data. This temperature device is now a connected internet of things object. 

Thanks for watching. To learn more, follow the links provided. Don't forget to like this video and subscribe to the Intel Software YouTube channel.