Open main menu

DAVE Developer's Wiki β

Changes

Introduction
==Introduction==
ORCAIn essence, this Technical Note (TN) is very similar to [[MISC-TN-024: Automated test equipment (ATE) monitoring with SBCSPG gateway and ThingsBoard IoT platform|''MISC-TN-001_—_Running_Armbian_Bullseye_024: Automated test equipment (Debian_11ATE)monitoring with SBCSPG gateway and ThingsBoard IoT platform'']]. There is a noticeable difference, however, as a different software stack was used on the edge device. In this case, [https://www.lfedge.org/projects/fledge/ Fledge] was utilized.
LAN ==Testbed==The edge device is the [[MISC-TN-004:_Running_Debian_(armbian)_on_SBCSPG#The_hardware_platform|SBCSPG gateway]] running Debian Bullseye. To deploy this distribution onto the target, the same approach described [[ORCA-TN-001_—_Running_Armbian_Bullseye_(Debian_11)|here]] was used. Unlike Orca SBC, SBCSPG is based on a 32-bit ARM Cortex-A7 processor, though. As such, a [https://mirrors.dotsrc.org/armbian-dl/tritium-h3/archive/Armbian_22.11.1_Tritium-h3_bullseye_current_5.15.80_minimal.img.xz different image] was used.30
To install Fledge, the <code>apt</code>-based approach described [https://github.com/fledge-iot.readthedocs.io/en/fledge-south-modbustcplatest/quick_start/pullinstalling.html here] was followed. It is worth to remember that some dependencies were handled manually. For instance, <code>autoconf</26code> and <code>libtool</filescode> packages were installed manually.
===Enabling the connection to the PLC===
As described in [[MISC-TN-024: Automated test equipment (ATE) monitoring with SBCSPG gateway and ThingsBoard IoT platform|''MISC-TN-024'']], the PLC we want to talk to is connected to a different subnet, namely 192.168.30.0/24. For testing the connection to the PLC, after adding the required subnet configuration, the <code>modbus</code> command line tool was used, which is provided by the <code>modbus_cli</code> package. In the following example, the register mapped ad the address 300 is read.
You can think about this This Technical Note (TN) as an evolution of the article <pre class="[[MISC-TNboard-021: SBCSPG and ThingsBoard IoT]]terminal". The use case described here is a real-world application based on the same elements: * [[MISC-TN-004: Running Debian (armbian) on SBCSPG#The hardware platform|The ''SBCSPG'' industrial gateway]] >* [httpsroot@sbcspg:/usr/local/thingsboard.iofledge/docspython/ ''ThingsBoard IoT platform''] * [https:fledge/plugins/thingsboardnorth# ip addr add 192.io/docs/iot-gateway/what-is-iot-gateway/ ''ThingsBoard IoT gateway'']168. The application is to monitor robotized DAVE Embedded Systems' ATEs like the one shown [https://youtu30.be253/OoNiKgJXq00?t=409 here].24 dev eth0 label eth0:1
== Implementation ==armbian@sbcspg:~/devel/fledge$ pip install modbus_cliThe implementation Defaulting to user installation because normal site-packages is suitable for a production environmentnot writeableRequirement already satisfied: modbus_cli in /home/armbian/.local/lib/python3.9/site-packages (0.1.8)Requirement already satisfied: colorama in /home/armbian/.local/lib/python3. Unlike what we did for [[MISC9/site-TNpackages (from modbus_cli) (0.4.6)Requirement already satisfied: umodbus in /home/armbian/.local/lib/python3.9/site-021packages (from modbus_cli) (1.0.4)Requirement already satisfied: SBCSPG and ThingsBoard IoT|this TN]], pyserial~=3.4 in this case the ThingsBoard IoT platform was installed on the cloud, specifically on an AWS EC2 instance running Ubuntu Linux/usr/local/lib/python3. The following diagram shows the complete solution9/dist-packages (from umodbus->modbus_cli) (3.5)
[notice] A new release of pip is available: 23.0 -> 23.0.1[Filenotice] To update, run: python3 -m pip install --upgrade pip...armbian@sbcspg:ATE monitoring SBCSPG ThingsBoard~$ .png|center|thumb|1000x1000px]]/.local/bin/modbus 192.168.30.42:502 300Parsed 0 registers definitions from 1 files300: 32 0x20</pre>
Technically, We then configured Fledge in order to read periodically a couple of PLC's registers. Please note that this is a no-code operation as it is carried out with the gateway can communicate with help of the ATE using different physical links and protocolsnative web-based Fledge UI. In the example under discussionTo access PLC exposed data, the physical link is Ethernet and the protocol is ModbusFledge's <code>modbustcp</TCPcode> South plugin was used. The gateway retrieves periodically some data regarding the robotic arm used Please note that also we had to patch it manually to move the device under test (DUT)solve a bug that prevented it from working properly. These data are The patch is detailed [https://www.universal-robotsgithub.com/articles/ur/interfacefledge-communicationiot/modbusfledge-server/ exposed by the PLC governing the arm] and are documented in detail [https://s3south-eu-west-1.amazonaws.commodbustcp/ur-support-sitepull/1637726/ModBus%20server%20data.pdf files here]. To make the change effective, we disabled and re-enabled the plugin via the web interface.
=== ThingsBoard IoT configuration ===[[File:SBCSPG-Fledge-2.png|center|thumb|600x600px|Installing the <code>modbustcp</code> South plugin.]]To install ThingsBoard IoT platform on an EC2 instance, [https[File://thingsboardSBCSPG-Fledge-3.io/docs/userpng|center|thumb|600x600px|Configuring the plugin]][[File:SBCSPG-guide/install/cluster/awsFledge-self4.png|center|thumb|600x600px|Configuring the plugin.]][[File:SBCSPG-hostedFledge-setup/ these instructions5.png|center|thumb|600x600px|The plugin is enabled.]] were followed[[File:SBCSPG-Fledge-6. png|center|thumb|600x600px|Fledge provides a native web interface to visualize collected data. ]]
 === Enabling the connection to ThingsBoard IoT gateway configuration platform ===In order to upload collected data to ThingsBoard platform, a simple North plugin was developed. To run this esampleend, the most important module Microsoft Azure plugin was used as reference. The ThingsBoard North plugin is minimalist and '''unfit for a real-world production environment'''. Nevertheless, it was enough to configure perform the basic tests described in this document. Before testing this new plugin, the <code>mosquitto-clients</code> package was installed as the plugin invokes the [https<code>mosquitto_pub</code> command line tool. <pre class="board-terminal">root@sbcspg:/usr/thingsboard.iolocal/docsfledge/iot-gatewaypython/configfledge/modbusplugins/ Modbus connector]north# apt install mosquitto mosquitto-clientsReading package lists... DoneBuilding dependency tree... DoneReading state information... DoneThe following additional packages will be installed: libcjson1 libdlt2 libev4 libmosquitto1 libwebsockets16Suggested packages: apparmorThe following box shows the resulting configuration file needed NEW packages will be installed: libcjson1 libdlt2 libev4 libmosquitto1 libwebsockets16 mosquitto mosquitto-clients0 upgraded, 7 newly installed, 0 to remove and 8 not upgraded.Need to poll some variables get 715 kB of the arm's joints (namely temperatures and currents)archives.After this operation, 1,492 kB of additional disk space will be used.<syntaxhighlight lang="json">armbian@sbcspgDo you want to continue? [Y/n] Get:1 http:~$ cat /etc/thingsboarddeb.debian.org/debian bullseye/main armhf libcjson1 armhf 1.7.14-gateway1 [20.5 kB]Get:2 http://deb.debian.org/configdebian bullseye/modbusmain armhf libdlt2 armhf 2.18.json6-1+deb11u1 [46.1 kB]{Get:3 http://deb.debian.org/debian bullseye/main armhf libev4 armhf 1:4.33-1 [38.6 kB] "master"Get:4 http: {//deb.debian.org/debian bullseye/main armhf libmosquitto1 armhf 2.0.11-1 [83.5 kB] "slaves"Get:5 http: //deb.debian.org/debian bullseye/main armhf libwebsockets16 armhf 4.0.20-2 [163 kB] {Get:6 http://deb.debian.org/debian bullseye/main armhf mosquitto armhf 2.0.11-1 [253 kB] "host"Get:7 http: "192//deb.debian.168org/debian bullseye/main armhf mosquitto-clients armhf 2.300.42"11-1 [110 kB]Fetched 715 kB in 0s (1,817 kB/s) Selecting previously unselected package libcjson1:armhf.(Reading database ... 72206 files and directories currently installed.)Preparing to unpack .../0-libcjson1_1.7.14-1_armhf.deb ...Unpacking libcjson1:armhf (1.7.14-1) ...Selecting previously unselected package libdlt2:armhf.Preparing to unpack .../1-libdlt2_2.18.6-1+deb11u1_armhf.deb ... "port"Unpacking libdlt2:armhf (2.18.6-1+deb11u1) ...Selecting previously unselected package libev4:armhf.Preparing to unpack .../2-libev4_1%3a4.33-1_armhf.deb ...Unpacking libev4:armhf (1: 502,4.33-1) ... "type"Selecting previously unselected package libmosquitto1: "tcp",armhf.Preparing to unpack .../3-libmosquitto1_2.0.11-1_armhf.deb ... "method"Unpacking libmosquitto1: "socket",armhf (2.0.11-1) ... "timeout"Selecting previously unselected package libwebsockets16: 35,armhf.Preparing to unpack .../4-libwebsockets16_4.0.20-2_armhf.deb ... "byteOrder"Unpacking libwebsockets16: "BIG",armhf (4.0.20-2) ...Selecting previously unselected package mosquitto.Preparing to unpack .../5-mosquitto_2.0.11-1_armhf.deb ...Unpacking mosquitto (2.0.11-1) ...Selecting previously unselected package mosquitto-clients.Preparing to unpack .../6-mosquitto-clients_2.0.11-1_armhf.deb ...Unpacking mosquitto-clients (2.0.11-1) ... "retries"Setting up libmosquitto1: true,armhf (2.0.11-1) ... "retryOnEmpty"Setting up libev4:armhf (1: true,4.33-1) ... "retryOnInvalid"Setting up libcjson1: true,armhf (1.7.14-1) ...Setting up mosquitto-clients (2.0.11-1) ... "pollPeriod"Setting up libdlt2: 5000,armhf (2.18.6-1+deb11u1) ... "unitId"Setting up libwebsockets16: armhf (4.0.20-2) ...Setting up mosquitto (2.0.11-1,) ...Created symlink /etc/systemd/system/multi-user.target.wants/mosquitto.service → /lib/systemd/system/mosquitto.service.Processing triggers for libc-bin (2.31-13+deb11u5) ...</pre> The following box shows the code of the ThingsBoard plugin.  <syntaxhighlight lang="deviceNamepython": class"UR5mw-collapsible=", "sendDataOnlyOnChangemw-collapsed": true, ="connectAttemptTimeMs"># -*- coding: 5000,utf-8 -*-  "connectAttemptCount": 5, "waitAfterFailedAttemptsMsThingsBoard North plugin": 300000, "timeseries": [ {import asyncioimport timeimport jsonimport sysimport os   from fledge.common import loggerfrom fledge.plugins.north.common.common import *  __author__ = "tagAndrea Marson": __copyright__ = "base_joint_temperature_deg_CCopyright (c) 2023 DAVE Srl", __license__ = "typeApache 2.0": __version__ = "16int${VERSION}", _LOGGER = logger.setup(__name__) _CONFIG_CATEGORY_NAME = "functionCodeTHINGSBOARD": 3, _CONFIG_CATEGORY_DESCRIPTION = "objectsCountThingsBoard Python North Plugin": 1, "address": 300 },_DEFAULT_CONFIG = { 'plugin': { "tag" 'description': "shoulder_joint_temperature_deg_C"'ThingsBoard North Plugin', " 'type"': "16int"'string', "functionCode" 'default': 3'thingsboard', "objectsCount" 'readonly': 1'true' }, "addresstb_iot_platform_host": 301 },{ { "tagdescription": "base_joint_current_mAThingsBoard IoT platform host.", "type": "16intstring", "functionCodedefault": 3, "objectsCountput the public name of your host here": 1, "address": 290 }, { "tagorder": "shoulder_joint_current_mA2", "typedisplayName": "16intThingsBoard IoT platform host" }, "functionCodetb_mqtt_topic": 3,{ "objectsCountdescription": 1, "addressMQTT topic": 291 }, { "tagtype": "elbow_joint_current_mAstring", "typedefault": "16intv1/devices/me/telemetry", "functionCodeorder": "3", "objectsCountdisplayName": 1"MQTT topic", "address" 'readonly': 292'true' }, "tb_device_access_token": { "tagdescription": "wrist1_joint_current_mADevice's access token.", "type": "16intstring", "functionCodedefault": 3"put your device's token here", "objectsCountorder": 1"4", "addressdisplayName": 293"Device's access token" }, "source": { "tagdescription": "wrist2_joint_current_mASource of data to be sent on the stream.", "type": "16intenumeration", "functionCodedefault": 3, "objectsCountreadings": 1, "address": 294 }, { "tagoptions": ["wrist3_joint_current_mAreadings"], "typeorder": "16int5", "functionCodedisplayName": 3, "objectsCountSource": 1, "address" 'readonly': 295 } ] } ]'true'
}
def plugin_info(): return { 'name': 'thingsboard', 'version': '2.1.0', 'type': 'north', 'interface': '1.0', 'config': _DEFAULT_CONFIG } def plugin_init(data): _LOGGER.info('Initializing ThingsBoard North Python Plugin') global thingsboard_north, config thingsboard_north = ThingsBoardNorthPlugin() config = data _LOGGER.info(f'config = {config}') return config """Example of payload [{'reading': {'base_joint_temperature_deg_C': 34, 'base_joint_current_mA': 2042}, 'asset_code': 'Modbus TCP', 'id': 35613, 'ts': '2023-02-22 16:33:49.961000+00:00', 'user_ts': '2023-02-22 16:33:47.126849+00:00'}, {'reading': {'base_joint_temperature_deg_C': 34, 'base_joint_current_mA': 2045}, 'asset_code': 'Modbus TCP', 'id': 35614, 'ts': '2023-02-22 16:33:49.961000+00:00', 'user_ts': '2023-02-22 16:33:48.126817+00:00'}, {'reading': {'base_joint_temperature_deg_C': 34, 'base_joint_current_mA': 2060}, 'asset_code': 'Modbus TCP', 'id': 35615, 'ts': '2023-02-22 16:33:49.961000+00:00', 'user_ts': '2023-02-22 16:33:49.126827+00:00'}] Example of upload mosquitto_pub -d -q 1 -h "$THINGSBOARD_HOST_NAME" -t "v1/devices/me/telemetry" -u "$ACCESS_TOKEN" -m '{"base_joint_temperature_deg_C":33}'"""async def plugin_send(data, payload, stream_id): try: _LOGGER.info(f'ThingsBoard North Python - plugin_send: {stream_id}') _LOGGER.info(f'data = {data}') _LOGGER.info(f'payload = {payload}') _LOGGER.info(f'host = {data["tb_iot_platform_host"]["value"]}') for reading in payload: _LOGGER.info(f'reading = {reading}') _LOGGER.info(f'reading[reading] = {reading["reading"]}') s = 'mosquitto_pub -d -q 1 -h "' + data["tb_iot_platform_host"]["value"] + '" -t "' + data["tb_mqtt_topic"]["value"] + '" -u "' + data["tb_device_access_token"]["value"] + '" -m \'' + str(reading["reading"]) + "\'" _LOGGER.info(f's = {s}') os.system(s) except asyncio.CancelledError as ex: _LOGGER.exception(f'Exception occurred in plugin_send: {ex}') else: _LOGGER.info('payload sent successfully') return True, payload[len(payload-1)]["id"], len(payload) def plugin_shutdown(data): pass # TODO: North plugin can not be reconfigured? (per callback mechanism)def plugin_reconfigure(): pass class ThingsBoardNorthPlugin(object): """ North ThingsBoard Plugin """  
</syntaxhighlight>
 == Dashboards Visualization of uploaded data ==ThingsBoard IoT allows Similarly to create easily custom dashboards to visualize data. At what we did in [[http://ec2-15-160-47-190.euMISC-southTN-1.compute.amazonaws.com024:8080/dashboard/1178fb20Automated test equipment (ATE) monitoring with SBCSPG gateway and ThingsBoard IoT platform|''MISC-e56dTN-11ec-8592-e3cb29424137?publicId=28967df0-e56d-11ec-8592-e3cb29424137 this link024'']] such , we created a simple dashboard is available showing some temperatures and currents of to visualize in real-time on cloud side collected data as shown in the arm's jointsfollowing example.[[File:ATE monitoring SBCSPG ThingsBoard dashboard1-Fledge-8.png|center|thumb|600x600px|Visualization of uploaded data.]]
4,650
edits