How to Subscribe MQTT Messages from LoRa Server

简体中文

Overview

The purpose of this article is to subscribe to data messages from TTN nodes using the MQTT plugin in the data flow applicition Node-Red provided by TTN.

The experiment kit used in this experiment is HT-M02, and CubeCell-board.

Maybe you don’t have a real device. You can still test this solution through the simulation uplink provided by TTN. How to use please see below.


Preparation

Download and install Node-red(takes a long wait)

If you are on a Raspberry Pi or any Debian-based operating system, including Ubuntu and Diet-Pi, you can use the Pi install script available here.

bash <(curl -sL https://raw.githubusercontent.com/node-red/raspbian-deb-package/master/resources/update-nodejs-and-nodered)

If you want to install to other operating systems such as Windows, RedHat, CentOS, please refer to the official installation guide of Node-Red:


Configure Node-Red

I access the web interface provided by Node-Red in ubuntu, so the port accessed through the browser is: localhost:1880

Then we need to download the TTN plugin in Node-Red.

Add TTN palettes to Node-red

  • Installation via user setting in Node-Red panel

    ../_images/0137.png

  • Install from the command line

    npm install node-red-contrib-ttn@2.0.1

We need to configure the data source from TTN, such as APP EUI, APP KEY, DevEUI and other parameters…

We select INPUT-> ttn_message palette from the downloaded TTN plugin, which is on the left side of the panel. Drag it into the Flow panel on the right.

../_images/13.png

Next, Double-click it fill in the key parameters such as the application EUI, KEY, and Device ID that we registered in TTN.

../_images/0321.png

../_images/0413.png

Click Update after configuration.

Configure MQTT plugin

We need to configure the topic forwarded by the MQTT plugin.

For example, now I want to wrap the upstream message of a node into a topic named Node_uplink through the MQTT plugin and forward it to my private MQTT Broker.

First, select the OUTPUT-> mqtt palette in the left panel. Drag it into the Flow panel on the right.

../_images/0510.png

Next, double-click it to fill in our reposted topic. In the end, you must fill in your target broker.

../_images/068.png

../_images/076.png

After filling all the palettes, we must connect them in Flow.

../_images/086.png

Please don’t forget to click the Deploy button in the upper right corner to make them effective after completing all the configurations.

../_images/093.png


View subscription

Then use MQTT.fx software to subscribe to this topic. If it goes well, we will see the default uplink data 1, 2, 3, 4.(ASCII: 31 32 33 34) of CubeCell-Board in MQTT.fx software.

../_images/102.png

We successfully subscribed the payload of the uplink data of the nodes in the TTN through MQTT.

If you don’t have a real device, you can use the SIMULATE UPLINK prepared by TTN for you, which can be used like this:

../_images/11.png

It’s in the Application-> Device page you created.

Click Send to simulate the node’s Uplink data.

enjoy.