I'm going to use exactly the same figure we use previously, and for now we'll deal with the uplink 1
data. 2
And for this part, we're focusing only on the HTTP GET request. 3
For this demonstration, we'll use TTN community for our network server. 4
Actually, this is the only one that I know which can handle HTTP GET request for the uplink data. 5
So we won't have many choices, but we'll explain later. 6
That HTTP GET request are probably not the best idea. 7
There are other ways to send uplink data to the IoT platform, but anyway, we'll see that later. 8
And for now we'll just make a small demonstration. 9
For the server part, I need to go on TTN console and to activate an integration called "Storage Integration". 10
So, I click on the Application Section and on the application used for this course, which is "training-usmb" 11
and on the left I can expand the integration tab and here I will find the storage integration. 12
What is nice with this integration is that TTN saves our uplink data in a persistent database. 13
We can request it whenever we want. 14
In the TTN community server we have a 24h storage, but obviously you will have more if you register 15
on the cloud version. 16
So, I hit the "activated storage integration" button. 17
There we go. 18
TTN is now ready to store my data. 19
So now, before leaving the server, I would like to deal with the authentification procedure. 20
Because, of course, not all requests from any client will be authorized. 21
Actually, only the client with a valid API Key will be able to use this server in each application 22
of your LoRaWAN server, 23
you can generate these keys, here. 24
It's at the bottom. 25
In the API Key section. 26
We add a new API Key. 27
We can give an expiry date or some other restriction. In our demonstration, 28
let's grant all privileges. Then the API Key provided needs to be copied. 29
Be careful because once you've left this page there is no way you can retrieve the API Key previously 30
generated. 31
So, I copy it and I store it in the text file. 32
I'm going to use it in a few seconds with the client. 33
So, the last thing I need to do is to send an HTTP GET request, but there is no way I can guess the 34
target URL of this request. 35
So, the method is always to check the documentation. We use TTN, 36
so I go on the TTN website. 37
TTN is the famous name for the community network, but it relies on the LoRaWAN stack called The Thing 38
Stack. 39
So the documentation we are looking for, is the documentation of The Thing Stack. 40
We'll need it again later when we will install this network server for our private network. 41
But for now, we just need the documentation of the Application Server. 42
So, obviously website, network servers, and documentation are updated on a daily basis, so I'm not going 43
to give you the direct link to the answer, but instead I would like us to experiment the user journey 44
to find the right information. 45
So on The Thing Stack documentation website, we'll use the search bar to look for the HTTP request. 46
If you hit HTTP queries here, then you will already be at the right place. 47
But maybe we could have been more precise by typing HTTP GET and we'll end up directly in the right 48
paragraph. 49
So any of these keywords works fine. 50
Great. 51
So, here we're going to learn how to send an HTTP request. 52
It's not yet the exact request we want to send, but it's a good start. 53
And like many documentation, when they want to give an example of a request, they provide the corresponding 54
cURL command so you can try it out quickly. 55
You maybe wonder what is cURL and why do we use it. For this explanation, 56
please go back to the video at the beginning of this lecture. 57
This video explained "How to send HTTP requests with cURL." 58
You will learn everything you need to know on this essential tool. 59
In our case, we'll use once again mobaXterm to send the cURL command. 60
But of course, you can use any terminal with cURL with the HTTP GET example, we'll get the names, description 61
and location of devices 62
dev1 in application app1. 63
So, I will just copy the command in a text editor. 64
I replace the right API key. 65
I change the target URL of the network server. 66
Here it's the community TTN network. 67
The address is the following one. 68
We will actually do the same thing later with our private network. 69
That's why this address can be different. 70
Then we change app1 by the name of our application. 71
Ours is called training-usmb, finally our device is called device1-abp. 72
We copy this cURL command and we send it in the terminal. 73
All right. 74
We got an answer. 75
That's a good news, because it means that first the request has been authenticated. 76
And secondly, it means that our requests had the right format. 77
Let's see the answer: 78
It a JSON format, 79
and as you know, we can pretty print it. 80
We just have to use a pipe, 81
(So, the vertical bar) and the JQ command at the end. Here we are, 82
it's much more readable. 83
Indeed, we have our device, within its application and with its name and description. 84
Now, we want more. 85
We want to send a request to get the uplink-data of an entire application or of a specific device. 86
What we've done so far, is just a basic HTTP GET format to ask information. 87
But The Thing Stack has a specific API, so a specific set of command called "Storage Integration API." 88
And when we click on this section, the documentation provides the HTTP GET request to ask for the data 89
received by any devices of any application. 90
Let's try that. 91
In this demonstration, I will ask for any received packet of all devices of my application called 92
training-usmb. 93
So I need to use the second URL, this one. 94
And if we go deeper in the documentation, we'll find out that this field has to be changed by our 95
application ID. Type field can have several possible values. 96
In our case, it will be "uplink_message." 97
So, I build a new request. 98
And I replaced the URL. 99
One last thing. 100
The documentation has to use this option in the request "Accept: text/event-stream." 101
So we'll add it in the command. 102
So, now that my request is ready, I can try it up. 103
I copy it. 104
And there it is. 105
I've got all the uplink messages that has been received on the network server for the last 24 hours. 106
Let's check the frame payload, here. 107
It's this one. 108
Just to let you know, during the last uplink message, I sent the message. 109
"Hello" 110
So in the frame payload, we should get the message. 111
"Hello" 112
As you can see, this message is in a base 64 format. 113
So ,we copy it and we can use any online base 64 decoder. 114
This one, for example. 115
And there we go. 116
This is the "hello" string. 117
Okay. 118
And if in the documentation you searched for" storage integration", then maybe you ended up directly here 119
and in the retrieve message section, there are a few examples of cURL command to send HTTP GET request 120
with many other nice options. 121
Limit. 122
If you want to limit the number of new messages in the answer or "after", if you want some specific messages 123
received after the date. 124
Right. 125
You can play with all the fields available and tell me if it works well. 126
In the next video, we'll speak about the efficiency of the HTTP GET request and see if we could find 127
another ID to retrieve the message received on the network server.