This project is the third part of an assignment for the course of Internet of Things at the Sapienza University of Rome. The aim is to build a Virtual Environmental Station based on Amazon Web Services (AWS). It is suggested to inspect the first part and the second part because in this guide it will be assumed that you already know the basics of the argument.
The system is made by two RIOT-OS native boards that generate random environmental data and send them firstly to The Things Network through LoRaWAN, then these data will be sent to AWS with a bridge.
IoT-LAB setupWhat is IoT-LAB?IoT-LAB provides a very large scale infrastructure suitable for testing small wireless sensor devices and heterogeneous communicating objects. It is the evolution and extension of the SENSLAB testbed (2010-2013).
The first step is to create your account and configure your SSH access.Simply follow the linked guides, because they are very detailed and clear; take your time to set everything.
Keep in mind that in this article, we refer to the LoRaWAN communication using RIOT and TheThingsNetwork guide provided by IoT-Lab itself
The LoRaWAN (Long Range Wide Area Network) specification is a Low Power, Wide Area (LPWA) networking protocol designed to wirelessly connect battery operated ‘things’ to the internet in regional, national or global networks, and targets key Internet of Things (IoT) requirements such as bi-directional communication, end-to-end security, mobility and localization services.
The Things Network setupThe Things Network is a contributor member of the LoRa Alliance.Again, you have to do some preparation steps, starting obviously from creating your account. Then, you need to create an application and register two devices. Like before, the linked guides are very clear and easy to use.
For a better visualization of the data incoming, in the decoder in the section Payload Formats of your application, copy this javascript code:
function Decoder (bytes, port){
var result = "";
for (var byte in bytes){
result += String.fromCharCode(bytes[byte]);
}
return {"string" : result};
}
RIOT-OSEven if the guide mentioned before is clear in how to run the two RIOT boards, we will see these steps together. Notice that it is important that you followed the other steps that you have seen in the IoT-LAB setup and The Things Network setup sections. Also, remember that you can find the code used in this repository.
- Connect to the Saclay site host
> ssh <login>@saclay.iot-lab.info
- Start an experiment with 2 RIOT nodes
> iotlab-auth -u <login>
> iotlab-experiment submit -n riot_ttn -d 60 -l <number-of-devices>,archi=st-lrwan1:sx1276+site=saclay
You have to insert 2 in <number-of_devices>. If you want, you can change also other parameters like the experiment name or the experiment duration.
- When the experiment is Running, get the nodes list. You should have obtained st-lrwan1-10.saclay.iot-lab.info and st-lrwan1-11.saclay.iot-lab.info.
> iotlab-experiment get -i <exp-id> -s
> iotlab-experiment get -i <exp-id> -r
In <exp-id> section you have to insert the id of your experiment.
- Clone the RIOT code from GitHub:
> git clone https://github.com/RIOT-OS/RIOT.git -b 2019.01-branch
> cd RIOT
Now pay attention! You have to substitute the basic main.c located at RIOT/tests/pkg_semtech-loramac with the main.c that you can find in my repository. You may have to use the Secure Copy (scp).
- RIOT doesn’t support the arm gcc version installed by default on the SSH frontend, e.g. 4.9. So we provide arm gcc 7.2 in /opt/gcc-arm-none-eabi-7-2017-q4-major. Use the following command to use gcc 7.2 by default:
> export PATH=/opt/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH
Notice that you have to check your version, in my case I had to change it.
> arm-none-eabi-gcc --version
- Build the LoRaWAN test application
> make -C tests/pkg_semtech-loramac clean all
- Use the CLI-Tools to flash the ST LoRa node with the LoRaWAN firmware that you have just built. Here we use st-lrwan1-10 and st-lrwan1-11 but it may change in your case
> iotlab-node --update tests/pkg_semtech-loramac/bin/b-l072z-lrwan1/tests_pkg_semtech-loramac.elf -l saclay,st-lrwan1,<device_number>
> iotlab-node --update tests/pkg_semtech-loramac/bin/b-l072z-lrwan1/tests_pkg_semtech-loramac.elf -l saclay,st-lrwan1,<device_number>
In the <device_number> section insert obviously the number of your device.
- You can now access the RIOT shell running on your node using netcat
nc st-lrwan1-<device_number> 20000
Again, change the <device_number> section. Run the devices in different terminals, repeating the steps needed for the setup.
- Now find the Device EUI, Application EUI and Application key information in the Overview tab of the iotlab-node device on the TTN web console. Then set them to the RIOT firmware (replace the values with yours):
> loramac set deveui 00000000000000
> loramac set appeui 00000000000000
> loramac set appkey 0000000000000000000000000000
For further information about loramac commands, you can type help.
- Also set a fast datarate, e.g. 5, corresponding to a bandwidth of 125kHz and a spreading factor of 7, since the nodes are very close to the gateway:
> loramac set dr 5
- Now that the node has the required information set, it is time to join it to the network using the OTAA
> loramac join otaa
- Now, if everything has been correctly setted up, you can start a station with
start <station_id>
where <station_id> is supposed to be station1 or station2.
Again, remember to run the two stations in two different terminals. In the second terminal, you have to connect again to the Saclay site and continue from the step iotlab-node --update [...]
.
A clarification: the file main.c is based on the semtech_loramac test available in the official RIOT folder. I modified it for our purposes, adding the function cmd_start. The comments in whole the code will help you to better understand what is by default and what not.
TTN/AWS bridgeLike in the second part of the project, we need a bridge that sends the data to AWS, this time getting them from The Things Network. As in the previous part, the localhost web page will display these data. Now give a look to the code, that resumes the same structure of the bridge presented in the second part, and remember that you will have to set your personal parameters!
Here we have some basic settings and the function to establish a connection with AWS, that you may remember from the previous parts.
In this section, you have to insert the name that you gave to your application and your access key. You can find the access key as the last line on the Overview page of your application.
Finally, we have the callbacks for decoding and publishing the messages. You can run the bridge, after modifying it with your parameters, opening a terminal and launching:
> python3 TTNbridge.py
You have to get 0 as the return value of the connection.
How the system worksThe code is available in my Github repository and obviously if you want to use it you have to change some parameters like the endpoint and the path of the certificates. If everything has been done correctly, you can run the system in the following way:
- (optional) Run the localhost page typing:
>
python3 manage.py runserver
The file is located in django_web folder - run the TTN Bridge in one terminal:
>
python3 TTNbridge.py
The file is located in lorawan_stations folder - run the two stations through RIOT nodes, following carefully the steps listed in the RIOT-OS paragraph
The file is located in lorawan_stations folder
If everything worked properly, you should see something like this!
Useful links
Comments