How to queue MQTT messages with AWS IoT Core?

171 Views Asked by At

I'm currently running a couple of Arduino MKR1500 NB-IoT boards that report measurement values to AWS IoT core to their shadow file.

I use a MQTT PubSub library and publish to the topic: $aws/things/thingName/shadow/update

To view all data of my devices I created a Fleet Hub dashboard.

The devices wake up once a day and need to toggle some booleans that are set in the cloud.

In my opinion this can be done by changing the desired values in the shadow file. This generates a publish on the topic $aws/things/thingName/shadow/update/delta

But when my device is in sleep and disconnected, it doesn't get the payload after waking up, mqtt connected and subscribed.

So basically while in sleep I'm missing the payload?

Since Fleet Hub only has Alerts and Jobs, I assumed I should trigger the boolean values via jobs.

But here I have the same effect. I only receive the topic $aws/things/MyThing/jobs/notify if my device is already online and subscribed. I will miss the notification if the job is started before my device is awake.

So the conclusion is mqtt messages are fired and not put on a waitlist to be delivered when the device gets online?

What is the whole point of using the shadow file if this is the case?

1

There are 1 best solutions below

0
On

As per the comments; if you want to receive messages sent whilst offline you need to:

  • Subscribe with QOS > 0
  • Connect with Clean Session set to 0 (false)

(this is for MQTT v3; things changed a bit with V5)

The MQTT V3 spec does not really provide a mechanism for deleting session state after a period of time but does include a "Non normative comment":

The storage capabilities of Client and Server implementations will of course have limits in terms of capacity and may be subject to administrative policies such as the maximum time that Session state is stored between Network Connections.

AWS IoT Core has a "Persistent session expiry period" which defaults to 3600 Seconds (1 hour) but you can change this such that messages are retained up to 7 days.