How to Transform Incoming IoT Core Message using IoT Core Rule SQL

16 views Asked by At

I am receiving incoming messages as

{"set":
  {"datapoints":[
    {"name":"abc","type":"int","value":151},
    {"name":"pqr","type":"int","value":246}],
  "timestamp":"2024-03-07T10:42:55.902Z"
  }
}

I want to transform this Message to another format as below:

{
    "vals": [
        {
            "name": "abc",
            "type": "Int",
            "timestamp": "2024-03-07T10:07:35.3405950Z",
            "val": "0"
        },
        {
            "name": "pqr",
            "type": "Int",
            "timestamp": "2024-03-07T10:07:35.3406800Z",
            "val": "0"
        }
    ]
}

The timestamp attribute should be part of each datapoint object in the result vals array. i wrote the Rule SQL

  SELECT
    (SELECT 0 AS id,
      dp.name AS name dp.type AS type,
      set.timestamp as ts,
      dp.value AS val
    FROM dset.datapoints as dp) AS vals
  FROM 'topic/data/+/#'

I am unable to get timestamp value. How can I add timestamp value to each datapoints element?

0

There are 0 answers