最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

mqtt - Want to Plot the List of values in the ThingsBoard Dashboard - Stack Overflow

programmeradmin0浏览0评论
Component
Dashboard
UI
Rule Engine
Environment
OS: Linux
ThingsBoard: 3.9.0
Browser: chrome and Version: 134.0.6998.89

Description

I am using ThingsBoard Gateway with Connector Type: MQTT. and i have created a device using that Gateway which is working perfectly fine. but my device is sending the values in a List. example-

Topic:- testDevice/telemetry
Value:- {"MACADDRESS": "00:00:00:00:00:00", "CH_NO": "0", "ADC_VAL": \[0.01, -0.19, -0.2, -0.05, -0.17, -0.08, -0.27, -0.52, -0.18, -0.05, -0.08, -0.23, -1.5, -0.14, -1.69, -0.88, -0.2, -1.54, -0.06, -1.42, -0.11, -1.48, -1.15, -0.18, -0.12, -1.55, -1.64, -0.02, -0.12, -1.5, -0.2, -0.09, -0.11, -1.55, -1.16, -0.39, -1.17, -0.08, -0.18, -1.5, -1.51, -0.03, -0.02, -0.0, -0.6, -1.67, -1.2, -0.8, -1.37, -0.17, -0.14, -0.16, -0.11, -1.35, -0.02, -1.57, -1.1, 0.07, -1.39, -0.55, -0.25, -0.08, 0.0, -0.15, -1.16, -0.17, -1.55, -1.35, -0.76, -0.17, -0.09, -0.14, -1.19, -0.02, -0.02, -0.7, 0.05, -0.21, -0.04, -1.26, -0.02, -0.17, -1.3, -0.12, 0.02, -1.07, -0.3, -1.5, -1.38, -0.17, -1.52, -1.22, -1.47, -1.39, -1.14, -0.17, -0.08, -0.18, -0.16, -1.21, -0.25, -0.06, -0.16, -0.69, -1.06, -0.94, -0.09, -1.4, -0.09, -0.15, -1.16, -0.05, -0.08, -0.31, -0.11, -1.49, -1.6, -0.2, -1.27, -1.33, -1.49, -0.07, 0.04, -0.14, -0.06, -0.13, -1.44, -1.41, -0.12, -1.5, -0.22, -1.27, -1.39, -1.37, -1.35, -1.52, 0.01, -1.24, -1.55, -0.06, -0.14, -0.24, -1.51, -0.11, -0.09, -0.63, -1.56, -0.13, -1.24, -0.18, -0.68, -1.35, -1.31, -1.41, -0.1, -0.29, -1.46, -1.33, -1.38, -1.38, -0.99, -0.61, -0.2, -0.09, -0.04, -0.28, -0.65, -1.37, -1.46, -1.15, -0.3, -0.13, -0.98, -1.43, -1.21, -1.46, -1.41, -1.32, -0.61, -1.35, -1.13, -1.02, -1.23, -0.03, -0.08, -1.35, -0.17, -0.56, -1.5, -1.4, -1.44, -0.11, -1.32, -1.25, -1.53, -0.28, -1.24, -1.36, -1.7, -1.53\]}

and in the device also i am getting the same value as my device is publishing, but i want to show the values in the ThingsBoard Dashboard and as the values in the List i am unable to display the graph using list of values in the Dashboard and it is directly showing the whole List in the Dashboard because as per my knowledge the Dashboard is only displaying the Values from the Database, and as you know in the DB the values are stored in the single Timeseries.

So, what other way i have used is i thought may be if we change the Rule Chain then after the Post Telemetry only the value should go to the DB and as per the Dashboard is only using that values it should work!! but this is also not working !! i wrote a Script right after "message type switch" as Post Telemetry and after the Script i have connected with the Timeseries as below image..

and i wrote the script like below..

function Transform(msg, metadata, msgType) {
 if (msg.ADC_VAL && Array.isArray(msg.ADC_VAL)) {
    var values = msg.ADC_VAL; // Extract list of ADC values
    var result = [];
    var baseTimestamp = Date.now(); // Get current timestamp for unique values

    for (var i = 0; i < values.length; i++) {
    // Clone metadata to avoid modifying the original
    var newMetadata = JSON.parse(JSON.stringify(metadata));

    // Ensure required metadata fields are included
    newMetadata.ts = baseTimestamp + i * 100;  // Unique timestamp per value
    newMetadata.deviceName = msg.MACADDRESS || "Unknown Device";
    newMetadata.deviceType = metadata.deviceType || "SensorProfile";
    newMetadata.key = metadata.key || "ADC_VAL"; // You can set a default key if needed

    // Create individual message for each ADC value
    var transformedMsg = {
        msg: {
            "ADC_VAL": values[i], // One individual ADC value
            "CH_NO": msg.CH_NO    // Channel number from incoming message
        },
        metadata: newMetadata, // Each message will have its own metadata
        msgType: msgType
    };

     // Push each transformed message to result
     result.push(transformedMsg);
  }
 // Instead of returning the entire array of objects, return each message separately
 return result;  // This will send multiple individual messages
} else {
// If ADC_VAL is not an array, return the message unchanged
return [{ msg: msg, metadata: metadata, msgType: msgType }]; 
} 
}

and using this script and "Test script function (JavaScript)" i got the below result..

[{ "msg": { "ADC_VAL": 0.01, "CH_NO": "0" }, "metadata": { "deviceType": "SensorProfile", "deviceName": "00:00:00:00:00:00", "key": "ADC_VAL", "ts": "1742291449930" }, "msgType": "POST_TELEMETRY_REQUEST" }, { "msg": { "ADC_VAL": -0.19, "CH_NO": "0" }, "metadata": { "deviceType": "SensorProfile", "deviceName": "00:00:00:00:00:00", "key": "ADC_VAL", "ts": "1742291450030" }, "msgType": "POST_TELEMETRY_REQUEST" }, { "msg": { "ADC_VAL": -0.2, "CH_NO": "0" }, "metadata": { "deviceType": "SensorProfile", "deviceName": "00:00:00:00:00:00", "key": "ADC_VAL", "ts": "1742291450130" }, "msgType": "POST_TELEMETRY_REQUEST" }, { "msg": { "ADC_VAL": -0.05, "CH_NO": "0" }, "metadata": { "deviceType": "SensorProfile", "deviceName": "00:00:00:00:00:00", "key": "ADC_VAL", "ts": "1742291450230" }, "msgType": "POST_TELEMETRY_REQUEST" }, . . . rest values . . , { "msg": { "ADC_VAL": -1.53, "CH_NO": "0" }, "metadata": { "deviceType": "SensorProfile", "deviceName": "00:00:00:00:00:00", "key": "ADC_VAL", "ts": "1742291469830" }, "msgType": "POST_TELEMETRY_REQUEST" }]

i have only splited the values with timeseries as you can see in the above output!! But i don't know whether this is the correct method or JSON to work on here But it is not working for me and also if is there a way to directly plot the List in the Dashboard also tell me how to do that !!

发布评论

评论列表(0)

  1. 暂无评论