Difference between revisions of "MISC-TN-021: SBCSPG and ThingsBoard IoT"

From DAVE Developer's Wiki
Jump to: navigation, search
(Remote logging)
(21 intermediate revisions by 2 users not shown)
Line 23: Line 23:
  
 
==Introduction==
 
==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]] and get it working in tandem with [https://thingsboard.io/docs/ ''ThingsBoard IoT platform''].
+
This Technical Note 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 Buster.
  
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 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 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 install
 +
 
 +
https://thingsboard.io/docs/iot-gateway/install/deb-installation/
 +
 
  
==Installing ''ThingsBoard IoT Gateway''==
+
<pre class="board-terminal">
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]. It was also necessary to upgrade manually the package <code>protobuf</code> as shown in the following box to prevent a fatal error upon ''ThingsBoard IoT Gateway'' starting: <pre class="board-terminal">
 
 
$ sudo pip3 install --upgrade protobuf
 
$ sudo pip3 install --upgrade protobuf
 
Requirement already satisfied: protobuf in /usr/local/lib/python3.7/dist-packages (3.10.0)
 
Requirement already satisfied: protobuf in /usr/local/lib/python3.7/dist-packages (3.10.0)
Line 46: Line 47:
 
</pre>
 
</pre>
  
==Installing ''Mosquitto'' MQTT broker==
+
==Installing==
  
On the gateway, an MQTT broker was installed as well, namely ''[https://mosquitto.org/ Mosquitto]''. For more details, please refer to [https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-debian-9 this tutorial].
+
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-debian-9
  
 
<pre class="board-terminal">
 
<pre class="board-terminal">
Line 102: Line 103:
 
Processing triggers for libc-bin (2.28-10) ...
 
Processing triggers for libc-bin (2.28-10) ...
 
</pre>
 
</pre>
 
== 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 ===
+
armbian@sbcspg:~$ mosquitto_sub -h localhost -t test
''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/guides/how-to-enable-remote-logging/ here].
 
  
The following image shows how it looks like in a ''Timeseries widget'' in the ''ThingsBoard platform'' environment.
 
  
[[File:SBCSPG-ThingsBoard-2.png|center|thumb|800x800px]]
+
armbian@sbcspg:~$ mosquitto_pub -h localhost -t test -m "hello world"
  
== Video ==
+
armbian@sbcspg:~$ mosquitto_sub -h localhost -t test
Watch our dedicated video were is possible to see this demo in action:
+
hello world
{{#ev:youtube|4TteWI8jG08|600|center|ThingsBoard IoT on Gateway ioT|frame}}
 

Revision as of 16:20, 3 February 2022

Info Box
SBCSPG-1.jpg Applies to SBCSPG
Cloud-computing-banner.jpg Applies to IoT
Warning-icon.png This technical note was validated against specific versions of hardware and software. It may not work with other versions. Warning-icon.png


History[edit | edit source]

Version Date Notes
1.0.0 February 2022 First public release

Introduction[edit | edit source]

This Technical Note illustrates how to run ThingsBoard IoT Gateway software on the SBCSBP gateway product running Debian Buster.


Installing ThingsBoard IoT Gateway[edit | edit source]

To install

https://thingsboard.io/docs/iot-gateway/install/deb-installation/


$ sudo pip3 install --upgrade protobuf
Requirement already satisfied: protobuf in /usr/local/lib/python3.7/dist-packages (3.10.0)
Collecting protobuf
  Downloading protobuf-3.19.4-py2.py3-none-any.whl (162 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 162.7/162.7 KB 702.7 kB/s eta 0:00:00
Installing collected packages: protobuf
  Attempting uninstall: protobuf
    Found existing installation: protobuf 3.10.0
    Uninstalling protobuf-3.10.0:
      Successfully uninstalled protobuf-3.10.0
Successfully installed protobuf-3.19.4

Installing[edit | edit source]

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-the-mosquitto-mqtt-messaging-broker-on-debian-9

root@sbcspg:~# sudo apt install mosquitto mosquitto-clients
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  libev4 libmosquitto1 libuv1 libwebsockets8
Suggested packages:
  apparmor
The following NEW packages will be installed:
  libev4 libmosquitto1 libuv1 libwebsockets8 mosquitto mosquitto-clients
0 upgraded, 6 newly installed, 0 to remove and 129 not upgraded.
Need to get 491 kB of archives.
After this operation, 936 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://httpredir.debian.org/debian buster/main armhf libev4 armhf 1:4.25-1 [34.7 kB]
Get:2 http://httpredir.debian.org/debian buster/main armhf libmosquitto1 armhf 1.5.7-1+deb10u1 [57.8 kB]
Get:3 http://httpredir.debian.org/debian buster/main armhf libuv1 armhf 1.24.1-1+deb10u1 [98.3 kB]
Get:4 http://httpredir.debian.org/debian buster/main armhf libwebsockets8 armhf 2.0.3-3 [85.8 kB]
Get:5 http://httpredir.debian.org/debian buster/main armhf mosquitto armhf 1.5.7-1+deb10u1 [147 kB]
Get:6 http://httpredir.debian.org/debian buster/main armhf mosquitto-clients armhf 1.5.7-1+deb10u1 [67.0 kB]
Fetched 491 kB in 0s (1001 kB/s)        
Selecting previously unselected package libev4:armhf.
(Reading database ... 56701 files and directories currently installed.)
Preparing to unpack .../0-libev4_1%3a4.25-1_armhf.deb ...
Unpacking libev4:armhf (1:4.25-1) ...
Selecting previously unselected package libmosquitto1:armhf.
Preparing to unpack .../1-libmosquitto1_1.5.7-1+deb10u1_armhf.deb ...
Unpacking libmosquitto1:armhf (1.5.7-1+deb10u1) ...
Selecting previously unselected package libuv1:armhf.
Preparing to unpack .../2-libuv1_1.24.1-1+deb10u1_armhf.deb ...
Unpacking libuv1:armhf (1.24.1-1+deb10u1) ...
Selecting previously unselected package libwebsockets8:armhf.
Preparing to unpack .../3-libwebsockets8_2.0.3-3_armhf.deb ...
Unpacking libwebsockets8:armhf (2.0.3-3) ...
Selecting previously unselected package mosquitto.
Preparing to unpack .../4-mosquitto_1.5.7-1+deb10u1_armhf.deb ...
Unpacking mosquitto (1.5.7-1+deb10u1) ...
Selecting previously unselected package mosquitto-clients.
Preparing to unpack .../5-mosquitto-clients_1.5.7-1+deb10u1_armhf.deb ...
Unpacking mosquitto-clients (1.5.7-1+deb10u1) ...
Setting up libmosquitto1:armhf (1.5.7-1+deb10u1) ...
Setting up libev4:armhf (1:4.25-1) ...
Setting up mosquitto-clients (1.5.7-1+deb10u1) ...
Setting up libuv1:armhf (1.24.1-1+deb10u1) ...
Setting up libwebsockets8:armhf (2.0.3-3) ...
Setting up mosquitto (1.5.7-1+deb10u1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/mosquitto.service -> /lib/systemd/system/mosquitto.service.
Processing triggers for systemd (241-7~deb10u5) ...
Processing triggers for man-db (2.8.5-2) ...
Processing triggers for libc-bin (2.28-10) ...


armbian@sbcspg:~$ mosquitto_sub -h localhost -t test


armbian@sbcspg:~$ mosquitto_pub -h localhost -t test -m "hello world"

armbian@sbcspg:~$ mosquitto_sub -h localhost -t test hello world