问题
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.
after manually adding a relation for customer->device
via GUI latest telemetry data is now flowing to the CUSTOMER entityType in Thingsboard.
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}}
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?
回答1:
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.
Step by step:
login to thingsboard as a tenant administrator
click on the
Root Rule Chain
find the
Save timeseries
node on thePost telemetry
branchdrag a new
filter...script
node onto the canvasconnect the new script node to the output of the
Save timeseries
node on thePost Telemetry
branchedit the filter script name: ->
Should Duplicate
edit the filter script function ->
return true;
drag a new
Transformation...change originator
node to the canvasconnect the new transformation node to the output of the filter node
edit the Transformation node name:
Reassign to Customer
edit the originator source:
Customer
drag a new
Action...save timeseries
node onto the canvasConnect the new Action node to the output of the Transformation node
edit the Action node name:
Save Related Telemetry
Your root rule chain should now look similar to this:
来源:https://stackoverflow.com/questions/56345204/how-to-retrieve-telemetry-for-all-customer-devices-from-thingsboard-via-websocke