IoT Core Rule SQL Nested Query

0

Hi, I have an incoming message to IoT Core as in format: {"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 incoming message to below format: { "device":"test", "vals": [ { "column_name": "abc", "column_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 problem is, i am unable to use set.timestamp inside nested query.

here is my Rule SQL:

SELECT topic(2) AS device, (SELECT "1" AS id, dp.name AS column_name, dp.type AS column_type, 0 AS qc, set.timestamp as ts, CAST(dp.value AS String) AS val FROM set.datapoints as dp) AS vals FROM 'measurement/data/+/#'

Please suggest how i can add timestamp from incoming message to each datapoints objects as attribute.

已提问 2 个月前120 查看次数
1 回答
0

Hello,

Please be informed that, AWS IoT Rules Engine does not consists the complete native SQL engine's features. Hence, some queries would not produce the expected results. However the AWS IoT rules provide some great SQL functions as mentioned in the below document for performing various operations.

[+] Functions - aws_lambda(functionArn, inputJson) - https://docs.aws.amazon.com/iot/latest/developerguide/iot-sql-functions.html#iot-func-aws-lambda

Having said, you could try using "aws_lambda" SQL function where the input JSON from the MQTT topic can be passed to the Lambda function by which you could modify the payload as you like and return the modified JSON to AWS IoT and this could be a viable workaround for your use-case mentioned. Please feel free to look into the above link for more details on the same.

AWS
已回答 2 个月前
profile picture
专家
已审核 2 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则