Skip to content

Commit 2cde164

Browse files
committed
Add example for configuring https security profile and fix bug where the whole body wasn't returned in http.readBody()
1 parent 3065e74 commit 2cde164

File tree

4 files changed

+37
-10
lines changed

4 files changed

+37
-10
lines changed

scripts/make.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )"
44

5-
TARGET=$SCRIPTPATH/../src/examples/sandbox/sandbox.ino
5+
TARGET=$SCRIPTPATH/../src/examples/http/http.ino
66
EXTRA_ARGS=--clean
77

88
if [ "$1" = "clean" ]; then

src/examples/http/http.ino

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,21 @@ void setup() {
1313

1414
// Start LTE modem and wait until we are connected to the operator
1515
Lte.begin();
16+
Log.infof("Connecting to operator");
1617
while (!Lte.isConnected()) {
17-
Log.info("Not connected to operator yet...\r\n");
18+
Log.raw(".");
1819
delay(1000);
1920
}
2021

21-
Log.info("Connected!\r\n");
22+
Log.raw("\r\n");
23+
Log.infof("Connected to operator: %s\r\n", Lte.getOperator().c_str());
2224

2325
testHttp();
2426
}
2527

2628
void testHttp() {
2729

28-
Log.info("---- Testing HTTP ----\r\n");
30+
Log.info("---- Testing HTTP ----");
2931

3032
HttpResponse response;
3133

@@ -35,20 +37,23 @@ void testHttp() {
3537
Log.info("Failed to configure http client\r\n");
3638
}
3739

38-
Log.info("Configured to HTTP\r\n");
40+
Log.info("Configured to HTTP");
3941

4042
response = HttpClient.post("/post", "{\"hello\": \"world\"}");
4143
Log.infof("POST - status code: %u, data size: %u\r\n",
4244
response.status_code,
4345
response.data_size);
4446

47+
Log.raw("\r\n");
48+
4549
// --- HTTPS ---
50+
Log.info("---- Testing HTTPS ----");
4651

4752
if (!HttpClient.configure(DOMAIN, 443, true)) {
4853
Log.info("Failed to configure https client\r\n");
4954
}
5055

51-
Log.info("Configured to HTTPS\r\n");
56+
Log.info("Configured to HTTPS");
5257

5358
response = HttpClient.head("/get");
5459
Log.infof("HEAD - status code: %d, data size: %d\r\n",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <log.h>
2+
#include <sequans_controller.h>
3+
4+
#define AT_HTTPS_CONFIGURE_SECURITY_PROFILE "AT+SQNSPCFG=3,2,\"\",1,1"
5+
6+
void setup() {
7+
Log.begin(115200);
8+
9+
SequansController.begin();
10+
11+
// Allow time for boot
12+
delay(500);
13+
14+
Log.info("Setting up security profile for HTTPS...");
15+
if (!SequansController.retryCommand(AT_HTTPS_CONFIGURE_SECURITY_PROFILE)) {
16+
Log.info("Failed to set security profile");
17+
return;
18+
}
19+
Log.info("Done!");
20+
}
21+
22+
void loop() {}

src/http_client.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ int16_t HttpClientClass::readBody(char *buffer, const uint32_t buffer_size) {
295295

296296
size_t response_length = strlen(buffer);
297297

298-
// Remove extra <CR><LF> from command response
299-
memset(buffer + response_length - 2, 0, 2);
298+
// Remove extra <CR> from command response
299+
memset(buffer + response_length - 1, 0, 1);
300300

301-
return response_length - 2;
301+
return response_length - 1;
302302
}
303303

304304
String HttpClientClass::readBody(const uint32_t size) {
@@ -309,5 +309,5 @@ String HttpClientClass::readBody(const uint32_t size) {
309309
return "";
310310
}
311311

312-
return buffer;
312+
return String(buffer);
313313
}

0 commit comments

Comments
 (0)