Skip to content

Commit 68871e0

Browse files
committed
MCU8MASS-1828 Use writeCommand instead of writeBytes when closing MQTT session
1 parent 9aaf956 commit 68871e0

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

examples/provision/provision.ino

+12-2
Original file line numberDiff line numberDiff line change
@@ -549,12 +549,22 @@ static bool requestAndSaveToNonVolatileMemory(const char* message,
549549
if (is_certificate) {
550550
// First erase the existing certifiate at the slot (if any)
551551
sprintf(command, AT_ERASE_CERTIFICATE, slot);
552-
SequansController.writeCommand(command);
552+
SequansController.writeBytes(command, strlen(command), true);
553+
554+
// Dummy read of response, we don't care about the response as the modem
555+
// will return an error if there's no certificate to erase and OK if it
556+
// was ereased
557+
SequansController.readResponse();
553558

554559
sprintf(command, AT_WRITE_CERTIFICATE, slot, data_length);
555560
} else {
556561
sprintf(command, AT_ERASE_PRIVATE_KEY, slot);
557-
SequansController.writeCommand(command);
562+
SequansController.writeBytes(command, strlen(command), true);
563+
564+
// Dummy read of response, we don't care about the response as the modem
565+
// will return an error if there's no certificate to erase and OK if it
566+
// was ereased
567+
SequansController.readResponse();
558568

559569
sprintf(command, AT_WRITE_PRIVATE_KEY, slot, data_length);
560570
}

src/mqtt_client.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,10 @@ bool MqttClientClass::begin(const char* client_id,
409409
// instantly. We just want to close the current connection if there are any.
410410
// If there aren't, this will return an error from the modem, but that is
411411
// fine as it just means that there aren't any connections active.
412-
SequansController.readResponse(NULL, 0);
412+
//
413+
// We do this with writeBytes instead of writeCommand to not issue the
414+
// retries of the command if it fails.
415+
SequansController.readResponse();
413416

414417
SequansController.clearReceiveBuffer();
415418

@@ -540,10 +543,7 @@ bool MqttClientClass::end(void) {
540543

541544
if (isConnected()) {
542545

543-
SequansController.writeBytes((uint8_t*)MQTT_DISCONNECT,
544-
strlen(MQTT_DISCONNECT),
545-
true);
546-
546+
SequansController.writeCommand(MQTT_DISCONNECT);
547547
SequansController.clearReceiveBuffer();
548548

549549
connected_to_broker = false;

0 commit comments

Comments
 (0)