The first step is to build an MQTT subscriber with Node-RED so we can receive the uplink stream. 1
This is exactly what we did in the chapter about MQTT, so you will find many more details if you go 2
back to the corresponding video. 3
However, I will quickly do it one more time. 4
We will need only two nodes the MQTT in node, so our subscriber and the debug node we'll always use it 5
to check that everything works as expected. 6
We connect them together and we can now configure the MQTT node. 7
We have to set the broker address and its credentials and the topic. 8
So we add a new MQTT broker called TTN. 9
With the URL and the credentials, we can find this information on our network server documentation. 10
In my case, I use TTN for this demonstration so I can find this information in the MQTT integration 11
section. 12
So that's the address, the username and the password that I need to generate. 13
So the server address and in the security tab, the username and the password. 14
Okay. 15
And for the topic, I will subscribe to everything at the beginning. 16
So I'm going to use the # wildcard. 17
There is one more configuration for this node. 18
It has nothing to do with MQTT, but if we want to have a nice output then it's better to select here: 19
Parsed JSON object. 20
Otherwise the output will be sent as text and it's not very convenient. 21
I can also set a name TTN. 22
Great. 23
Let's deploy that. 24
My subscriber is connected, which is a good news and I can see the log in the debug window. 25
What I'm going to do before going forward is to change the topic. 26
Because as we can see, there are more debug messages than uplink frames because I subscribe to all 27
events on the network server, but the only one I'm interested in is the uplink event. 28
And this is one: "v3/training-usmb@ttn/devices/device1-otaa/up" 29
So I quickly modify the subscriber node with this topic. 30
And I deploy my flow once again. 31
This time when I transmit a frame, there is only one debug message. 32
If I open the debug message, I can find everything I need in the uplink- 33
message object: the payload, 34
And further in the rx_metadata array, the RSSI. 35
Fine. 36
But there is one more thing that won't be very convenient here. 37
It's that the payload is a string in base 64. 38
Rather, I would rather have a number. 39
I know that it's a temperature. 40
So here I want a number representing that temperature. 41
We have also done it in a previous video. 42
The trick is to use the payload decoder of the network server. 43
So we go on TTN, but of course you will find a similar payload decoder on all other network server. 44
And in the uplink payload formatter section, then we can specify that the first byte. 45
So byte zero is the data called temperature. 46
If we do that, then now the LoRaWAN server will send a new object called decoded payload to our subscriber. 47
And in this object we'll find our field temperature and its value. 48
Okay, so first step is done. 49
Now let's save this temperature on our side in the database.