Querying bridged MQTT passing into DynamoDB

0

I can't get a rule working, for MQTT messages being passed into IOT.

In the Test rule I'm subscribing to "mygateway2-out/////+" and which gets the following JSON:
{
"topicFilter": "mygateway2-out/////+",
"qos": 0,
"messages": [
{
"format": "json",
"topic": "mygateway2-out/61/1/1/0/0",
"timestamp": 1621297559099,
"payload": 14.9
}
]
}

I have a DynamoDB table with 'sample_time' and 'value' and am trying to populate it with a Rule that looks like this:

SELECT messages,
(SELECT VALUE payload FROM messages) as value,
FROM 'mygateway2-out/////+'

I'm not getting anything populated in the table. I've also tried:
SELECT payload FROM 'messages' as value
and
SELECT payload FROM messages as value
and
SELECT messages, (SELECT VALUE payload FROM messages) as value
and
SELECT VALUE payload FROM messages as value

None of which is inserting any rows in my table.

已提問 3 年前檢視次數 174 次
1 個回答
0

The problem I had was the bridged MQTT was not sending the 'payload' in json format.
{
"format": "json",
"topic": "mygateway2-out/20/0/1/0/0",
"timestamp": 1621717535170,
"payload": 56
}

I would not have had this problem if the "payload" was sent like this:
...
"payload": {
"temperature": 28
}

So I needed to build the json sql query to convert the payload into a numerical value:
SELECT cast(concat(substring(decode(encode(, 'base64'),'base64'),0, 2), ".", substring(decode(encode(, 'base64'),'base64'),3, 8)) as Decimal) AS value FROM 'mygateway2-out///1/0/0'

Now the numerical values get inserted as "NUM" (numbers) in my DynamoDB table.

已回答 3 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南