Open main menu

DAVE Developer's Wiki β

Changes

MISC-TN-021: SBCSPG and ThingsBoard IoT

2,955 bytes added, 13:56, 27 June 2022
Remote logging
==Introduction==
This Technical Note (TN) illustrates how to run [https://thingsboard.io/docs/iot-gateway/what-is-iot-gateway/ ''ThingsBoard IoT Gateway'' software] on the [[MISC-TN-004:_Running_Debian_(armbian)_on_SBCSPG#The_hardware_platform|SBCSBP gateway product]] running Debian Busterand get it working in tandem with [https://thingsboard.io/docs/ ''ThingsBoard IoT platform'']. As an example, the following configuration was set up:
also shows how As an example, the following configuration was set up: [[File:MISC-TN-021-block-diagram.png|center|thumb|600x600px]] ''ThingsBoard IoT Gateway'' is interfaced to connect a local MQTT broker (''[https://mosquitto.org/ Mosquitto]'') via the [https://thingsboard.io/docs/iot-gateway /config/mqtt/ MQTT connector]. On the network side, ''ThingsBoard IoT Gateway'' is connected to a server running an instance of ''[https://thingsboard.io/docs/ ThingsBoard IoT platform Community Edition]''. For the sake of simplicity, this instance was installed on a PC. The PC and the SBCSPG gateway are connected to the same LAN. Obviously, in a more realistic scenario, the ThingsBoard IoT platform would be installed on a remote server or on a cloud infrastructure. See [https://thingsboard.io/docs/user-guide/install/installation-options/ this page] for more information about installation options.
==Installing ''ThingsBoard IoT Gateway''==
To The unit used for this TN was equipped with [[MISC-TN-004: Running Debian (armbian) on SBCSPG|Debian Buster]]. As such, to install ''ThingsBoard IoT Gateway'' , it is possible to make use of the <code>.deb</code> package as described in the [https://thingsboard.io/docs/iot-gateway/install/deb-installation/ official documentation]. In order to run the software, it It was also necessary to upgrade manually the package <code>protobuf</code> as shown in the following boxto prevent a fatal error upon ''ThingsBoard IoT Gateway'' starting: <pre class="board-terminal">
$ sudo pip3 install --upgrade protobuf
Requirement already satisfied: protobuf in /usr/local/lib/python3.7/dist-packages (3.10.0)
== Testing ==
To test the configuration, it is possible to publish some data with the help of the <code>mosquitto_pub</code> client tool. In the following example, two data points, associated to the variables ''temperature'' and ''humidity'', are published :
 
<pre class="board-terminal">
armbian@sbcspg:~$ mosquitto_pub -h 127.0.0.1 -p 1883 -u "testuser" -P "testuser" -t "/sensor/SN-001/data" -m '{"sensorType": "Thermometer", "sensorModel": "T1000", "temp": 22, "hum": 55}'
</pre>
 
By setting the logging level of the broker to <code>all</code>, a lot of useful messages are printed. For example, they come to help for understanding if the data are received properly by the ''ThingsBoard IoT Gateway''<nowiki/>'s MQTT connector:
 
<pre class="board-terminal">
armbian@sbcspg:~$ sudo tail -n 100 -f /var/log/mosquitto/mosquitto.log
...
1643982761: New connection from 127.0.0.1 on port 1883.
1643982761: New client connected from 127.0.0.1 as mosqpub|4975-sbcspg (c1, k60, u'testuser').
1643982761: No will message specified.
1643982761: Sending CONNACK to mosqpub|4975-sbcspg (0, 0)
1643982761: Received PUBLISH from mosqpub|4975-sbcspg (d0, q0, r0, m0, '/sensor/SN-001/data', ... (76 bytes))
1643982761: Sending PUBLISH to ThingsBoard_gateway (d0, q0, r0, m0, '/sensor/SN-001/data', ... (76 bytes))
1643982761: Received DISCONNECT from mosqpub|4975-sbcspg
1643982761: Client mosqpub|4975-sbcspg disconnected.
1643982811: Received PINGREQ from ThingsBoard_gateway
1643982811: Sending PINGRESP to ThingsBoard_gateway
</pre>
 
In turn, ''ThingsBoard IoT Gateway'' finally sends the data to the ''ThingsBoard IoT platform'':
 
[[File:SBCSPG-ThingsBoard-1.png|center|thumb|600px]]
 
=== Remote logging ===''ThingsBoard'' provides the ''Remote logging'' functionality too. It can be extremely helpful when it comes to debug connections issues, for instance. It can be enabled as described [https://thingsboard.io/docs/iot-gateway/configguides/mqtthow-to-enable-remote-logging/here].
armbian@sbcspg:~$ mosquitto_sub -h localhost -t testThe following image shows how it looks like in a ''Timeseries widget'' in the ''ThingsBoard platform'' environment.
armbian@sbcspg[[File:~$ mosquitto_pub SBCSPG-h localhost ThingsBoard-t test -m "hello world"2.png|center|thumb|800x800px]]
armbian@sbcspg== Video ==Watch our dedicated video were is possible to see this demo in action:~$ mosquitto_sub -h localhost -t testhello world{{#ev:youtube|4TteWI8jG08|600|center|ThingsBoard IoT on Gateway ioT|frame}}
4,650
edits