Skip to content

Commit 5fa5b52

Browse files
committed
Add timeout for delivering payload for HTTPS and delay some before retrieving system clock in lte module
1 parent c0fb29a commit 5fa5b52

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/http_client.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "log.h"
33
#include "sequans_controller.h"
44

5+
#include <Arduino.h>
56
#include <math.h>
67
#include <stdio.h>
78
#include <stdlib.h>
@@ -46,7 +47,7 @@
4647
#define HTTP_BODY_BUFFER_MIN_SIZE 64
4748
#define HTTP_BODY_BUFFER_MAX_SIZE 1500
4849

49-
#define DEFAULT_RETRIES 5
50+
#define HTTP_TIMEOUT 10000
5051

5152
HttpClientClass HttpClient = HttpClientClass::instance();
5253

@@ -104,19 +105,38 @@ static HttpResponse sendData(const char *endpoint,
104105

105106
// We receive one start bytes of the character '>', so we wait for
106107
// it
107-
while (SequansController.readByte() != HTTP_SEND_START_CHARACTER) {}
108+
109+
uint64_t start = millis();
110+
int16_t start_character = 0;
111+
112+
do {
113+
start_character = SequansController.readByte();
114+
} while (millis() - start < HTTP_TIMEOUT &&
115+
start_character != HTTP_SEND_START_CHARACTER);
116+
117+
if (start_character != HTTP_SEND_START_CHARACTER) {
118+
Log.error("Timed out waiting for modem to be ready for HTTP payload");
119+
return httpResponse;
120+
}
121+
122+
delay(100);
108123

109124
// Now we deliver the payload
110125
SequansController.writeBytes(buffer, buffer_size);
111126

112127
// Wait until we get some valid response and we don't reach the timeout for
113128
// the interface
129+
130+
start = millis();
114131
ResponseResult response_result;
132+
115133
do {
116134
response_result = SequansController.readResponse();
117-
} while (response_result == ResponseResult::TIMEOUT);
135+
} while (millis() - start < HTTP_TIMEOUT &&
136+
response_result != ResponseResult::OK);
118137

119138
if (response_result != ResponseResult::OK) {
139+
Log.error("Modem timed out whilst delivering HTTP payload");
120140
return httpResponse;
121141
}
122142

@@ -218,7 +238,7 @@ bool HttpClientClass::configure(const char *host,
218238
char command[HTTP_CONFIGURE_SIZE] = "";
219239
sprintf(command, HTTP_CONFIGURE, host, port, enable_tls ? 1 : 0);
220240

221-
return SequansController.retryCommand(command, DEFAULT_RETRIES);
241+
return SequansController.retryCommand(command);
222242
}
223243

224244
HttpResponse HttpClientClass::post(const char *endpoint,
@@ -293,12 +313,7 @@ int16_t HttpClientClass::readBody(char *buffer, const uint32_t buffer_size) {
293313
return 0;
294314
}
295315

296-
size_t response_length = strlen(buffer);
297-
298-
// Remove extra <CR> from command response
299-
buffer[response_length - 1] = '\0';
300-
301-
return response_length - 1;
316+
return strlen(buffer);
302317
}
303318

304319
String HttpClientClass::readBody(const uint32_t size) {

src/lte.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ bool LteClass::begin(const bool print_messages) {
171171
Log.rawf(" OK!\r\n");
172172
}
173173

174+
// CCLK might fail if issued to quickly after CPIN
175+
delay(500);
176+
174177
SequansController.clearReceiveBuffer();
175178
SequansController.retryCommand(AT_COMMAND_GET_CLOCK);
176179

0 commit comments

Comments
 (0)