如何通过Websocket从Thingsboard检索所有客户设备的遥测 [英] How to retrieve telemetry for all customer devices from Thingsboard via websocket
问题描述
我想通过Websocket通过API通过API通过物联网CE获取与单个客户相关的所有设备的最新遥测.这样我就可以在收到测量结果时实时更新jquery数据表.
I want to get the latest telemetry for all devices related to a single customer from thingsboard CE via API over a websocket. So that I can update a jquery datatable in real-time when measurements are received.
之后通过GUI手动添加customer->device
的关系,最新的遥测数据现在流到Thingsboard中的CUSTOMER实体类型.
after manually adding a relation for customer->device
via GUI latest telemetry data is now flowing to the CUSTOMER entityType in Thingsboard.
但是;返回的数据不包含任何设备属性信息,我可以使用这些信息来将ws响应与生成测量值的设备相匹配.
However; the data returned does not contain any device attribute information that I can use to match the ws response to the device that generated the measurements.
{"subscriptionId":10,"errorCode":0,"errorMsg":null,"data":{"battery_voltage":[[1559065098932,"2.8623046875"]],"pressure":[[1559065098932,"0.05001525953412056"]],"relative_humidity":[[1559065098932,"53.7109375"]],"temperature":[[1559065098932,"83.78323364257812"]]},"latestValues":{"battery_voltage":1559065098932,"temperature":1559065098932,"pressure":1559065098932,"relative_humidity":1559065098932}}
Thingsboard中的端点:/api/ws/plugins/telemetry
endpoint in Thingsboard:/api/ws/plugins/telemetry
此代码有效并返回最新的遥测更新,但未在返回的结果中指定哪个设备.
this code works and returns latest telemetry update, but it doesn't specify which device in the returned result.
$( document ).ready(function() {
...
webSocket.onopen = function () {
var object = {
tsSubCmds: [{
entityType: "CUSTOMER",
entityId: "00000000-0000-0000-0000-0000...",
scope: "LATEST_TELEMETRY",
cmdId: 10
}
],
historyCmds: [],
attrSubCmds: []
};
var data = JSON.stringify(object);
webSocket.send(data);
console.log("Message is sent: " + data);
console.log("socket open: ");
};
如何使用设备属性丰富遥测时间序列数据?
How can i enrich the telemetry timeseries data with device attribute?
推荐答案
我找到的解决方案是更新GUI中的规则链,以便复制传入的DEVICE遥测数据的副本并将其保存到相关的CUSTOMER实体
The solution I found was to update the rule-chain in the GUI so that a copy of the incoming DEVICE telemetry data is duplicated and saved to the related CUSTOMER entity.
逐步:
-
以租户管理员身份登录Thingsboard
login to thingsboard as a tenant administrator
单击Root Rule Chain
在Post telemetry
分支上找到Save timeseries
节点
将新的filter...script
节点拖到画布上
将新脚本节点连接到Post Telemetry
分支上Save timeseries
节点的输出
connect the new script node to the output of the Save timeseries
node on the Post Telemetry
branch
编辑过滤器脚本名称:-> Should Duplicate
edit the filter script name: -> Should Duplicate
编辑过滤器脚本功能-> return true;
edit the filter script function -> return true;
将新的Transformation...change originator
节点拖到画布上
将新的转换节点连接到过滤器节点的输出
connect the new transformation node to the output of the filter node
编辑转换节点名称:Reassign to Customer
编辑创建者源:Customer
将新的Action...save timeseries
节点拖到画布上
将新的Action节点连接到Transformation节点的输出
Connect the new Action node to the output of the Transformation node
编辑操作节点名称:Save Related Telemetry
您的根规则链现在应该看起来像这样:
Your root rule chain should now look similar to this:
这篇关于如何通过Websocket从Thingsboard检索所有客户设备的遥测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!