This project is related to CleverWeather,so it's strongly recommended to check that first. The implementation part takes for granted that you already have an Azure IoT hub, at least a device and a web app to visualize data.
This IoT system is part of an assignment for Internet of Things course at Sapienza University of Rome. Two RIOT apps will publish messages with random values to TheThingsNetwork (TTN) using LoRaWAN protocol. A gateway connected to TTN will receive these messages and will send them to Azure IoT Hub. Finally the nodejs app allows you to visualize data in local.
RIOT-OS app
A simple RIOT-OS app will be used to randomly create values and publish them using LoRaWAN, a protocol for long range transmission.
TheThingsNetworkapp
TTN provides a set of open tools and global, open network to build IoT applications. It will host the application and its devices.
IoT-LAB
IoT-LAB provides a very large scale infrastructure facility suitable for testing small wireless sensor devices and heterogeneous communicating objects. I will use wireless sensors located in Saclay (France) and deployed on two reserved nodes.
Gateway
The gateway connects to TTN app using MQTT protocol and, when a message is received, it will send it to Azure IoT Hub using MQTT direct implementation. I have used python, but you can choose the programming language you prefer.
Azure IoT Hub
The IoT hub will be used as a MQTT broker, but it's not complete and it doesn't support all the standard behaviours.
Nodejs
Nodejs is used to run an application that lets you visualize the data in local. You have to install also the package @azure/event-hubs.
Implementation- TheThingsNetwork app
The first thing to do is sign in to the site, then you can go to the console and click on "Add application". Choose an univocal name and best practice is to use the closest server, so use ttn-handler-eu if you are in Europe. Click Add Application to finish.
Open your app, go to Devices section and click on "register device" to add one. Choose a name and randomly create a device EUI, then click on "register" to finish the operation.
For this assignment I have created 2 devices with the same name of my IoT Hub devices. Now select your device and take Device EUI, Application EUI and App Key values, you will use them later.
- IoT-LAB
Sign in and configure your SSH access to the IoT-LAB servers. Open a terminal and type the following command:
my_computer$ ssh-keygen -t rsa
my_computer$ cat ~/.ssh/id_rsa.pub
It will generate a public and a private key. The last line is used to see the public key that you will copy on the webportal.
Copy the value here and click on the green button to update the SSH key.
Now you can start the deployment. During this tutorial, <login>
indicates your username in IoT-LAB. Open a terminal and connect to the Saclay site host:
my_computer$ ssh <login>@saclay.iot-lab.info
Start an experiment called riot_ttn
with 2 nodes located in Saclay. It will last 60 min and will use St-Lrwan1 (Sx1276) architecture:
<login>@saclay:~$ iotlab-auth -u <login>
<login>@saclay:~$ iotlab-experiment submit -n riot_ttn -d 60 -l 2,archi=st-lrwan1:sx1276+site=saclay
The last command will return the experiment id <exp_id>
that will be used to check that the experiment state is "Running" and to get the nodes list.
<login>@saclay:~$ iotlab-experiment get -i <exp_id> -s
<login>@saclay:~$ iotlab-experiment get -i <exp_id> -r
Now get the code of 2019.01 release of RIOT and the code of my project from GitHub.
<login>@saclay:~$ git clone https://github.com/RIOT-OS/RIOT.git -b 2019.01-branch
<login>@saclay:~$ git clone https://github.com/domitix/CleverWeather
Replace the original main.c of the project with the one written by me to start publishing messages with random values and go to the RIOT folder:
<login>@saclay:~$ cp -a CleverWeather/LoRa/. RIOT/tests/pkg_semtech-loramac
<login>@saclay:~$ cd RIOT
Since this experiment runs in 2 different nodes, you can start another terminal and connect to IoT-LAB using SSH. Then follow the same procedure in both terminals using different ST LoRa nodes.
Change the arm gcc version with the one provided by IoT-LAB:
<login>@saclay:~/RIOT/$ export PATH=/opt/gcc-arm-none-eabi-7-2018-q2-update/bin:$PATH
Build the LoraWAN app:
<login>@saclay:~/RIOT/$ 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. In my case, I have used st-lrwan1-14, but it may change:
<login>@saclay:~/RIOT/$ iotlab-node --update tests/pkg_semtech-loramac/bin/b-l072z-lrwan1/tests_pkg_semtech-loramac.elf -l saclay,st-lrwan1,14
Access the RIOT shell running on your node using netcat:
<login>@saclay:~/RIOT/$ nc st-lrwan1-14 20000
Now you can interact with the LoRawAN stack running on the node through the command loramac.
First you need to set the parameters of the device of TTN app and a fast datarate (5):
> loramac set deveui 00000000000000
> loramac set appeui 00000000000000
> loramac set appkey 0000000000000000000000000000
> loramac set dr 5
Now you can join the network using the OTAA and start publishing messages:
> loramac join otaa
Join procedure succeeded!
> loramac publisher
If everything works, it should look like this, sending messages every 15 seconds.
- Gateway
The gateway is a python program that connects to the TTN app using the MQTT protocol. When a message arrives, the payload is decoded using base64 and then sent to the hub by an IoT device with the same name as that of the TTN device. To do this, for TTN part you will need the server location, TTN app name as username and application access key as password. For IoT Hub, you will need a connection string for every IoT device.
- Nodejs
You can run the web app simply going into the folder and typing in the command line:
npm start
If the gateway is connected, you will see the incoming messages in the command line:
Open in a browser http://localhost:3000/ and visualize the values.
These are the charts of the values sent from the first device (foggia_2):
And these are the charts of the values sent from the second device (rome_2):
Comments
Please log in or sign up to comment.