# \[GM02S\] Configure MQTT CleanSession flag on connect?

**URL:** https://forum.sequans.com/t/gm02s-configure-mqtt-cleansession-flag-on-connect/606
**Category:** LTE-M / NB-IoT (Monarch)
**Created:** [September 10, 2026, 12:06am UTC](https://forum.sequans.com/t/gm02s-configure-mqtt-cleansession-flag-on-connect/606 "2026-09-10T00:06:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Ben-AgFlo](https://avatars.discourse-cdn.com/v4/letter/b/8e8cbc/32.png) [@Ben-AgFlo](https://forum.sequans.com/u/Ben-AgFlo)
#### Post date: [September 10, 2026, 12:06am UTC](https://forum.sequans.com/t/gm02s-configure-mqtt-cleansession-flag-on-connect/606/1 "2026-09-10T00:06:50Z")

</div>

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](https://www.hivemq.com/blog/mqtt-essentials-part-7-persistent-session-queuing-messages/)

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.

---

<div class="post-metadata">

### Author: ![Xi\_liu](https://avatars.discourse-cdn.com/v4/letter/x/8e8cbc/32.png) [@Xi\_liu](https://forum.sequans.com/u/Xi_liu)
#### Post date: [September 22, 2026, 2:43am UTC](https://forum.sequans.com/t/gm02s-configure-mqtt-cleansession-flag-on-connect/606/2 "2026-09-22T02:43:42Z")

</div>

Hi

In the atest release [LR8.2.3.1-65130](https://sequanscommunicationsfrance.sharepoint.com/:f:/r/sites/customers/customers%20root/Download/MassMarket/Monarch%202%20GM02SP%20-%20LTE-M%20%26%20NB-IoT%20-%20GNSS/Software/LR8.2.3.1-65130?d=w4cc1ff9c5b7543e9ba9776e35bcb8a2a&csf=1&web=1&e=nDOWwn), 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](https://sequanscommunicationsfrance.sharepoint.com/:b:/r/sites/customers/customers%20root/Download/MassMarket/Monarch%202%20GM02S%20-%20LTE-M%20%26%20NB-IoT/Module/AT%20Commands/Monarch2-ATCommandsReferenceManual-LR82-Rev.4.pdf?d=w3aca707057ab45cc857b2960bf3d0297&csf=1&web=1&e=m8A53I)

BR

Liu Xi
