1
votes

My weather-station is publishing its status via MQTT to AWS IoT.

The message is published to topic $aws/things/my-weather-station-001/shadow/update and looks like this:

{
 "state": {
   "reported": {
      "temperature" : 22,
      "humidity" : 70,
       ....
      "wind" : 234,
      "air" : 345
   }
 }

After message is received I have create a rule to store it in AWS DynamoDB the rules select statement is:

SELECT state.reported.* FROM $aws/things/+/shadow/update/accepted

And when this works well, whilst I am sending messages containing state.reported field.

However sometimes to the topic $aws/things/weather-station-0001/shadow/update are sent "control" messages telling device to switch on an LED or some other part. These messages would be usually sent by an app or a controlling server and look like this notice that instead of reported field it hasdesired

{
 "state": {
   "desired": {
      "led1" : "on",
      "locked" : true
   }
 }

So when these messages are arriving, they ARE STILL processed by the rule and arrive to the DynamoDb table with {} empty payload.

Is there any way to force the Rule to ignore messages not containing state.reported element?

1
If you are trying to update the thing shadow over MQTT the topic should be $aws/things/<thing_name>/shadow/update - cementblocks
Thank you @cementblocks for your suggestion, however I believe you're incorrect in this case. In order to receive an update which is "confirmed" by AWS IoT you need to subscribe to $aws/things/<thing_name>/shadow/update/accepted or if you're interested in deltas to ../shadow/update/delta. If you subscribe only to ..shadow/update you are NOT really using shadows service, but simply getting back the update you sent (including when it is malformed). You can read more on that on docs.aws.amazon.com/iot/latest/developerguide/… - Dimitry K
This line in your question The message is published to topic $aws/things/my-weather-station-001/update and looks like this: has the incorrect topic, you should publish to $aws/things/my-weather-station-001/shadow/update - cementblocks
@cementblocks sorry, my bad. That was just a typo in the question (will fix it). The actual code is posting as you said to $aws/things/my-weather-station-001/shadow/update - Dimitry K

1 Answers

1
votes

You can add a where clause to your SQL statement. Try

SELECT state.reported.* FROM $aws/things/+/shadow/update/accepted WHERE state.reported <> ''