IoT Application Server
Objective
Our goal in this lab is to develop an application server that can be used for processing and visualizing IOT data with open source software. The application server can be used with data from any source that supports the ability to output data to an MQTT stream.
Getting Started
These instructions will take you through setting up a Node-RED dashboard.
Note: Windows and Debian Linux were used to develop and validate this project. The same applications can be deployed on other Linux distributions, potentially, with some minor modifications.
In this lab you will
- Set Up the MQTT Data Flow
- Format the Data
- Create a Basic Dashboard
You will need:
- Linux or Windows Host
- Node.js
- Node-RED
- Mosquitto
- MQTT
Node-RED Set Up
Installation
- Install the latest LTS version of Node.js
- To verify whether this was installed properly run
node -v
and npm -v
(the system should display what node and npm version is installed on your system)
- Install Node-RED locally with npm
Check
- Check whether you installed it correctly by running
node-red
in your terminal
- Navigate to http://localhost:1880/ which should automatically direct you to your flow (unless you changed the port number in configuration)
Security
Follow this tutorial on setting up a username and password to secure your Node-RED flows.
MQTT Set Up
Moquitto Installation
- Install Mosquitto
- Use this link for Windows
- Use this link for Linux
- Make sure it is installed correctly by running
mosquitto -h
in your mosquitto folder
- Another way to check is by running
netstat -na
and looking for a listener on port 1883 (unless you changed it from the default in your configuration file)
Mosquitto Configuration
Configure your Mosquitto MQTT broker with username and password here
Mosquitto Validation
Validate and troubleshoot Mosquitto connectivity and authenication issues here
Setting Up Your Node-RED Flow
- Set up your publishing flow like this
- Set up your subscribing flow like this
-
Configure your MQTT nodes by making sure that they have the same topic
and are on the same server
- If you set up a username and password, make sure you enter that information into the security tab when you edit the MQTT server
-
You should be able to see the timestamp in your debug window if you press on the inject node
Formatting the Data
Right now, our timestamp is in a number format, but we want to convert it into a Date. Here we use a function node to format our data.
Your subscribing flow should look like this
Making a Dashboard
Attach a text node and make a new dashboard group and tab to contain it. After clicking on the inject node, your dashboard (at the URL http://localhost:1880/ui/) should look like this.
Your Node-RED flow should look like this
Conclusion
In this lab, you learned how to set up and install Node-RED and Mosquitto (an MQTT broker). You formatted data from the MQTT data stream and created a basic dashboard for people to view.
Next Steps
Check out some extensions to this basic app server