Skip to main content

Ubidots Integrated(via TTS)

Ubidots is a low-code IoT application development platform that enabled rapidly assembling and launching IoT applications without having to write code or hire a software development team. Nowadays, over 40,000+ applications already connect the dots with Ubidots.

To meet the growing need for building IoT applications, we’ve been cooperating with Ubidots and supporting the community to add SenseCAP T1000 Tracker easily to Ubidots through The Things Network.

pir

Before starting the setup, please check Connect SenseCAP T1000 to TTS to connect your SenseCAP T1000 Tracker to TTS first.

Configure Ubidots

To get started, create an account with Ubidots.

Log in to your Ubidots account and find the Devices tab in the upper part of your dashboard. In its drop-down list, choose Plugins.

Ubidots Plugins

Click on the + or on the Create Data Plugin button to create a new plugin.

pir

When you are presented with available plugins, select The Things Stack plugin.

pir

Next, you need to select a Ubidots token. You can use the Default token, also can create a new token.

pir

To create a new token, first click on your avatar in the upper right corner and select API Credentials. Then select More below the Default token and add a new token within the API Credentials page.

pir

Select > to continue and then hit the checkmark to finish.

pir

Configure the Decoder

Once created the plugin, go to the decoder section, delete all the code and replace it for the following:

pir

const HOTSPOT_INFO = false;

function handleErrorIfExists(data){
const error = 'error' in data;
if (error) {
const errorMsg = { "error": { "value": data.errorCode, "context" : { "reason": data.error } } };
return errorMsg;
}
return false;
}

function addLat(lat, ubidotsPayload){
ubidotsPayload.position.context.lat = lat;
}

function addLng(lng, ubidotsPayload){
ubidotsPayload.position.context.lng = lng;
}

const coordinateActions = {
"Longitude": addLng,
"Latitude": addLat,
}

const assignPayloadKeys = (data, ubidotsPayload) => {
const { type, measurementValue } = data;

if (type === "Longitude" || type === "Latitude") {
if (!ubidotsPayload.position) {
ubidotsPayload.position = { "value": 1, "context": { "lat": undefined, "lng": undefined } };
}
coordinateActions[type](measurementValue, ubidotsPayload);
}
else if (data.type === "Timestamp") {
ubidotsPayload.timestamp = data.measurementValue;
}
else {
ubidotsPayload[type] = measurementValue;
}
};

function buildUbidotsPayload(data){
const ubidotsPayload = {};
data.forEach(innerData => {
innerData.forEach(innerInnerData => {
assignPayloadKeys(innerInnerData, ubidotsPayload);
});
});
return ubidotsPayload;
}

async function formatPayload(args){

const data = args.uplink_message.decoded_payload.messages;
let ubidotsPayload = {};

const error = handleErrorIfExists(data[0][0]);
if (error) return error;

if (HOTSPOT_INFO) {
const { hotspots, port, fcnt } = args;
const { snr, rssi } = hotspots[0];
Object.assign(ubidotsPayload, { SNR: snr, RSSI: rssi, port, 'Frame Counter': fcnt });
}
ubidotsPayload = buildUbidotsPayload(data);
console.log(ubidotsPayload);
return ubidotsPayload;
};

module.exports = { formatPayload };

Configure The Things Stack

When you have prepared the setup on Ubidots, then you need to create a Webhook integration on The Things Stack by using the Ubidots Webhook template.

On The Things Stack, navigate to IntegrationsWebhooks, and click Add Webhook.

pir

Choose the Ubidots Webhook template.

pir

Name your integration by filling in the Webhook ID, and paste the Plugin ID and Ubidots token values.

pir

info

To find the plugin ID, click on your newly created plugin and navigate to the Decoder tab on the left. The plugin ID is available as part of the HTTPs Endpoint URL (as highlighted on the image below).

pir

Monitor Your Data

After you have completed the integration, navigate to Devices menu. You will see your end device appearing in the end devices list as soon as it sends an uplink message.

pir

Loading Comments...