[GM02S] Configure MQTT CleanSession flag on connect?

Hi,

We are faced with an issue when connecting to Azure’s IoTHub MQTT broker using Monarch’s embedded MQTT client. This is related to Cloud to Device messages emitted while the remote device is offline.

Right on successful connection to remote broker, any pending Azure Cloud to Device (C2D) messages pending to be sent are seemingly dropped. And there is no way to retrieve them.

This is most likely related to the CleanSession flag usually set when connecting to broker. As per explained over there: Understanding Persistent Sessions and Clean Sessions – MQTT Essentials: Part 7 | HiveMQ

What I assume is the current implementation in Monarch platform sets CleanSession flag to 0, implicitly forcing a persistent connection from the broker’s point of view. As such, the broker would assume the client is still subscribed to the necessary MQTT topics to get notified of incoming messages as the broker sends them to the now connected client.

Just to be clear, C2D messages framework is working. It’s been tested successfully with a GM02S but only when the GM02S is actively connected to broker, already subscribed to C2D reception topic and then the message is emitted.

What I need now is to have messages queued in while GM02S is offline and sent over from the broker when the GM02S connects and subscribe to necessary topics.

So the following steps produce the intended result, a notification of incoming message is received:

  1. AT+SQNSMQTTCFG=0,“”,“/<dev_id>/?api-version=2021-04-12”,1
  2. AT+SQNSMQTTCONNECT=0,“”,8883
  3. [wait for connection success]
  4. AT+SQNSMQTTSUBSCRIBE=0,“devices//messages/devicebound/#”,1
  5. [emit C2D message here]
  6. +SQNSMQTTONMESSAGE:0,“devices/<dev_id>/messages/devicebound/%24.to=%2Fdevices%2F<dev_id>%2Fmessages%2FdeviceBound&%24.ct=text%2Fplain%3B%20charset%3DUTF-8&%24.ce=utf-8”,7,1,1

But the following sequence isn’t working

  1. [emit C2D message here]
  2. AT+SQNSMQTTCFG=0,“”,“/<dev_id>/?api-version=2021-04-12”,1
  3. AT+SQNSMQTTCONNECT=0,“”,8883
  4. [wait for connection success]
  5. AT+SQNSMQTTSUBSCRIBE=0,“devices//messages/devicebound/#”,1
  6. Nothing is received

At step 4, I can see in the IotHub’s device twin that pending C2D messages are flushed. Pending count goes from the number of held back message down to 0.

Current firmware on our device:
ATI1
UE8.2.0.2
LR8.2.0.2-59200à

So, is there a way to explicitely define the CleanSession flag to 1 (ON) when connecting to a MQTT broker?

Thanks.

Hi

In the atest release LR8.2.3.1-65130, it is able to set CleanSession flag by set clear in command: AT+SQNSMQTTCFG=<id>,<client_id>[,<username>] [,<password>][,<sp_id>][,<retain>[,<clear>]]

Detailed description can be found in section 8.4.2 in Monarch2-ATCommandsReferenceManual-LR82-Rev.4.pdf

BR

Liu Xi