Install ThingsBoard Gateway from Source
Generate an SSH Key to Clone the GitHub Repository
Move to the home directory of the gateway:
cd ~Generate an SSH key:
ssh-keygenYou don’t need to enter any special configuration values for your SSH key if prompted. Simply press Enter for each prompt until the command has finished running.
Visit the directory where your SSH key can now be found:
cd .sshDisplay the public key. Copy it.:
cat id_rsa.pubGo to the GitHub and log in with your account associated with the gateway repository
Navigate to Settings > SSH and GPG keys > New SSH Key
Paste the public key in the Key box
Install ThingsBoard Gateway
Move to the home directory of the gateway:
cd ~Install dependencies:
sudo apt update && sudo apt install python3-dev python3-pip libglib2.0-dev git mosquitto mosquitto-clientsInstall python dependencies:
pip install cython PyYAMLClone the repository:
git clone --single-branch --branch thingsboard-master git@github.com:drexelwireless/thingsboard-gateway.gitMove to the repository:
cd thingsboard-gateway/thingsboard-gatewayInstall the gateway python module:
sudo python3 setup.py installCopy the service files:
Move to the directory the service files will live in:
cd /etc/systemd/systemCopy the service files to the current directory:
cp ~/thingsboard-gateway/setup_files/*.service .<– the period here is important
Notify the system that daemons were changed:
sudo systemctl daemon-reload
Create Gateway Device
Go to the VarIoT Devices panel
Click the “+” button near the upper right corner to create a new device:
Give it a name
Check the “Is a gateway” box
Click “Add”
Click on the new device in the list then click the “Copy access token” button
Configure ThingsBoard Gateway
Move to the config directory of the gateway:
cd ~/thingsboard-gateway/thingsboard-gateway/thingsboard_gateway/configEdit the main gateway config file:
nano tb_gateway.yamlReplace
host: thingsboard.cloudwithhost: variot.ece.drexel.eduReplace
accessToken: PUT_YOUR_ACCESS_TOKEN_HEREwith the copied access tokenPress
Ctrl-O <Enter> Ctrl-Xto save and exit
Optional: VPN
If VPN access is needed, install it with:
sudo apt install openconnect network-manager-openconnect-gnomeConnect with:
sudo openconnect -u <your Drexel abc123> <vpn.drexel.edu>Be sure to type in Drexel when prompted for the Group. The password is the same one you use to login to your Drexel Connect account.
The VPN login sequence requires Two-Factor Authentication (2FA). Be sure to check your mobile phone when prompted for the security response.
The VPN output should look like the following:
sudo openconnect -u abc123 vpn.drexel.edu POST https://vpn.drexel.edu/ Connected to 144.118.1.196:443 SSL negotiation with vpn.drexel.edu Connected to HTTPS on vpn.drexel.edu with ciphersuite (TLS1.2)-(ECDHE-SECP256R1)-(RSA-SHA512)-(AES-256-GCM) XML POST enabled Please enter your username and password: GROUP: [DrexelVPN|IRT-Application-Test|IRT-Private|IRT-Private-MSmfa|VPN-ANS-Private|VPN-DPS-Private|VPN-Drexel-Trusted-Clients|ZNG-VPN-Drexel-Trusted-Clients]:Drexel POST https://vpn.drexel.edu/ XML POST enabled Please enter your username and password: Password:
Run ThingsBoard Gateway
Start the ThingsBoard service:
sudo service thingsboard-gateway startEnable the Thingsboard service on start-up:
sudo systemctl enable thingsboard-gateway.serviceCheck the service status:
sudo service thingsboard-gateway status(Press q to return to the prompt)The ouput should look like the following:
● thingsboard-gateway.service - ThingsBoard Gateway Loaded: loaded (/etc/systemd/system/thingsboard-gateway.service; disabled; vendor preset: enabled) Active: active (running) since Thu 2022-04-14 20:18:27 EDT; 1s ago Main PID: 16994 (python3) Tasks: 11 (limit: 8986) CPU: 935ms CGroup: /system.slice/thingsboard-gateway.service └─16994 /usr/bin/python3 /home/pi/thingsboard-gateway/thingsboard-gateway/thingsboard_gateway/tb_gateway.pyBe sure to check there is no line in the status that contains
|ERROR| - [tb_device_mqtt.py] - tb_device_mqtt - _on_connect - 146 - connection FAIL with error 5 not authorised". This error means the gateway failed to connect to ThingsBoard due to a bad access token.Once everything is running smoothly, use the following command to send a telemetry packet to ThingsBoard:
mosquitto_pub -d -q 1 -h "variot.ece.drexel.edu" -p "1883" -t "v1/devices/me/telemetry" -u "$ACCESS_TOKEN" -m {"temperature":25}. Be sure to replace$ACCESS_TOKENwith your access code.Navigate to the devices panel of ThingsBoard, click on your gateway device, then the “Latest Telemetry” tab. If everything worked the way it should, you should see an entry with key “temperature” and value “25”.