This script allows you to receive messages published on MQTT topic, select data, and publish this data via HTTP request. the script is developed to work between The Things Network and Things Board. The ThingsBoard Professional Edition of Things Board allows you to read a Topic MQTT directly and a Gateway module is available to do the same.
- download the zip of the project
https://github.com/guiguitt/gateway_ttn-thingsboard/archive/master.zip
- or clone on your computer
git clone https://github.com/guiguitt/gateway_ttn-thingsboard.git
to execute the script that requires the python environment. for linux:
https://docs.python-guide.org/starting/install3/linux/
for windows:
http://winpython.sourceforge.net/
and 4 module
- Paho-mqtt
pip3 install paho-mqtt
- requests
pip3 install requests
- json
- datatime
- MQTT
- BROKER:
for TTN is it is included in the application handler
- topic:/devices/
- +/devices/+/up - for messages sent from node
- +/devices/+/down - for messages receive by node
- +/devices/+/events/activations - (communication activate of node
- +/devices/+/+ - all things of communicate
- PORT: We generally use the port 1883
- KEEP_ALIVE: 45 is good
- ClientId: turn on your imagnation
- TTN
- App_ID: the Name of your application on TTN (at the overview top )
- AccessKey: the access key of your application (at the overview bottom)
- THINGS
- URL: url of your ThingsBoard
- PublicID: ->customers->copy customers ID
- add a user
gateway_ttn
on the server:sudo adduser gateway_ttn
. - clone the current repository in the home of this newly added user.
su gateway_ttn
cd
git clone https://github.com/guiguitt/gateway_ttn-thingsboard.git
exit
- configure the systemctl service by editing the file
/etc/systemd/system/gateway_ttn.service
as root
sudo nano /etc/systemd/system/gateway_ttn.service
The content of /etc/systemd/system/gateway_ttn.service
:
[Unit]
Description=Gateway between TTN and Thingsboard
After=network.target
StartLimitIntervalSec=0
[Service]
Type=simple
Restart=always
RestartSec=1
User=gateway_ttn
ExecStart=/usr/bin/env python3 /home/gateway_ttn/gateway_ttn-thingsboard.py
[Install]
WantedBy=multi-user.target
- Start the service:
sudo systemctl start
- Check if the service is working properly:
sudo systemctl status gateway_ttn.service
gateway_ttn.service - Gateway between TTN and Thingsboard
Loaded: loaded (/etc/systemd/system/gateway_ttn.service; disabled; vendor preset: enabled)
Active: active (running) since Wed 2019-06-26 11:36:58 CEST; 8ms ago
Main PID: 27385 (python3)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/gateway_ttn.service
└─27385 python3 /home/gateway_ttn/gateway_ttn-thingsboardpy
- enable service at startup with command ````sudo systemctl enable gateway_ttn.service```
For the gateway to work correctly, the Device ID on TTN must match the corresponding device on the things board.
- created a new device on Things board.
- copy your device ID.
- creates a new device on TTN with this device ID and the EUI device of the node.
- then enter the EUI application and the appKey in the node program. in description in TTN it is recommended to place the device name and a link to the thingsboard