@@ -177,8 +177,11 @@ static void internalConnectedCallback(char* urc_data) {
177177 connected_to_broker = false ;
178178 LedCtrl.off (Led::CON, true );
179179
180- // TODO: test
181- LedCtrl.on (Led::USER, true );
180+ SequansController.writeBytes ((uint8_t *)MQTT_DISCONNECT,
181+ strlen (MQTT_DISCONNECT),
182+ true );
183+ delay (10 );
184+ SequansController.clearReceiveBuffer ();
182185
183186 if (disconnected_callback != NULL ) {
184187 disconnected_callback ();
@@ -189,6 +192,12 @@ static void internalConnectedCallback(char* urc_data) {
189192static void internalDisconnectCallback (char * urc_data) {
190193 connected_to_broker = false ;
191194
195+ SequansController.writeBytes ((uint8_t *)MQTT_DISCONNECT,
196+ strlen (MQTT_DISCONNECT),
197+ true );
198+ delay (10 );
199+ SequansController.clearReceiveBuffer ();
200+
192201 if (disconnected_callback != NULL ) {
193202 disconnected_callback ();
194203 }
@@ -389,10 +398,13 @@ bool MqttClientClass::begin(const char* client_id,
389398 return false ;
390399 }
391400
392- // Disconnect if connected
393- if (isConnected ()) {
394- SequansController.writeCommand (MQTT_DISCONNECT);
395- }
401+ // Disconnect to terminate existing configuration
402+ SequansController.writeBytes ((uint8_t *)MQTT_DISCONNECT,
403+ strlen (MQTT_DISCONNECT),
404+ true );
405+
406+ delay (100 );
407+ SequansController.clearReceiveBuffer ();
396408
397409 // -- Configuration --
398410
@@ -511,29 +523,24 @@ bool MqttClientClass::begin(const char* client_id,
511523}
512524
513525bool MqttClientClass::end (void ) {
514- connected_to_broker = false ;
526+
527+ LedCtrl.off (Led::CON, true );
515528
516529 SequansController.unregisterCallback (MQTT_ON_MESSAGE_URC);
517530 SequansController.unregisterCallback (MQTT_ON_CONNECT_URC);
518531 SequansController.unregisterCallback (MQTT_ON_DISCONNECT_URC);
519532
520- connected_callback = NULL ;
521- disconnected_callback = NULL ;
522-
523- LedCtrl.off (Led::CON, true );
533+ SequansController.writeBytes ((uint8_t *)MQTT_DISCONNECT,
534+ strlen (MQTT_DISCONNECT),
535+ true );
536+ delay (10 );
537+ SequansController.clearReceiveBuffer ();
524538
525- if (!isConnected ()) {
526- return true ;
527- }
539+ connected_to_broker = false ;
528540
529- // If LTE is not connected, the MQTT client will be disconnected
530- // automatically
531- if (!Lte.isConnected ()) {
532- return true ;
533- }
541+ internalDisconnectCallback (NULL );
534542
535- return (SequansController.writeCommand (MQTT_DISCONNECT) ==
536- ResponseResult::OK);
543+ return true ;
537544}
538545
539546void MqttClientClass::onConnectionStatusChange (void (*connected)(void ),
0 commit comments