Configure the MQTT Sparkplug API to collect IoT data from Pareto Anywhere.
Learn how to configure MQTT Sparkplug in ThingsBoard to collect data from Pareto Anywhere.
Pareto Anywhere (with barnacles-sparkplug) installed.
* Add the /barnacles-sparkplug module to act as MQTT Sparkplug client.
[OPTIONAL] Install ThingsBoard on the same Linux machine as Pareto Anywhere.
Skip this step if using an existing ThingsBoard instance!
Our instructions assume a Debian-based flavour of Linux such as Ubuntu or Pi OS. ( Official Guides)
ThingsBoard is programmed in Java, which may not be included by default in the given Linux distribution.
On the local server, open a terminal and refresh the package index with the command sudo apt update
Then install the latest headless OpenJDK with the command sudo apt install openjdk-21-jdk-headless*
* Change the version number (ex: 21) based on what is supported by the Linux distribution.
Confirm that the installed OpenJDK version is the default with the command sudo update-alternatives --config java
There is 1 choice for the alternative java (providing /usr/bin/java). Selection Path Priority Status ------------------------------------------------------------ * 0 /usr/lib/jvm/java-21-openjdk-arm64/bin/java 2111 auto mode 1 /usr/lib/jvm/java-21-openjdk-arm64/bin/java 2111 manual mode Press enter to keep the current choice[*], or type selection number:
At any time, it is possible to confirm the Java version with the command java -version
ThingsBoard v4.1 is recommended as the latest version which supports legacy Sparkplug clients (pre-Sparkplug 3.0).
In a terminal on the local server, download a specific version of ThingsBoard ( Releases Table) with the command wget https://github.com/thingsboard/thingsboard/releases/download/v4.1/thingsboard-4.1.deb*
* Find the latest release download path on /thingsboard/releases.
Then install the Debian package with the command sudo dpkg -i thingsboard-4.1.deb*
* Change the version number to match the downloaded package, if required.
Skip this step if a local PostgreSQL database was already installed with Pareto Anywhere!
ThingsBoard supports PostgreSQL and Cassandra databases. PostgreSQL alone is sufficient for most local deployments.
In a terminal on the local server, install PostgreSQL with the command sudo apt install postgresql
Then start the database with the command sudo service postgresql start
The PostgreSQL database will run automatically in the background.
In a terminal on the local server, log into the database as the postgres user with the command sudo -u postgres psql
Once logged in, the terminal prompt should change to postgres=#, accepting database queries. Enter the following queries:
CREATE USER tb WITH ENCRYPTED PASSWORD 'thinboar'; CREATE DATABASE thingsboard WITH OWNER tb; exit This will create a database called thingsboard owned by user tb with password thinboar.
In a terminal on the local server, edit the thingsboard.conf file with the command sudo nano /etc/thingsboard/conf/thingsboard.conf and add the following lines:
# DB Configuration export DATABASE_TS_TYPE=sql export SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/thingsboard export SPRING_DATASOURCE_USERNAME=tb export SPRING_DATASOURCE_PASSWORD=thinboar # Partitioning size allowed values: DAYS, MONTHS, YEARS, INDEFINITE. export SQL_POSTGRES_TS_KV_PARTITIONING=DAYS # Restrict to 2G RAM (should not be more than half available RAM) export JAVA_OPTS="$JAVA_OPTS -Xms2G -Xmx2G"
Change the USERNAME/PASSWORD if different from those suggested in Part 4 above.
Next, run the ThingsBoard installation script with the command sudo /usr/share/thingsboard/bin/install/install.sh >1 min
Finally, start the ThingsBoard service with the command sudo service thingsboard start
ThingsBoard should now be running and connected to the local PostgreSQL database, as will be validated in Step 2, below.
Create a MQTT Sparkplug B Edge of Network node for Pareto Anywhere.
Browse to the local ThingsBoard instance at localhost:8080.*
* If connecting remotely, change localhost to the IP address of the server.
Log in to ThingsBoard using the e-mail address and password of the tenant administrator.
If this is the first login to ThingsBoard, use the default credentials sysadmin@thingsboard.org | sysadmin and then create a new tenant, and add a tenant administrator.
In ThingsBoard, from the menu at left, select Device profiles from the Profiles category.
From the Device profiles page, select + to add a device profile, then select Create new device profile.
Configure the profile as follows:
Configure the transport as follows:
Configure device provisioning as follows:
Then click Add. The profile should appear in the device profiles table.
In ThingsBoard, from the menu at left, select Devices from the Entities category.
Configure the Device details as follows:
Configure the Credentials as follows:
Then click Add. The device should appear in the devices table.
The MQTT Sparkplug API is now configured for ThingsBoard to receive data from a local Pareto Anywhere instance—the Edge of Network node—which will be validated in Step 3, below.
Configure the barnacles-sparkplug module of Pareto Anywhere to connect to ThingsBoard.
Pareto Anywhere includes a startup script which initiates a local MQTT Sparkplug connection.
First, stop any running instance of Pareto Anywhere on the local server. Then, open a terminal and browse to the pareto-anywhere folder to start the Sparkplug script with the command npm run sparkplug*
* If prompted, first run npm install barnacles-sparkplug to install the module, then run the script again.
Once running, the Sparkplug script should produce console output which includes the following:
barnacles-sparkplug: connected to MQTT server
This indicates that the connection is successful, with real-time IoT data automatically published to ThingsBoard.
ThingsBoard versions >4.1 may not support the official sparkplug-client used by barnacles-sparkplug. See this ThingsBoard issue and this sparkplug-client issue for a temporary workaround.
Additional configuration of barnacles-sparkplug is required in the case of connection to:
Skip to Part 3 if connection was successful in Part 1, above.
From the terminal browse again to the pareto-anywhere folder and copy the Sparkplug script with the command cp bin/pareto-anywhere-sparkplug bin/pareto-anywhere-thingsboard
Open the copied script for editing with the command nano bin/pareto-anywhere-thingsboard
#!/usr/bin/env node
const ParetoAnywhere = require('../lib/paretoanywhere.js');
const BARNACLES_SPARKPLUG_OPTIONS = {
url: "mqtt://localhost",
groupId: "iot",
edgeNodeId: "paretoanywhere",
clientId: "ParetoAnywhereEdgeNode",
username: null,
password: null
};
// ----- Exit gracefully if the optional dependency is not found -----
let BarnaclesSparkplug;
try {
BarnaclesSparkplug = require('barnacles-sparkplug');
}
catch(err) {
console.log('This script requires the barnacles-sparkplug package. Try installing with:');
console.log('\r\n "npm install barnacles-sparkplug"\r\n');
return console.log('and then run this script again.');
}
// -------------------------------------------------------------------
let pa = new ParetoAnywhere();
// Add the Sparkplug interface
pa.barnacles.addInterface(BarnaclesSparkplug, BARNACLES_SPARKPLUG_OPTIONS);
Add both snippets highlighted in bold above, and edit the properties of the BARNACLES_SPARKPLUG_OPTIONS as required. Then save the script.
From the terminal in the pareto-anywhere folder, run the edited script with the command node bin/pareto-anywhere-thingsboard
Once running, the edited script should produce console output which includes the following:
barnacles-sparkplug: connected to MQTT server
This indicates that the connection is successful, with real-time IoT data automatically published to ThingsBoard.
In ThingsBoard, from the menu at left, select Gateways from the Entities category.
Pareto Anywhere should appear in the list with status Active. Click on Pareto Anywhere in the gateway list for more details.
If Pareto Anywhere has a source of real-time IoT data, the corresponding devices will appear in the Devices table as MQTT EoN Node device(s).
To view the most recent telemetry from any such device, from the menu at left, select Devices from the Entities category, then select a device from the list, and finally select the Latest telemetry tab from the device details overlay.
Pareto Anywhere will publish supported dynamb properties to ThingsBoard as telemetry data.
Our cheatsheet details the standard properties of the dynamb JSON output from Pareto Anywhere.
Tutorial prepared with ♥ by jeffyactive.
You can reelyActive's open source efforts directly by contributing code & docs, collectively by sharing across your network, and commercially through our packages.Continue exploring our open architecture and all its applications.