B.One Middleware Howto: Connection to the IoT Platform TagoIO

– 📖🕓 ≈ 6 min – In my last two articles I have already shown you how you can connect the B.One.Middleware to the IoT platforms TagoIO and Kaa. In this…
– 📖🕓 ≈ 6 min – In my last article I already showed you how you can connect the B.One Middleware to the IoT platform TagoIO. Today we come to the…
– 📖🕓 ≈ 6 min – Updated on 09/23/2022 1. General The B.One Middleware supports three different network protocols to forward the traffic of your own end devices. Depending on your…
– 📖🕓 ≈ 6 min – This Quick Guide is intended to help you find your way around the B.One Middleware more easily. The following step-by-step instructions explain the views of…
– 📖🕓 ≈ 5 min – In the last articles you have already been given a small introduction to the open source tool Grafana. It was also reported how to install…
– 📖🕓 ≈ 3 min – In the B.One Gallery, your sensor data is visualized in an appealing way. But is it also possible to export the raw data of your devices? You can find the answer in this post.
As you may already know, the versatile B.One Middleware can be flexibly connected to various IoT systems. In the following small series of articles I would like to share with you how exactly this works using the example of TagoIO, Thingsboard and Kaa. In each of the articles, I will go into how to create a sensor on the platform , how to connect the middleware to this platform (http or mqtt) and last but not least, how to visualize the data on so-called dashboards. I will start with the platform TagoIO.
However, before I get to the points mentioned at the beginning, a brief introduction to TagoIO. TagoIO is an open source IoT platform for collecting, processing and visualizing data. In the free version, the platform limits the number of devices/sensors that we can display. In this guide, however, I will show you a way to easily avoid the latter.
Before you can start, you must of course first register on the platform. As mentioned at the beginning, there is a free version, but there are some limitations compared to the paid versions. To create our first device, click on Devices in the top left of the input menu and select the Custom MQTT device. Then we can rename the device easily.
The device you just created now serves as a kind of "digital twin" that represents the actual sending physical device. In addition to the device, a so-called bucket was automatically created in which the incoming data from the device is stored. The bucket has the same name as the device and can be found in the menu under Buckets.
If we click on our device in the device menu, an overview with various information about it opens. Only the device token is important for us. This acts as a kind of password to gain access to the device from outside. Tokens are generated automatically, but can be changed at will.
Now that we have set up our "digital twin" on the platform, we can connect a real device to it. To circumvent the number of devices limited by the platform, we only use one device, which almost always serves as the entry point for incoming data. This also stores all data in the same bucket. We use MQTT as the transmission standard. The platform acts as a broker here. After setting up a corresponding forwarding as described in the blog article "Forwarding B.One Middleware ", the sensor data or all sensor data of a client are published to the broker. The following parameters are required for forwarding :
user: “Token” password: our device token host: “mqtt.tago.io” port: 1883
Example: mqtt://Token:ölakjdfn9@mqtt.tago.io:1883
When forwarding is active for a device, its activity can be tracked on the platform. To do this, click on Live Inspector in the Device menu and start it using the arrow icon.
If data arriving via a device is in "Tago format", it is stored in the appropriate bucket under an automatically generated variable (name/description). In the "Tago Format" the JSON payload must always have at least the keys "variable" and "value". Example:
[{
“variable”: “temperature”,
“value”: 71
}]
Since this is not the case in our case, the payload parser and an action must be used to adapt it. The payload parser can restructure the incoming telegrams, and actions are specific actions that are carried out as a result of self-configurable triggers. To set up a parser, go to Payload Parser in the Device menu and then click “Run your own parser” in the top right corner. Depending on which values are to be read from the sensor or visualized later, the parser must now be initialized.
Below is an example of sensor data as it could be published by the B.One.Middleware and an associated payload parser that assigns a separate variable to each value from payload_fields (summary of the data sent). In addition, the device ID of the sending device was added to the respective variable name so that we can later distinguish between the data in the bucket.
Sensor data:
{
“metadata”: {
“mqtt_topic” : “test/devices/test/up”
},
“payload_fields”: {
“ul_counter”: 2,
“dl_counter”:2,
“temperature” : 12,
“battery_level” : 24,
“latitude” : 1,
“longitude” : 1,
“latitude_dmm”: 1,
“longitude_dmm”: 1,
“gps_quality”: “good”,
“snr_dl”:2,
“rssi_dl”:2,
“stats”:4
“long_hemisphere”: “North”,
“lati_hemisphere”: “North”
},
“dev_id”: 1111111111111111
}
The values for longitude and latitude must be assembled into a value "location" for the platform to work with it.
Payload Parser:
if (payload && (!Array.isArray(payload)) || !payload[0].variable) {
if (Array.isArray(payload)) payload = payload[0];
//verschachtelte Daten
const payload_fields = { …payload.payload_fields};
//unverschachtelte Daten
const deviceId = String(payload.dev_id); //Name des Sensors/Device
const serie = new Date().getTime(); // generates a unique serie for this batch of data.
payload = [
{ variable: deviceId + “_ul_counter”, value: Number(payload_fields.ul_counter), serie },
{ variable: deviceId + “_dl_counter”, value: Number(payload_fields.dl_counter), serie},
{ variable: deviceId + “_temperature”, value: Number(payload_fields.temperature),unit: “°C”, serie },
{ variable: deviceId + “_battery_level”, value: Number(payload_fields.battery_level), serie},
{ variable: deviceId + “_latitude_dmm”, value: String(payload_fields.latitude_dmm), serie},
{ variable: deviceId + “_longitude_dmm”, value: String(payload_fields.longitude_dmm), serie},
{ variable: deviceId + “_gps_quality”, value: String(payload_fields.gps_quality), serie },
{ variable: deviceId + “_snr_dl”, value: Number(payload_fields.snr_dl), serie },
{ variable: deviceId + “_rssi_dl”, value: Number(payload_fields.rssi_dl), serie},
{ variable: deviceId + “_stats”, value: Number(payload_fields.stats), serie},
{ variable: deviceId + “_long_hemisphere”, value: String(payload_fields.long_hemisphere)},
{ variable: deviceId + “_lati_hemisphere”, value: String(payload_fields.lati_hemisphere)},
]
if(payload_fields.latitude && payload_fields.longitude){
//longitude & latitude müssen zu location zusammengefasst werden
payload.push({
variable: deviceId+ “_location”,
value: String(payload_fields.latitude)+ “, ” + String(payload_fields.longitude),
location: { lat: Number(payload_fields.latitude), lng: Number(payload_fields.longitude) }, serie,
})
}
}
To create the action, we go to Actions in the main menu. Then click on “Add Action” in the top right corner. For “Trigger” we now select “MQTT Topic” and for “Type of Action” “Insert into Device Bucket”. So data posted on a specific topic is routed to a bucket where the payload parser restructures and saves the data. We now select the device we have just created as the device and set the following topic for “ MQTT Topic” : “ +/devices/+/up ”. Under the latter, a summary of the complete telegram is published by all devices (wildcared “+”).
Now, when a device sends data, the corresponding variables under which the data was saved become visible in the device bucket.
In its free version, the platform offers us the possibility of creating up to five dashboards. We can place so-called widgets on these, with which we can display data in real time. Widgets can be simple maps where we can display individual values, but also more complex things like maps to show location or graphs to visualize data over time. To create our first dashboard, click on the “+” icon under Dashboard in the main menu. Then name the Dashboard and click on “Create Dashboard”. The new dashboard will now open automatically. At the top right we can now create our first widget again using the “+” icon. The platform offers a variety of widgets. However, in this tutorial we will only deal with the Map and Line widgets.
As our first widget we choose the Map widget. The configuration of the widgets is quite simple and does not differ significantly from each other. If we select a widget, a configuration overview will open. In this we now select our previously created device and as a variable “ devId_location”. Depending on taste, other optical parameters can be adjusted.
Next is an example of a Line widget that we can use to visualize the history of data over time. The process is again the same as with the map widget: We select one or more devices and the variable that we want to have visualized. Of course, we also have the opportunity to make further adjustments here.
So you now know how the B.One Middleware can be connected to a platform like TagoIO and how you can visualize your data on dashboards there. In the next article I will show you this using the Kaa platform. Until then, have fun trying it out!
COOKIES: