Skip to main content

Ubidots 集成(通过 TTS)

note

本文档由 AI 翻译。如您发现内容有误或有改进建议,欢迎通过页面下方的评论区,或在以下 Issue 页面中告诉我们:https://github.com/Seeed-Studio/wiki-documents/issues

Ubidots 是一个低代码物联网应用开发平台,可以快速组装和启动物联网应用,而无需编写代码或雇佣软件开发团队。目前,已有超过 40,000 个应用通过 Ubidots 实现了连接。

为了满足构建物联网应用的日益增长的需求,我们与 Ubidots 合作,支持社区通过 The Things Network 轻松将 SenseCAP T1000 Tracker 添加到 Ubidots。

pir

在开始设置之前,请先查看 将 SenseCAP T1000 连接到 TTS,以先将您的 SenseCAP T1000 Tracker 连接到 TTS。

配置 Ubidots

首先,创建一个 Ubidots 账户。

登录到您的 Ubidots 账户,在仪表板顶部找到 Devices 标签。在下拉列表中选择 Plugins

Ubidots 插件

点击 +Create Data Plugin 按钮以创建一个新插件。

pir

当显示可用插件时,选择 The Things Stack 插件。

pir

接下来,您需要选择一个 Ubidots token。您可以使用 Default token,也可以创建一个新 token。

pir

要创建一个新 token,首先点击右上角的头像并选择 API Credentials。然后在 Default token 下选择 More,并在 API Credentials 页面中添加一个新 token。

pir

选择 > 继续,然后点击复选标记完成。

pir

配置解码器

创建插件后,进入解码器部分,删除所有代码并替换为以下内容:

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,
}

// 分配数据键值到 Ubidots 负载
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;
}
};

// 构建 Ubidots 负载
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 };

配置 The Things Stack

当您在 Ubidots 上完成设置后,需要通过使用 Ubidots Webhook 模板在 The Things Stack 上创建一个 Webhook 集成。

在 The Things Stack 上,导航到 IntegrationsWebhooks,然后点击 Add Webhook

pir

选择 Ubidots Webhook 模板。

pir

通过填写 Webhook ID,并粘贴 Plugin ID 和 Ubidots token 值来命名您的集成。

pir

info

要找到插件 ID,点击您新创建的插件并导航到左侧的 Decoder 标签。插件 ID 可在 HTTPs Endpoint URL 中找到(如下图所示)。

pir

监控您的数据

完成集成后,导航到 Devices 菜单。只要您的终端设备发送上行消息,您就会在终端设备列表中看到它的出现。

pir

Loading Comments...