Influxdb has been installed with Docker and is already running. 1
If we want to see what's inside, then we can connect to it. 2
Thanks to a user interface available on port 8086. 3
If you've used my configuration file, the username and password are "admin" for the login and "univ-lorawan" 4
for the password. 5
We could even build dashboard with this influxdb container, but it's not widely used, so we're going 6
to stick with the original ID to use Grafana to build our dashboard for us. 7
This simple interface is just going to be useful to dive into the database and verify the stored data. 8
On the left menu, we can click on the Data Explorer section where we'll find our bucket called IoT-platform 9
... 10
This bucket has been created during installation exactly as it was instructed in the Docker compose 11
configuration file. 12
A bucket is just a name of a place where we're going to store our data called measurements. 13
Of course, our bucket is empty right now because we haven't stored anything yet, so let's do it. 14
So back in Node-RED, we need to use a node called Influxdb out and that is with this node that we're 15
going to feed the database with the data received by our subscriber. 16
So the first idea is to connect directly the MQTT subscriber to the influxdb node. 17
If this inflow node wants to be able to connect to the database, we need to configure it so it can 18
have the credentials. 19
So we click on the influxdb out node, we give a name to the node, let's call it InfluxDB. 20
Then we have to add the information of the influxdb 21
instance, exactly 22
in the same way we add a new MQTT broker earlier, but this time this is where stands our database. 23
So we click on Add a new influxdb. 24
Let's give again a name to this influxdb instance, and we choose the version. 25
In our case, we're using version two. 26
We now need the database URL, Iot-app.univ-lorawan.fr on port 8086 and the token again, you need to provide 27
the one we put in the configuration file or the one you've created in influxdb. 28
The organization is training-usmb and the bucket is iot-platform. 29
Again, same information that is in the Docker compose file. 30
And this time we'll ask him to store a new set of data. 31
We'll ask it to do it in a measurement called LoRaWAN sensor. 32
But of course you can choose your own measurement name. 33
So now, what happens if a new uplink frame is received? 34
Nothing much except that we still receive the debug information from the MQTT subscriber. 35
So let's see what has been stored in the database in the IoT platform bucket. 36
A new measurement called lorawan-sensors has appeared. 37
That is a very good news. 38
That means that we didn't meet any issues to connect to our database. 39
But if we try to see what's in our measurement, there is nothing. 40
Actually, this is quite normal because of course we can't just send the overall object from the MQTT 41
subscriber with everything in it influxdb doesn't understand what we really want to do, and when 42
it tries to guess, then it mostly finds string value and influxdb can only deal with numbers. 43
I remind you that we only want to store the temperature and the RSSI of the LoRaWAN device, so we need to 44
extract this data from this object and we want that the number stored in the database is stored with 45
the name of the value, which will be "temperature" or "RSSI", depending on the value we store. 46
If we want to do that, then we need to provide a clear message to the database. 47
This is not complicated at all, but we need to comply with a specific format. 48
So we need to put a new node between the MQTT subscriber and Influxdb. 49
This new node is going to build the message to send to the Influxdb with only the relevant value. 50
This node is called function. 51
And inside we have to provide some JavaScript code. 52
We could have done this in no code by using only nodes, but in the end I think it's more complicated. 53
So to make things easy, I provide a template which is this one. 54
This is an array of two objects. 55
One is here and the other one is there. 56
The first one at the top is a list of the value we want to store in the database. 57
For each of them, we need to provide a name and where to find the value. 58
So, for example, the first value we're going to store will be called "temperature". 59
And to get the corresponding temperature value, we need to follow the corresponding path of the object 60
coming from the MQTT subscriber. 61
So if we look at the object provided by the subscriber, then we see that to get the temperature we 62
need to select the field: 63
"Msg.payload" It's the standard preamble for an output object. 64
Then "uplink message", "decoded payload", "temperature." 65
This is what we need to provide on the first line. 66
In Node-RED there is a very useful button. 67
We want to pick up the path of a value called copy path so we don't have to remember all the object 68
hierarchy. 69
If we follow the same process, then for the second line we can call the value RSSI and to pick up the 70
value we go back on the object and we copy the path. 71
There we go. 72
Now there is another object at the bottom for Influxdb. 73
This object represents the tag that we want to provide. 74
It's optional, but maybe it could be very useful to know from which device ID or from which application 75
the data comes from. 76
So the tags are often information that can't be represented in a graph because it's usually a string 77
anyway. 78
But for example, it can be very useful to filter a range of value among a dataset. 79
So when we query the database, if we use tags, then we'll be able to select only the temperature of 80
a specific device, for example. 81
Great. 82
Let's try that. 83
For each temperature on our RSSI value stored in the database, we're going to store the name of the 84
device. 85
So we write here "device". 86
And the corresponding name can be found here. 87
So once again, we copy the path and we provide it to our JSON object. 88
Okay, we're done. 89
So now each time a temperature is sent of a LoRaWAN, a JSON object with this specific format is built 90
using this function and it contains these informations: 91
Temperature, RSSI and the device name. 92
Of course, you can add as many values as you want in the function. 93
So let's have a look at the database now. 94
We select the bucket, the measurement, and here we can see all the stored data. 95
Temperature, RSSI and the corresponding device name. 96
And that's exactly what we wanted. 97
If we submit the query corresponding to the selected field, then we can have the data overview. 98
If you're not happy with the query, then you can change the settings and submit a new one. 99
Great. 100
So now let's finish the most interesting part of our IoT platform. 101
We're going to create a dashboard with two charts the temperature and the RSSI. 102
And for that, we're going to use Grafana. 103
Let's see how it works in the next video.