First, if you want to know more about the MQTT protocol, I advise you to go back to the previous chapter 1
where we explain everything about the protocol itself. 2
I'm going to use exactly the same diagram for this explanation about the liquidity integration with 3
ChirpStack, because it works exactly in the same way. 4
So, if you were comfortable with the previous demonstration, this one should be easy. 5
What we want to do is to connect two clients, one subscriber for the uplink stream and one publisher 6
for the downlink stream. 7
And these two clients will be connected to the embedded broker in ChirpStack. 8
This broker is already available and enabled because this service was part of the ChirpStack installation 9
process. 10
Now let's recap what we need to configure for the connection of the subscriber and the publisher. 11
First, we need to know the broker address on ChirpStack to reach the broker. 12
We need to use the IP address of the LoRaWAN server colon 1883. 13
In our case it will be chirpstack.univ-lorawan.fr:1883 14
Fine. 15
Secondly, we said that we will need credentials to connect to this broker. 16
However, the default ChirpStack installation remove these needs of credentials. 17
This is absolutely not secure. 18
So of course, except for this demonstration, we will never leave it like this. 19
If we want to apply some credentials, then before the installation we need to configure the MQTT broker 20
called Mosquitto. 21
We can do this configuration thanks to the configuration folder from the ChirpStack installation files. 22
In this folder we will find a folder for each service. 23
In the folder called Mosquitto, which is the name of the broker used in ChirpStack, there is a configuration 24
file. 25
This file is called mosquitto.conf, and that's in this file that we will need to set the credentials. 26
We just have to follow the steps explained in the documentation. 27
Third, we need a topic. 28
And again, we'll make it easy for the subscriber because we're going to use the #. 29
What happens if I do that? 30
I will receive all events from all sensors of all applications. 31
Of course, if we want the data from a specific device of a specific application, then we need the 32
exact topic. 33
And again, we'll find this information in the documentation. 34
So, let's have a look. 35
We go on the ChirpStack website? 36
Then in the ChirpStack section, we go on Integrations. 37
Then MQTT. 38
Here we have the default event topic. 39
That is the generic topic we need to subscribe if we want information on an event. 40
Application/APPLICATION_ID. 41
device/DEV_EUI. 42
event/ 43
EVENT 44
APPLICATION_ID needs to be replaced by our application identifier. 45
DEV_EUI needs to be replaced by the device EUI in lower case and EVENT needs to be replaced by the type 46
of event we are interested in. 47
Let's see what we can have: all these ones. 48
But of course the most important will probably be the up event. 49
Anyway, if you want all of them then we just need to use the wildcard + instead of the keyword EVENT. 50
Okay. 51
And now for the publisher, 52
so to send downlink messages, the information we need is just at the bottom of that page. 53
The topic is this one. 54
Again, we need to replace the APPLICATION_ID and DEV_EUI with the right values. 55
Okay, we're almost done. 56
We need one last information for the publisher. 57
That's the format of the downlink message. 58
The payload of the message has to respect a specific JSON format. 59
It's represented here in the documentation. 60
Basically, we will specify once again the devEui, whether it's a confirmed or unconfirmed value and obviously 61
the data we want to send. 62
Great. 63
We are now ready. For this demonstration 64
my device is going to send a temperature each time I press the user button. On the left, I've got my 65
end-device logs and on the right I've got my application and I can check that everything works well. 66
Now I want to connect my subscriber and publisher. 67
Let's start with Node-red and after I will show you the same demonstration with MQTT Explorer. 68
We will need all the information gathered previously so I saved everything here. 69
First, let's start with the uplink. 70
I come back on my node-red user interface. 71
I will keep the previous demonstration so I open a new tab. 72
But the flow I'm going to use is very similar, so I copy all nodes of the demonstration we made already 73
and I paste them on my new flow. 74
I change the name of the tab. 75
This demonstration is about an MQTT connection with ChirpStack, so the name will be MQTT ChirpStack. 76
The broker is now ChirpStack. 77
Again, this is just a comment, so don't worry about that. 78
But I think it's clearer if we keep in mind that there is a ChirpStack broker here. 79
Okay, so now let's configure the Subscriber. 80
So let's click on the subscriber node and I'm going to add a new broker. 81
I fill in the server name. 82
So chirpstack.univ-lorawan.fr on port 1883. 83
This time in the security tab. 84
There is nothing to enter because, as we said, ChirpStack doesn't use credentials for its default 85
configuration. 86
So I just add the broker to the list available when the configuration is done. 87
Now I've got the new ChirpStack broker available in the list. 88
Great. 89
So, now the topic. 90
I said I would use the #, but if you want you can specify one. 91
And there we go. 92
We are done with the Subscriber. 93
So we can retry that part and it should work. 94
I click on deploy. 95
For this test. 96
I'm only interested on the subscriber part, so don't look at the publisher because this is just the 97
one I copied from our previous demonstration. 98
And if I hit the push button of my end device, then I receive the message on my application. 99
This message has traveled all the way from my device, my gateway, the Network Server, the Application 100
Server, the ChirpStack broker, and finally has been pushed on my Subscriber here. 101
If we want the exact topic of our device, then we can find it here in the debug. 102
We just need to copy that and change the topic of our subscriber with this one if we wish. 103
Okay. 104
So the right part of this flow is working for the uplink traffic. 105
Now on the left, I'm going to take care of the Publisher part for the downlink traffic. 106
So I click on the Publisher here, I choose the ChirpStack broket I've just added. 107
And for the topic I just paste, the topic I took from the documentation. 108
All right. 109
We are done with the Publisher configuration. 110
Now I need to select the content of the JSON object to send the downlink message. 111
This is what I picked up from the documentation, so I just opened the JSON editor here. 112
I erase the content because this is the one used for the other Network Server and I paste it here. 113
In this example, I'm just going to send the command 1, which is this payload in base 64. 114
On the application port 15 that will turn on the LED on my end-device. 115
Great. 116
So let's deploy and test this application. 117
Both Publisher and Subscriber are now connected. 118
If there were any problems, I would have them reported here. 119
So now everything seems fine. For the moment, 120
nothing happened. 121
And then I press the button to publish the downlink message on the broker. On my debug window, 122
I've got a message from the LoRaWAN server telling me that the message has been queued. 123
It has not been sent yet because I remind you that this device is a class A end-device, so I need to 124
send a message before sending a downlink. 125
And for that I need to press my end-device push button. On my application, 126
I received two messages, one telling me that an uplink data has been received. 127
And another message telling me that my downlink message has been transmitted. 128
So, let's go on the device. 129
And yes, indeed, I've received 01 and 130
I can check that the LED is turned on. 131
If I now want to turn it off, then I just need to modify the downlink frame payload in the other injection 132
node. 133
This time, I want to send the payload "AA==" which is zero coding in base 64. 134
Once we send this, the LED will turn off. 135
Great. 136
So, now we can try to do the same demonstration with MQTT Explorer. 137
Now that we know the broker address and the payload to send, it would be quicker. On MQTT Explorer, 138
I create a new connection. 139
I call it chirpstack. 140
And I enter the broker address, again with no credential. For the topic, 141
I leave it like this because if you remember, the default topic is #. 142
So, that means that if I don't change this configuration, I will receive all messages from all topics. 143
I connect my client to the broker and I can send an uplink message from my end-device. 144
For that, I just need to press the push button. 145
There we go. 146
The content is here. 147
And I can see the frame payload in base 64. 148
That was the uplink traffic. 149
So now, how do we send a downlink message? 150
We go on the Publisher part. 151
We assign the right topic, which is this one, and I enter the JSON object message with the right devEUI, 152
the right port and the payload. 153
As soon as I publish it, a new message is received from the broker telling us that the message is queued. 154
And when I press the push button, I receive two messages one telling me that a new uplink has been 155
received and another message telling me that my downlink message has been transmitted. 156
And obviously, on the device I've received the command and the LED is now on. 157
Great. 158
The integration with ChirpStack is now over as we've covered both HTTP and MQTT. 159
Please tell us if you've managed to do it on your own server.