This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NRF9160 HTTPS Issue on sending data

Hi everyone,

I am looking at sending data via HTTPS to Azure.

I have used the https_sample and modified it to send the data to Azure with no issue. But now I am trying to not only send 1 request but several and I got a weird issue.

I use a while loop in which I open a socket, I then set up the tls on this socket, connect to Azure and send the request. In the end of the loop I use the same "clean-up" than in the example (which closes the socket).

Here is my code :

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* Copyright (c) 2020 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
*/
#include <string.h>
#include <zephyr.h>
#include <stdlib.h>
#include <net/socket.h>
#include <net/bsdlib.h>
#include <net/tls_credentials.h>
#include <lte_lc.h>
#include <at_cmd.h>
#include <at_notif.h>
#include <modem_key_mgmt.h>
#define HTTPS_PORT 443
#define HTTP_HEAD "POST /devices/test-1/messages/events?api-version=2018-06-30 HTTP/1.1\r\nHost: test-aptus.azure-devices.net\r\nConnection: close\r\nAuthorization: SharedAccessSignature sr=test-aptus.azure-devices.net%2Fdevices%2Ftest-1&sig=d4QxSCDxhUHMLO2Jp2ygU0cxhModw0oaNzAQI%2BzVH%2F8%3D&se=601590498671\r\nContent-Type: text/plain\r\nContent-Length: 6\r\n\r\ncancer\r\n"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

When I test it I got the sending of the request working a first time, but the second time the NRF9160 just freezes in the connecting step. It bugs me that I do not get any error message and when debugging the firmware just goes and stays in "cpu_idle.S".

Here is my log :

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
*** Booting Zephyr OS build v2.1.99-ncs1 ***
HTTPS client sample started
Provisioning certificate
Waiting for network.. OK
Sending a request to microsoft!
Address info done!
Socket number 2
opened socket!
tls done...
Connecting to azure
Sent 340 bytes
Received 133 bytes
> HTTP/1.1 204 No Content
Finished, closing socket.
done
Sending a request to microsoft!
Address info done!
Socket number 2
opened socket!
tls done...
Connecting to azure
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I would like to know what is wrong in my code and how I can re-use the socket to send several HTPPS request.

Kind regards,

Thomas