2 | How to develop an IoT device using RIOT-OS and connect it to Thingsboard using MQTT-SN

IoT cloud-based system using Thingsboard, MQTT, RIOT-OS and IoT-LAB
git pull
git submodule update --init --recursive
  • brokers : it contains all configurations of the broker and the gateway. In addition, there are 2 submodules to fetch directly source code of mosquitto.rsmb and paho MQTT-SN Transparent Gateway.
  • device/riot : contains the RIOT source folder for the IoT device and a small script set_network.sh to easily configure network interfaces on native deployment.

RIOT-OS

  • energy-efficiency and real-time capabilities;
  • small memory footprint and modularity;
  • uniform API access: independent of the underlying hardware (POSIX).

Thingsboard

IoT devices are no longer directly connected to Thingsboard MQTT, hence we need to change our default topic. Now, we will publish telemetry over:

Topic: v1/gateway/telemetry
{
"Device A": [
{
"ts": 1483228800000,
"values": {
"temperature": 42,
"humidity": 80
}
}
],
"Device B": [
{
"ts": 1483228800000,
"values": {
"temperature": 42,
"humidity": 80
}
}
]
}
Thingsboard gateway configuration
DRIVER ?= lps331ap        #to use directly sensors
USEMODULE += $(DRIVER)
USEMODULE += saul_default #sensors API
custom shell commands on riot

MQTT-SN

MQTT-SN is a publish/subscribe messaging protocol for wireless sensor networks (WSN), with the aim of extending the MQTT protocol beyond the reach of TCP/IP infrastructure for Sensor and Actuator solutions.

MQTT-SN Architecture
BrokerName=localhost
BrokerPortNo=1884
GatewayUDP6Bind=fec0:affe::1/64
GatewayUDP6Port=1885
cd brokers/MQTTSN-Gateway
./custom_install.sh
mv gateway.conf gateway.conf.bkp
cp ../conf/MQTTSN-Gateway.conf gateway.conf
mosquitto -c brokers/conf/bridge_gateway_prod.conf
cd brokers/MQTTSN-Gateway
./MQTT-SNGateway
cd device/riot/sensors_mqttsn
./start_network.sh
PORT=tap0 make clean all term
RIOT native, MQTTSN trasparent bridge and mosquitto
ifconfig 5 add fec0:affe::99
con fec0:affe::1 1885
set_device "Device Piano"
pub v1/gateway/telemetry "{ 'Device Piano': [ { 'ts': 1585744760000, 'values':{'humidity': 42 }}]}" 1
pub_telemetry
  • set_device <device_name> : is a custom command which I wrote to setup dynamically the device name
  • pub <topic> <payload> is a default command available emcute_mqttsn
  • pub_telemetry : is a custom command which I wrote to directly push random data (in case of native applications) to <device_name>
  • pub_data : is a custom command to continuously push data using another thread. (Not use it for now, it is only a stub to multi-thread programming)
A RIOT execution
Multi-device dashboard
Device Dashboard

IoT-LAB

  1. Register to IoT-Lab.
  2. Configure SSH Access (link).
  3. Follow this tutorial
ssh <username>@saclay.iot-lab.info
#mv to your src folder
source /opt/riot.source
BOARD=iotlab-m3 make all
iotlab-experiment submit -n riot_m3 -d 60 -l 1,archi=m3:at86rf231+site=saclay
iotlab-experiment get -i <exp_id> -r
iotlab-node --update <your_binary>.elf -l saclay,m3,<dev_id>
nc <dev_id> 20000

--

--

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