Skip to content

Commit 41ec4fd

Browse files
committed
MCU8MASS-481 Temporary fix for timing out waiting for start character for payload
This commit addresses the bug where the modem does not respond after issuing a publish or receieve message with a temporary fix. It also restructures the mqtt examples to publish before reading the message.
1 parent 60867ff commit 41ec4fd

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

examples/mqtt_polling/mqtt_polling.ino

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,6 @@ void setup() {
6565
}
6666

6767
void loop() {
68-
69-
String message = MqttClient.readMessage(MQTT_SUB_TOPIC);
70-
71-
// Read message will return an empty string if there were no new
72-
// messages, so anything other than that means that there was a new
73-
// message
74-
if (message != "") {
75-
Log.infof("Got new message: %s\r\n", message.c_str());
76-
}
77-
7868
String message_to_publish = String("Hello world: " + String(counter));
7969

8070
bool publishedSuccessfully =
@@ -87,5 +77,16 @@ void loop() {
8777
Log.error("Failed to publish");
8878
}
8979

90-
delay(5000);
80+
delay(2000);
81+
82+
String message = MqttClient.readMessage(MQTT_SUB_TOPIC);
83+
84+
// Read message will return an empty string if there were no new
85+
// messages, so anything other than that means that there was a new
86+
// message
87+
if (message != "") {
88+
Log.infof("Got new message: %s\r\n", message.c_str());
89+
}
90+
91+
delay(2000);
9192
}

examples/mqtt_polling_aws/mqtt_polling_aws.ino

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ bool initMQTTTopics() {
4444

4545
void setup() {
4646
Log.begin(115200);
47-
4847
LedCtrl.begin();
4948
LedCtrl.startupCycle();
5049

@@ -86,15 +85,6 @@ void setup() {
8685

8786
void loop() {
8887

89-
String message = MqttClient.readMessage(mqtt_sub_topic);
90-
91-
// Read message will return an empty string if there were no new
92-
// messages, so anything other than that means that there were a
93-
// new message
94-
if (message != "") {
95-
Log.infof("Got new message: %s\r\n", message.c_str());
96-
}
97-
9888
bool published_successfully =
9989
MqttClient.publish(mqtt_pub_topic, "{\"light\": 9, \"temp\": 9}");
10090

@@ -104,5 +94,16 @@ void loop() {
10494
Log.error("Failed to publish\r\n");
10595
}
10696

107-
delay(1000);
97+
delay(2000);
98+
99+
String message = MqttClient.readMessage(mqtt_sub_topic);
100+
101+
// Read message will return an empty string if there were no new
102+
// messages, so anything other than that means that there were a
103+
// new message
104+
if (message != "") {
105+
Log.infof("Got new message: %s\r\n", message.c_str());
106+
}
107+
108+
delay(2000);
108109
}

src/http_client.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ static HttpResponse sendData(const char *endpoint,
101101

102102
SequansController.clearReceiveBuffer();
103103

104+
// Fix for bringing the modem out of idling and prevent timeout whilst
105+
// waiting for modem response during the next AT command
106+
SequansController.retryCommand("AT");
107+
104108
// Setup and transmit SEND command before sending the data
105109
const uint32_t digits_in_data_length = trunc(log10(buffer_size)) + 1;
106110

@@ -110,7 +114,6 @@ static HttpResponse sendData(const char *endpoint,
110114

111115
// We receive one start bytes of the character '>', so we wait for
112116
// it
113-
114117
uint64_t start = millis();
115118
int16_t start_character = 0;
116119

@@ -191,6 +194,10 @@ static HttpResponse queryData(const char *endpoint, const uint8_t method) {
191194

192195
SequansController.clearReceiveBuffer();
193196

197+
// Fix for bringing the modem out of idling and prevent timeout whilst
198+
// waiting for modem response during the next AT command
199+
SequansController.retryCommand("AT");
200+
194201
// Set up and send the query
195202
char command[strlen(HTTP_QUERY) + strlen(endpoint)];
196203
sprintf(command, HTTP_QUERY, method, endpoint);
@@ -332,6 +339,10 @@ int16_t HttpClientClass::readBody(char *buffer, const uint32_t buffer_size) {
332339

333340
SequansController.clearReceiveBuffer();
334341

342+
// Fix for bringing the modem out of idling and prevent timeout whilst
343+
// waiting for modem response during the next AT command
344+
SequansController.retryCommand("AT");
345+
335346
// We send the buffer size with the receive command so that we only
336347
// receive that. The rest will be flushed from the modem.
337348
char command[HTTP_RECEIVE_LENGTH] = "";

src/mqtt_client.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,11 @@ bool MqttClientClass::publish(const char *topic,
583583
Log.debugf("Starting publishing on topic %s\r\n", topic);
584584

585585
SequansController.clearReceiveBuffer();
586+
587+
// Fix for bringing the modem out of idling and prevent timeout whilst
588+
// waiting for modem response during the next AT command
589+
SequansController.retryCommand("AT");
590+
586591
const size_t digits_in_buffer_size = trunc(log10(buffer_size)) + 1;
587592
char command[MQTT_PUBLISH_LENGTH_PRE_DATA + digits_in_buffer_size];
588593

@@ -697,6 +702,10 @@ bool MqttClientClass::readMessage(const char *topic,
697702

698703
SequansController.clearReceiveBuffer();
699704

705+
// Fix for bringing the modem out of idling and prevent timeout whilst
706+
// waiting for modem response during the next AT command
707+
SequansController.retryCommand("AT");
708+
700709
// We determine all message IDs lower than 0 as just no message ID passed
701710
if (message_id < 0) {
702711
char command[MQTT_RECEIVE_LENGTH] = "";
@@ -738,14 +747,10 @@ bool MqttClientClass::readMessage(const char *topic,
738747
}
739748
}
740749

741-
// Then we retrieve the payload
742-
ResponseResult result =
750+
// Then we retrieve the payload (if any)
751+
const ResponseResult result =
743752
SequansController.readResponse((char *)buffer, buffer_size);
744753

745-
if (result != ResponseResult::OK) {
746-
Log.warn("Failed whilst retrieving the MQTT message payload");
747-
}
748-
749754
return (result == ResponseResult::OK);
750755
}
751756

0 commit comments

Comments
 (0)