Skip to content

Commit f9b9317

Browse files
committed
Add timeout error message if the message start character aren't received
1 parent 45e580c commit f9b9317

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/mqtt_client.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,10 +731,19 @@ bool MqttClientClass::readMessage(const char *topic,
731731

732732
// First two bytes are <LF><CR>, so we flush that
733733
uint8_t start_bytes = 2;
734+
735+
start = millis();
736+
734737
while (start_bytes > 0) {
735738
if (SequansController.readByte() != -1) {
736739
start_bytes--;
737740
}
741+
742+
if (start_bytes > 0 && millis() - start > MQTT_TIMEOUT_MS) {
743+
Log.error("Timed out waiting for the modem to deliver the start "
744+
"characters for the MQTT message");
745+
return false;
746+
}
738747
}
739748

740749
// Then we retrieve the payload

0 commit comments

Comments
 (0)