How to split up data from one device to multiple devices

How to split up data from one device to multiple devices

@Vitor Lima

Splitting up data from one device to multiple devices (MQTT/NodeRed)

Quick setup an analysis to split up data in different devices based on a ID or Serial. Very useful when sending data to TagoIO using MQTT/NodeRed.

In this tutorial, you will learn:

  • How to create a network
  • How to create a connector
  • Setup an analysis to split the data when MQTT publish is received.

Why do I need to split data from a device?

There are a few situations when you can only send data to one device using MQTT or other kind of integration. When that happens, it is recommended to split the data some way into different devices of your account.
TagoIO main features expects for a device to represents a sensor. Blueprint dashboards only works with that structure, and it is the most useful resource for scaling applications.

Having a different device for each sensor also make easier to pull data from the device when needed, as there is no need to check each data of the device to know from which sensor it belongs.

What do I need to split data from a device?

You will need an working application, which means you need to have your Gateway/Device already communicating with TagoIO using a Custom MQTT or other connector integration.

Step 1: Create your network

The network will provide some routes to find a device in your account, that had been created using the network. Later on we will see that in use on the analysis script.

1 Go to Integration Network to add a network. In this example, the network name is UG65 Network.

  1. After creating, enable the Serial Number setting and generate a network token, then save the settings.

  1. Copy the network by clicking in the copy icon. Save it to use later.

Step 2: Create your connector

  1. Go to Integration Connector to add a connector. When adding, select the network you created. You can create connectors for different device types and add corresponding information and decoders.
  2. Enter a name. This is just a standard way to integrate new sensors for a network in TagoIO.
  3. You can create other connectors for different device models you may have. It can be good later to use different payload parsers if you need.
  4. On the connector screen, you don’t need to fill up anything if you don’t want to.

Step 3: Create your Split Devices Analysis

This step is one of the most important, as the analysis code is responsible for doing all the job of splitting up your data into different devices.

The script provided in this step does have in-code comments, that you can read to understand each section of the code. You will need to use the scope parameter of the analysis, that is the content that you sent to the analysis, and then get the correct parameter that contains the Serial of your device.
If needed, you can always add a console.log(scope) to see exactly what you’re receiving on the scope parameter.

  1. Now install following analysis template by clicking here

  2. In the analysis screen, go to Environment Variables.

  3. You can place the Network token in the value of the network_token key.

  4. You need a account-token from your profile for the account-token value. Generate one in you ProfileTokens.

  5. Press the save button.

Step 4: Create your action to trigger the analysis

We need to create an Action, it will be responsible to understand when the Analysis must run and on which conditions.

In this case, we want the analysis to trigger when we receive any message from a specific topic on our Device MQTT Connection. So this is how we set it up:

  1. Go to Action to add an action, select the type as MQTT Topic and action as Run Analysis , then select the analysis you created.

  2. Go to Action tab to add an action, select the type as MQTT Topic and action as Run Analysis , then select the analysis you created.

Step 5: Create your devices

As the end of the tutorial, you only need now to create devices using the connectors you created, and making sure you input serial that you’re sending to the MQTT.

You can create devices by accessing Devices+ Add DeviceMy Networks.