• a Python MQTT Transparent Bridge
  • a Riot-OS firmware which retrieves real environment data
  • The Things Network MQTT bridge

Architecture

Complete Architecture
The Things Network architecture

Prerequisites

First of all, you need to pull the update from my GitHub repository. If you have not already done it, I highly recommend you to check my previous tutorials and videos.

  1. How to setup an IoT system using ThingsBoard: blog-post, video, GitHub
  2. How to develop an IoT device using RIOT-OS and connect it to Thingsboard using MQTT-SN: blog-post, video, GitHub
  • device/riot/sensors_lora
  • brokers/TTN_BT_Gateway

Configure a TTN application

Before using the LoRa nodes on IoT-LAB, you need an account and an application with a device configured on TTN.

  1. If you do not already have a TTN account, create one from here.
The Things Network | Add application
  • Device EUI: the device unique identifier is an 8 bytes array.
  • Application EUI: the application unique identifier is an 8 bytes array.
  • Application Key: the application key is a 16 bytes array.
TTN devices
function Decoder(bytes, port) {I 
let result = "";
for (let byte in bytes) {
result += String.fromCharCode(bytes[byte]);
}
return {"string": result};
}

Riot-OS firmware

I build a riot firmware which automatically connects to the LoRa Gateway and sends telemetry data by reading from the temperature and humidity sensors every PERIOD .

main.c get_payload
Makefile

Thingsboard

In this tutorial, you will have to make a few changes to the Thingsboard compared to the previous configuration. You just have to create a new gateway and take notes of the access token.

Creation of a new Gateway device

Transparent Gateway

I built a transparent gateway using the paho.mqtt library. It is very simple, it connects to MQTT TTN broker and Thingsboard broker. The most important part is the callback on receiving messages from TTN. In this tutorial, I decided to write a transparent gateway from scratch and not configure mosquitto with 2 different connections because it is also necessary to modify the incoming packet.

TTN_TN_Gatway

Configuration

Remember to replace the data entered in the mysecrets.example.py file with your ones. Then:

mv mysecrets.example.py mysecrets.py
ACCESS_TOKEN_TB_GATEWAY = 'hwi5VuEHBYsqPvS6fAAA'
THINGSBOARD_IP = "64.227.26.128"
TTN_APPID = 'tutorialiot' TTN_KEY = 'ttn-accountv2.7SPdlSUMHyWyBwSR6x0Bxn5nuNWfXfPYaf1wD0aaaa'

IoT-Lab setup

  1. Access to saclay: ssh <username>@saclay.iot-lab.info
  2. Clone RIOT repository (already done see Tutorial 2)
  3. Setup gcc compiler
cd ~/RIOT
source /opt/riot.source
export PATH=/opt/gcc-arm-none-eabi-7-2017-q4-major/bin:$PATH
arm-none-eabi-gcc --version # to check whether is 7.x
mkdir ~/RIOT/examples/mylorawan
cd device/riot
scp sensors_lora/* colasant@saclay.iot-lab.info:~/RIOT/examples/mylorawan
make -C examples/mylorawan clean all
iotlab-experiment submit -n riot_ttn -d 120 -l 1,archi=st-lrwan1:sx1276+site=saclay
iotlab-experiment get -r
iotlab-node --update lorawan.elf -l saclay,st-lrwan1,<dev_id>
nc st-lrwan1-<dev_id> 20000
IoT-Lab node is running
TTN_TB_Gateway example

Dashboard

Now we can enjoy our data directly from the dashboard. Congratulations, you have been great!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Francesco Colasante

Francesco Colasante

Sapienza University — Engineering in Computer Science