© Copyright 2016 by The-Box Development

Node-Red and MQTT

 

Having the data available  at The Things Network is nice, however it would be nicer if we could extract the data from TTN to process it. For this purpose TTN provides a MQTT message broker where you can subscribe to get the data.

 

In this example we will use Node-Red to process the data.

 

Every participant (or group) will be provided number, this number is required to access a node red instance. The password will be provided as well.

 

Point your browser to http://workshop.tbdev.nl:20<2 digit groupno> (so 2001-2015). Use username 'gebruiker' amd the provided password.

 

For those unfamiliar with node red, it allows 'drawing' code by dragging nodes from the bar at the left onto the canvas in the middle. The nodes can be connected by clicking on the terminals of one node and drawing a line to another nodes terminal.

 

We start our flow by adding an MQTT input node to the canvas. From the 'Input', drag the MQTT node to the canvas.

Double click the MQTT node to configure it. First click on the pencil icon to add a new connection.

Server: staging.thethingsnetwork.org

Port: 1883

Client ID: leave blank

 

Switch to the 'Security' TAB, open a second browser window with the application details on TTN. In the application details click on "learn how to get data from this app" to get the connection details.

Copy-and-paste the 'username' and 'password' values (use the 'eye' icon to show the password) to the appropriate fields in node red.

Click the 'Add' button, this adds the connection information for MQTT. Now we need to supply the topic for this connection. Use '<App EUI>/devices/+/up' to get all messages from all nodes registered to this application. Replace the '+' by the 16 character Dev EUI of a node if you just want to get data from that one node.

Click on "Ok" to close the MQTT configuration. From the "Output" category drag a debug node to the canvas and connect the two by drawing line from the output terminal of the MQTT node to the input terminal of the debug node.

Deploy the new flow by clicking the red "Deploy" button. A status icon and message will appear below the MQTT node. After a few seconds the icon should be green and the status should say 'connected'. Click on the "Debug" tab to the right to see output generated by the debug node. When the node transmits a new packet the data will appear there.