25
25
#define SECURITY_PROFILE_PREFIX_LENGTH 11
26
26
#define HTTPS_SECURITY_PROFILE_NUMBER ' 3'
27
27
28
- #define HTTP_SEND " AT+SQNHTTPSND=0,%u,\" %s\" ,%lu,\"\" ,\" %s\" "
28
+ #define HTTP_SEND " AT+SQNHTTPSND=0,%u,\" %s\" ,%lu,\" %s \" ,\" %s\" "
29
29
#define HTTP_RECEIVE " AT+SQNHTTPRCV=0,%lu"
30
30
#define HTTP_QUERY " AT+SQNHTTPQRY=0,%u,\" %s\" ,\" %s\" "
31
31
37
37
#define HTTP_HEAD_METHOD 1
38
38
#define HTTP_DELETE_METHOD 2
39
39
40
+ // Content type specifiers for POST requests for the AT+SQNHTTPSND command
41
+ #define HTTP_CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED " 0"
42
+ #define HTTP_CONTENT_TYPE_TEXT_PLAIN " 1"
43
+ #define HTTP_CONTENT_TYPE_APPLICATION_OCTET_STREAM " 2"
44
+ #define HTTP_CONTENT_TYPE_APPLICATION_MULTIPART_FORM_DATA " 3"
45
+ #define HTTP_CONTENT_TYPE_APPLICATION_APPLICATION_JSON " 4"
46
+
40
47
#define HTTP_RECEIVE_LENGTH 32
41
48
#define HTTP_RECEIVE_START_CHARACTER ' <'
42
49
#define HTTP_SEND_START_CHARACTER ' >'
@@ -74,7 +81,12 @@ static HttpResponse sendData(const char* endpoint,
74
81
const uint32_t data_length,
75
82
const uint8_t method,
76
83
const uint8_t * header = NULL ,
77
- const uint32_t header_length = 0 ) {
84
+ const uint32_t header_length = 0 ,
85
+ const char * content_type = " " ) {
86
+
87
+ // The modem could hang if several HTTP requests are done quickly after each
88
+ // other, this alleviates this
89
+ SequansController.writeCommand (" AT" );
78
90
79
91
HttpResponse http_response = {0 , 0 };
80
92
@@ -94,6 +106,7 @@ static HttpResponse sendData(const char* endpoint,
94
106
method,
95
107
endpoint,
96
108
(unsigned long )data_length,
109
+ content_type,
97
110
header == NULL ? " " : (const char *)header);
98
111
99
112
SequansController.writeBytes ((uint8_t *)command, command_length, true );
@@ -279,23 +292,64 @@ HttpResponse HttpClientClass::post(const char* endpoint,
279
292
const uint8_t * data_buffer,
280
293
const uint32_t data_length,
281
294
const uint8_t * header_buffer,
282
- const uint32_t header_length) {
295
+ const uint32_t header_length,
296
+ const ContentType content_type) {
297
+
298
+ // The content type within the Sequans modem is classified by a single
299
+ // character (+1 for NULL termination)
300
+ char content_type_buffer[2 ] = " " ;
301
+
302
+ switch (content_type) {
303
+ case CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED:
304
+ strncpy (content_type_buffer,
305
+ HTTP_CONTENT_TYPE_APPLICATION_X_WWW_FORM_URLENCODED,
306
+ sizeof (content_type_buffer));
307
+ break ;
308
+
309
+ case CONTENT_TYPE_APPLICATION_OCTET_STREAM:
310
+ strncpy (content_type_buffer,
311
+ HTTP_CONTENT_TYPE_APPLICATION_OCTET_STREAM,
312
+ sizeof (content_type_buffer));
313
+ break ;
314
+
315
+ case CONTENT_TYPE_MULTIPART_FORM_DATA:
316
+ strncpy (content_type_buffer,
317
+ HTTP_CONTENT_TYPE_APPLICATION_MULTIPART_FORM_DATA,
318
+ sizeof (content_type_buffer));
319
+ break ;
320
+
321
+ case CONTENT_TYPE_APPLICATION_JSON:
322
+ strncpy (content_type_buffer,
323
+ HTTP_CONTENT_TYPE_APPLICATION_APPLICATION_JSON,
324
+ sizeof (content_type_buffer));
325
+ break ;
326
+
327
+ default :
328
+ strncpy (content_type_buffer,
329
+ HTTP_CONTENT_TYPE_TEXT_PLAIN,
330
+ sizeof (content_type_buffer));
331
+ break ;
332
+ }
333
+
283
334
return sendData (endpoint,
284
335
data_buffer,
285
336
data_length,
286
337
HTTP_POST_METHOD,
287
338
header_buffer,
288
- header_length);
339
+ header_length,
340
+ content_type_buffer);
289
341
}
290
342
291
343
HttpResponse HttpClientClass::post (const char * endpoint,
292
344
const char * data,
293
- const char * header) {
345
+ const char * header,
346
+ const ContentType content_type) {
294
347
return post (endpoint,
295
348
(uint8_t *)data,
296
349
strlen (data),
297
350
(uint8_t *)header,
298
- strlen (header));
351
+ header == NULL ? 0 : strlen (header),
352
+ content_type);
299
353
}
300
354
301
355
HttpResponse HttpClientClass::put (const char * endpoint,
@@ -318,7 +372,7 @@ HttpResponse HttpClientClass::put(const char* endpoint,
318
372
(uint8_t *)message,
319
373
strlen (message),
320
374
(uint8_t *)header,
321
- strlen (header));
375
+ header == NULL ? 0 : strlen (header));
322
376
}
323
377
324
378
HttpResponse HttpClientClass::get (const char * endpoint, const char * header) {
0 commit comments