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년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠