This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Thingy91 https_client - getaddrinfo failed err 116 50% of the time

Hi All,

I got my hands on a Thingy91 and trying to do devlopment with it starting with a  basic https client sample app. I have registered my Sim and everything works ~50% of the time.

When it works, I found that the network connects and does the ip address query quickly. Though when it doesn't, its like it just timesout. I tried putting a retry counter on the getaddress function, though if 1 fails with a timeout, they will all do the same. Roughly 40s per fail, so 5 retries is around ~3.2min period.

Non-Working example:

*** Booting Zephyr OS build v2.6.99-ncs1  ***
Flash regions		Domain		Permissions
00 02 0x00000 0x18000 	Secure		rwxl
03 31 0x18000 0x100000 	Non-Secure	rwxl

Non-secure callable region 0 placed in flash region 2 with size 32.

SRAM region		Domain		Permissions
00 07 0x00000 0x10000 	Secure		rwxl
08 31 0x10000 0x40000 	Non-Secure	rwxl

Peripheral		Domain		Status
00 NRF_P0               Non-Secure	OK
01 NRF_CLOCK            Non-Secure	OK
02 NRF_RTC0             Non-Secure	OK
03 NRF_RTC1             Non-Secure	OK
04 NRF_NVMC             Non-Secure	OK
05 NRF_UARTE1           Non-Secure	OK
06 NRF_UARTE2           Secure		SKIP
07 NRF_TWIM2            Non-Secure	OK
08 NRF_SPIM3            Non-Secure	OK
09 NRF_TIMER0           Non-Secure	OK
10 NRF_TIMER1           Non-Secure	OK
11 NRF_TIMER2           Non-Secure	OK
12 NRF_SAADC            Non-Secure	OK
13 NRF_PWM0             Non-Secure	OK
14 NRF_PWM1             Non-Secure	OK
15 NRF_PWM2             Non-Secure	OK
16 NRF_PWM3             Non-Secure	OK
17 NRF_WDT              Non-Secure	OK
18 NRF_IPC              Non-Secure	OK
19 NRF_VMC              Non-Secure	OK
20 NRF_FPU              Non-Secure	OK
21 NRF_EGU1             Non-Secure	OK
22 NRF_EGU2             Non-Secure	OK
23 NRF_DPPIC            Non-Secure	OK
24 NRF_REGULATORS       Non-Secure	OK
25 NRF_PDM              Non-Secure	OK
26 NRF_I2S              Non-Secure	OK
27 NRF_GPIOTE1          Non-Secure	OK

SPM: NS image at 0x18200
SPM: NS MSP at 0x200192f8
SPM: NS reset vector at 0x1ad05
SPM: prepare to jump to Non-Secure image.
*** Booting Zephyr OS build v2.6.99-ncs1  ***
HTTPS client sample started
Waiting for network.. OK
Waiting for ip addr.. getaddrinfo() failed, err 116
Waiting for ip addr.. getaddrinfo() failed, err 116
Waiting for ip addr.. getaddrinfo() failed, err 116
Waiting for ip addr.. getaddrinfo() failed, err 116
Waiting for ip addr.. getaddrinfo() failed, err 116
coulnd't get ip over 5 retries

Working Example:

*** Booting Zephyr OS build v2.6.99-ncs1  ***
Flash regions		Domain		Permissions
00 02 0x00000 0x18000 	Secure		rwxl
03 31 0x18000 0x100000 	Non-Secure	rwxl

Non-secure callable region 0 placed in flash region 2 with size 32.

SRAM region		Domain		Permissions
00 07 0x00000 0x10000 	Secure		rwxl
08 31 0x10000 0x40000 	Non-Secure	rwxl

Peripheral		Domain		Status
00 NRF_P0               Non-Secure	OK
01 NRF_CLOCK            Non-Secure	OK
02 NRF_RTC0             Non-Secure	OK
03 NRF_RTC1             Non-Secure	OK
04 NRF_NVMC             Non-Secure	OK
05 NRF_UARTE1           Non-Secure	OK
06 NRF_UARTE2           Secure		SKIP
07 NRF_TWIM2            Non-Secure	OK
08 NRF_SPIM3            Non-Secure	OK
09 NRF_TIMER0           Non-Secure	OK
10 NRF_TIMER1           Non-Secure	OK
11 NRF_TIMER2           Non-Secure	OK
12 NRF_SAADC            Non-Secure	OK
13 NRF_PWM0             Non-Secure	OK
14 NRF_PWM1             Non-Secure	OK
15 NRF_PWM2             Non-Secure	OK
16 NRF_PWM3             Non-Secure	OK
17 NRF_WDT              Non-Secure	OK
18 NRF_IPC              Non-Secure	OK
19 NRF_VMC              Non-Secure	OK
20 NRF_FPU              Non-Secure	OK
21 NRF_EGU1             Non-Secure	OK
22 NRF_EGU2             Non-Secure	OK
23 NRF_DPPIC            Non-Secure	OK
24 NRF_REGULATORS       Non-Secure	OK
25 NRF_PDM              Non-Secure	OK
26 NRF_I2S              Non-Secure	OK
27 NRF_GPIOTE1          Non-Secure	OK

SPM: NS image at 0x18200
SPM: NS MSP at 0x2001a2f8
SPM: NS reset vector at 0x1ae29
SPM: prepare to jump to Non-Secure image.
*** Booting Zephyr OS build v2.6.99-ncs1  ***
HTTPS client sample started
Provisioning certificate
Waiting for network.. OK
Waiting for ip addr.. OK
Connecting to example.com
Sent 61 bytes
Received 370 bytes

>	 HTTP/1.1 200 OK

Finished, closing socket.

I am not sure about the best way to approach this. The only visibility I have of my sim is from nrfcloud, so I cannot see what happens on the backend for failed connections to the network etc.

I also tried using my own DNS from this example. Though results in same as above, sometimes works, sometimes doesn't.

I played around with the at_cmd.c file and overrode the logging. So I got these 2 sets of logs instead, with more verbose information.

Working:

*** Booting Zephyr OS build v2.6.99-ncs1  ***
Flash regions		Domain		Permissions
00 02 0x00000 0x18000 	Secure		rwxl
03 31 0x18000 0x100000 	Non-Secure	rwxl

Non-secure callable region 0 placed in flash region 2 with size 32.

SRAM region		Domain		Permissions
00 07 0x00000 0x10000 	Secure		rwxl
08 31 0x10000 0x40000 	Non-Secure	rwxl

Peripheral		Domain		Status
00 NRF_P0               Non-Secure	OK
01 NRF_CLOCK            Non-Secure	OK
02 NRF_RTC0             Non-Secure	OK
03 NRF_RTC1             Non-Secure	OK
04 NRF_NVMC             Non-Secure	OK
05 NRF_UARTE1           Non-Secure	OK
06 NRF_UARTE2           Secure		SKIP
07 NRF_TWIM2            Non-Secure	OK
08 NRF_SPIM3            Non-Secure	OK
09 NRF_TIMER0           Non-Secure	OK
10 NRF_TIMER1           Non-Secure	OK
11 NRF_TIMER2           Non-Secure	OK
12 NRF_SAADC            Non-Secure	OK
13 NRF_PWM0             Non-Secure	OK
14 NRF_PWM1             Non-Secure	OK
15 NRF_PWM2             Non-Secure	OK
16 NRF_PWM3             Non-Secure	OK
17 NRF_WDT              Non-Secure	OK
18 NRF_IPC              Non-Secure	OK
19 NRF_VMC              Non-Secure	OK
20 NRF_FPU              Non-Secure	OK
21 NRF_EGU1             Non-Secure	OK
22 NRF_EGU2             Non-Secure	OK
23 NRF_DPPIC            Non-Secure	OK
24 NRF_REGULATORS       Non-Secure	OK
25 NRF_PDM              Non-Secure	OK
26 NRF_I2S              Non-Secure	OK
27 NRF_GPIOTE1          Non-Secure	OK

SPM: NS image at 0x18200
SPM: NS MSP at 0x2001a300
SPM: NS reset vector at 0x1ae41
SPM: prepare to jump to Non-Secure image.
*** Booting Zephyr OS build v2.6.99-ncs1  ***
HTTPS client sample started
Common AT socket created
Common AT socket processing thread created
Setting notification handler to 0x1d675
Sending command AT+CMEE?
AT socket thread started
Writing any pending command
Awaiting response for AT+CMEE?
Listening on socket
at_cmd_rx 15 bytes, +CMEE: 0
OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=1
Writing any pending command
Sending command AT+CMEE=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT%CMNG=1,42,0
Writing any pending command
Sending command AT%CMNG=1,42,0
Listening on socket
at_cmd_rx 85 bytes, %CMNG: 42,0,"0000000000000000000000000000000000000000000000000000000000000000"
OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=0
Writing any pending command
Sending command AT+CMEE=0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CMEE?
Writing any pending command
Sending command AT+CMEE?
Listening on socket
at_cmd_rx 15 bytes, +CMEE: 0
OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=1
Writing any pending command
Sending command AT+CMEE=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT%CMNG=3,42,0
Writing any pending command
Sending command AT%CMNG=3,42,0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=0
Writing any pending command
Sending command AT+CMEE=0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Provisioning certificate
Awaiting response for AT+CMEE?
Writing any pending command
Sending command AT+CMEE?
Listening on socket
at_cmd_rx 15 bytes, +CMEE: 0
OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=1
Writing any pending command
Sending command AT+CMEE=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT%CMNG=0,42,0,"-----BEGIN CERTIFICATE-----
MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
-----END CERTIFICATE-----
"
Writing any pending command
Sending command AT%CMNG=0,42,0,"-----BEGIN CERTIFICATE-----
MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
-----END CERTIFICATE-----
"
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=0
Writing any pending command
Sending command AT+CMEE=0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Writing any DNS set result 0
Waiting for network.. Sending command AT%XSYSTEMMODE?
pending command
Awaiting response for AT%XSYSTEMMODE?
Listening on socket
at_cmd_rx 28 bytes, %XSYSTEMMODE: 1,0,1,0
OK

Enqueueing response for sync call
Awaiting response for AT%XSYSTEMMODE=1,0,0,0
Writing any pending command
Sending command AT%XSYSTEMMODE=1,0,0,0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT%XMAGPIO=1,1,1,7,1,746,803,2,698,748,2,1710,2200,3,824,894,4,880,960,5,791,849,7,1565,1586
Writing any pending command
Sending command AT%XMAGPIO=1,1,1,7,1,746,803,2,698,748,2,1710,2200,3,824,894,4,880,960,5,791,849,7,1565,1586
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CEREG=5
Writing any pending command
Sending command AT+CEREG=5
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CSCON=1
Writing any pending command
Sending command AT+CSCON=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT%XSYSTEMMODE=1,0,0,0
Writing any pending command
Sending command AT%XSYSTEMMODE=1,0,0,0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CEREG=5
Writing any pending command
Sending command AT+CEREG=5
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CSCON=1
Writing any pending command
Sending command AT+CSCON=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CFUN=1
Writing any pending command
Sending command AT+CFUN=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Writing any pending command
Listening on socket
at_cmd_rx 58 bytes, +CEREG: 2,"3060","0833070C",7,0,0,"11100000","11100000"

Writing any pending command
Listening on socket
at_cmd_rx 12 bytes, +CSCON: 1

Writing any pending command
Listening on socket
at_cmd_rx 56 bytes, +CEREG: 5,"3060","0833070C",7,,,"00001000","11100000"

OK
Waiting for ip addr.. Writing any pending command
Listening on socket
OK
Connecting to example.com
Sent 61 bytes
Received 369 bytes

>	 HTTP/1.1 200 OK

Finished, closing socket.
at_cmd_rx 12 bytes, +CSCON: 0

Writing any pending command
Listening on socket

And finally, not working:

*** Booting Zephyr OS build v2.6.99-ncs1  ***
Flash regions		Domain		Permissions
00 02 0x00000 0x18000 	Secure		rwxl
03 31 0x18000 0x100000 	Non-Secure	rwxl

Non-secure callable region 0 placed in flash region 2 with size 32.

SRAM region		Domain		Permissions
00 07 0x00000 0x10000 	Secure		rwxl
08 31 0x10000 0x40000 	Non-Secure	rwxl

Peripheral		Domain		Status
00 NRF_P0               Non-Secure	OK
01 NRF_CLOCK            Non-Secure	OK
02 NRF_RTC0             Non-Secure	OK
03 NRF_RTC1             Non-Secure	OK
04 NRF_NVMC             Non-Secure	OK
05 NRF_UARTE1           Non-Secure	OK
06 NRF_UARTE2           Secure		SKIP
07 NRF_TWIM2            Non-Secure	OK
08 NRF_SPIM3            Non-Secure	OK
09 NRF_TIMER0           Non-Secure	OK
10 NRF_TIMER1           Non-Secure	OK
11 NRF_TIMER2           Non-Secure	OK
12 NRF_SAADC            Non-Secure	OK
13 NRF_PWM0             Non-Secure	OK
14 NRF_PWM1             Non-Secure	OK
15 NRF_PWM2             Non-Secure	OK
16 NRF_PWM3             Non-Secure	OK
17 NRF_WDT              Non-Secure	OK
18 NRF_IPC              Non-Secure	OK
19 NRF_VMC              Non-Secure	OK
20 NRF_FPU              Non-Secure	OK
21 NRF_EGU1             Non-Secure	OK
22 NRF_EGU2             Non-Secure	OK
23 NRF_DPPIC            Non-Secure	OK
24 NRF_REGULATORS       Non-Secure	OK
25 NRF_PDM              Non-Secure	OK
26 NRF_I2S              Non-Secure	OK
27 NRF_GPIOTE1          Non-Secure	OK

SPM: NS image at 0x18200
SPM: NS MSP at 0x2001a300
SPM: NS reset vector at 0x1ae41
SPM: prepare to jump to Non-Secure image.
*** Booting Zephyr OS build v2.6.99-ncs1  ***
HTTPS client sample started
Common AT socket created
Common AT socket processing thread created
Setting notification handler to 0x1d675
Sending command AT+CMEE?
AT socket thread started
Writing any pending command
Awaiting response for AT+CMEE?
Listening on socket
at_cmd_rx 15 bytes, +CMEE: 0
OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=1
Writing any pending command
Sending command AT+CMEE=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT%CMNG=1,42,0
Writing any pending command
Sending command AT%CMNG=1,42,0
Listening on socket
at_cmd_rx 85 bytes, %CMNG: 42,0,"0000000000000000000000000000000000000000000000000000000000000000"
OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=0
Writing any pending command
Sending command AT+CMEE=0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CMEE?
Writing any pending command
Sending command AT+CMEE?
Listening on socket
at_cmd_rx 15 bytes, +CMEE: 0
OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=1
Writing any pending command
Sending command AT+CMEE=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT%CMNG=3,42,0
Writing any pending command
Sending command AT%CMNG=3,42,0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=0
Writing any pending command
Sending command AT+CMEE=0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Provisioning certificate
Awaiting response for AT+CMEE?
Writing any pending command
Sending command AT+CMEE?
Listening on socket
at_cmd_rx 15 bytes, +CMEE: 0
OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=1
Writing any pending command
Sending command AT+CMEE=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT%CMNG=0,42,0,"-----BEGIN CERTIFICATE-----
MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
-----END CERTIFICATE-----
"
Writing any pending command
Sending command AT%CMNG=0,42,0,"-----BEGIN CERTIFICATE-----
MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh
MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3
d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD
QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT
MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j
b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB
CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97
nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt
43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P
T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4
gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO
BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR
TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw
DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr
hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg
06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF
PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls
YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk
CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
-----END CERTIFICATE-----
"
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CMEE=0
Writing any pending command
Sending command AT+CMEE=0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Writing any DNS set result 0
Waiting for network.. Sending command AT%XSYSTEMMODE?
pending command
Awaiting response for AT%XSYSTEMMODE?
Listening on socket
at_cmd_rx 28 bytes, %XSYSTEMMODE: 1,0,1,0
OK

Enqueueing response for sync call
Awaiting response for AT%XSYSTEMMODE=1,0,0,0
Writing any pending command
Sending command AT%XSYSTEMMODE=1,0,0,0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT%XMAGPIO=1,1,1,7,1,746,803,2,698,748,2,1710,2200,3,824,894,4,880,960,5,791,849,7,1565,1586
Writing any pending command
Sending command AT%XMAGPIO=1,1,1,7,1,746,803,2,698,748,2,1710,2200,3,824,894,4,880,960,5,791,849,7,1565,1586
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CEREG=5
Writing any pending command
Sending command AT+CEREG=5
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CSCON=1
Writing any pending command
Sending command AT+CSCON=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT%XSYSTEMMODE=1,0,0,0
Writing any pending command
Sending command AT%XSYSTEMMODE=1,0,0,0
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CEREG=5
Writing any pending command
Sending command AT+CEREG=5
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CSCON=1
Writing any pending command
Sending command AT+CSCON=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Awaiting response for AT+CFUN=1
Writing any pending command
Sending command AT+CFUN=1
Listening on socket
at_cmd_rx 5 bytes, OK

Enqueueing response for sync call
Writing any pending command
Listening on socket
at_cmd_rx 58 bytes, +CEREG: 2,"3060","0833070C",7,0,0,"11100000","11100000"

Writing any pending command
Listening on socket
at_cmd_rx 12 bytes, +CSCON: 1

Writing any pending command
Listening on socket
at_cmd_rx 12 bytes, +CSCON: 0

Writing any pending command
Listening on socket
at_cmd_rx 12 bytes, +CSCON: 1

Writing any pending command
Listening on socket
at_cmd_rx 56 bytes, +CEREG: 5,"3060","0833070C",7,,,"00001000","11100000"

OK
Waiting for ip addr.. Writing any pending command
Listening on socket
getaddrinfo() failed, err 116
Waiting for ip addr.. getaddrinfo() failed, err 116
Waiting for ip addr.. getaddrinfo() failed, err 116
Waiting for ip addr.. getaddrinfo() failed, err 116
Waiting for ip addr.. at_cmd_rx 58 bytes, +CEREG: 2,"3060","0833070C",7,0,0,"11100000","11100000"

Writing any pending command
Listening on socket
at_cmd_rx 12 bytes, +CSCON: 0

Writing any pending command
Listening on socket
getaddrinfo() failed, err 114
coulnd't get ip over 5 retries
at_cmd_rx 12 bytes, +CSCON: 1

Writing any pending command
Listening on socket
at_cmd_rx 56 bytes, +CEREG: 5,"3060","0833070C",7,,,"00001000","11100000"

Writing any pending command
Listening on socket

Parents
  • Hi,

     

    If we look at this part of the log:

    at_cmd_rx 56 bytes, +CEREG: 5,"3060","0833070C",7,,,"00001000","11100000"
    
    OK
    Waiting for ip addr.. Writing any pending command
    Listening on socket
    getaddrinfo() failed, err 116
    Waiting for ip addr.. getaddrinfo() failed, err 116
    Waiting for ip addr.. getaddrinfo() failed, err 116
    Waiting for ip addr.. getaddrinfo() failed, err 116
    Waiting for ip addr.. at_cmd_rx 58 bytes, +CEREG: 2,"3060","0833070C",7,0,0,"11100000","11100000"

    CEREG state of 5 = roaming (ie: connected)

    Later it goes to state of 2 = searching, meaning that you are disconnected from the network. Have you checked your signal strength using CESQ? https://infocenter.nordicsemi.com/topic/ref_at_commands/REF/at_commands/mob_termination_ctrl_status/proc_cesq_set.html?cp=2_1_4_3_0

    I think you might have a marginal connection to the network in your area.

     

    Kind regards,

    Håkon

  • After some more testing throughout today. I drove over to a tower where I had very good signal strength. This time it could connect to the tower and show a strong signal, though would still suffer from getting a dns or sending data out on 50% of the restarts. I did some testing with both the default assest tracker and the https basic application. Both tests were done within line of sight of the tower ~500m away over open farm land. Note the signal strength from the https example. With the https example, after leaving the device for an extended period of time (~30 mins) it began communicating. Though within the first 5 minutes would not.

    https log extract (getaddrinfo failed: 116):

    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 48,2,11,1
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 53,2,11,1
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 21 bytes, %CESQ: 255,0,255,0
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 21 bytes, %CESQ: 255,0,255,0
    
    Writing any pending command
    Listening on socket
    Button query pressed
    
    
    ----------------------------
    ---> Started <-----
    -----> Waiting for ip addr.. 
    at_cmd_rx 19 bytes, %CESQ: 56,2,15,2
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 56,2,15,2
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 50,2,10,1
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 12 bytes, +CSCON: 1
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 51,2,15,2
    
    Writing any pending command
    Listening on socket
    getaddrinfo() failed, err 116
    Sending command AT+CEREG=5
    Awaiting response for AT+CEREG=5
    at_cmd_rx 5 bytes, OK
    
    Enqueueing response for sync call
    Awaiting response for AT+CEREG?
    Writing any pending command
    Sending command AT+CEREG?
    Listening on socket
    at_cmd_rx 62 bytes, +CEREG: 5,5,"3060","082F630B",7,,,"00001000","11100000"
    OK
    
    Enqueueing response for sync call
    ----->reg status 5
    ---> CONN ATTEMPT FAIL <-----
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 51,2,10,1
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 12 bytes, +CSCON: 0
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 21 bytes, %CESQ: 255,0,255,0
    
    Writing any pending command
    Listening on socket
    Button query pressed
    
    
    ----------------------------
    ---> Started <-----
    -----> Waiting for ip addr.. 
    at_cmd_rx 12 bytes, +CSCON: 1
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 51,2,15,2
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 51,2,10,1
    
    Writing any pending command
    Listening on socket
    getaddrinfo() failed, err 116
    Sending command AT+CEREG=5
    Awaiting response for AT+CEREG=5
    at_cmd_rx 5 bytes, OK
    
    Enqueueing response for sync call
    Awaiting response for AT+CEREG?
    Writing any pending command
    Sending command AT+CEREG?
    Listening on socket
    at_cmd_rx 62 bytes, +CEREG: 5,5,"3060","082F630B",7,,,"00001000","11100000"
    OK
    
    Enqueueing response for sync call
    ----->reg status 5
    ---> CONN ATTEMPT FAIL <-----
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 55,2,19,2
    
    Writing any pending command
    Listening on socket
    Button query pressed
    
    
    ----------------------------
    ---> Started <-----
    -----> Waiting for ip addr.. 
    at_cmd_rx 12 bytes, +CSCON: 0
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 21 bytes, %CESQ: 255,0,255,0
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 12 bytes, +CSCON: 1
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 51,2,11,1
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 51,2,16,2
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 55,2,16,2
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 56,2,14,2
    
    Writing any pending command
    Listening on socket
    at_cmd_rx 19 bytes, %CESQ: 56,2,16,2
    
    Writing any pending command
    Listening on socket
    getaddrinfo() failed, err 116
    Sending command AT+CEREG=5
    Awaiting response for AT+CEREG=5
    at_cmd_rx 5 bytes, OK
    
    Enqueueing response for sync call
    Awaiting response for AT+CEREG?
    Writing any pending command
    Sending command AT+CEREG?
    Listening on socket
    at_cmd_rx 62 bytes, +CEREG: 5,5,"3060","082F630B",7,,,"00001000","11100000"
    OK
    


    Asset tracker log extract (getaddrinfo failed: -11):

    [00:00:31.960,662] {1B}[1;33m<wrn> date_time: getaddrinfo, error: -11{1B}[0m
    [00:00:57.561,737] {1B}[0m<dbg> nrf_cloud_transport.nct_connect: getaddrinfo failed -11{1B}[0m
    [00:00:57.569,396] {1B}[0m<dbg> nrf_cloud.api_event_handler: NRF_CLOUD_EVT_TRANSPORT_CONNECTING{1B}[0m
    [00:00:57.577,819] {1B}[0m<inf> asset_tracker: CLOUD_EVT_CONNECTING{1B}[0m
    [00:00:57.583,862] {1B}[1;31m<err> asset_tracker: Failed to connect to cloud, error -3{1B}[0m
    [00:00:57.591,491] {1B}[1;31m<err> asset_tracker: Network error, check cloud configuration{1B}[0m
    [00:00:57.599,487] {1B}[1;31m<err> asset_tracker: Device will reboot in 300 seconds{1B}[0m
    [00:00:57.606,903] {1B}[1;31m<err> asset_tracker: LTE link disconnect{1B}[0m
    +CEREG: 0,"3060","082F630B",7,0,0,"11100000","11100000"
    [00:01:00.761,871] {1B}[1;33m<wrn> date_time: getaddrinfo, error: -11{1B}[0m
    [00:01:00.774,475] {1B}[1;33m<wrn> date_time: getaddrinfo, error: -11{1B}[0m
    [00:01:00.787,109] {1B}[1;33m<wrn> date_time: getaddrinfo, error: -11{1B}[0m
    [00:01:00.799,713] {1B}[1;33m<wrn> date_time: getaddrinfo, error: -11{1B}[0m
    [00:01:00.805,816] {1B}[1;33m<wrn> date_time: Not getting time from any NTP server{1B}[0m
    +CSCON: 0
    [00:01:02.622,497] {1B}[0m<inf> asset_tracker: RRC mode: Idle{1B}[0m
    [00:01:04.070,953] {1B}[1;31m<err> asset_tracker: Shutdown modem{1B}[0m
    [00:01:04.083,526] {1B}[0m<inf> asset_tracker: DATE_TIME_NOT_OBTAINED{1B}[0m
    Comport Closed - Did the device disconnect?
    Comport Opened 'USB Serial Device (COM5)'
    +CEREG: 2,"3060","082F630B",7,0,0,"11100000","11100000"
    [00:00:01.550,018] {1B}[0m<inf> asset_tracker: LTE cell changed: Cell ID: 137323275, Tracking area: 12384{1B}[0m
    +CSCON: 1
    [00:00:01.600,402] {1B}[0m<inf> asset_tracker: RRC mode: Connected{1B}[0m
    +CEREG: 5,"3060","082F630B",7,,,"00001000","11100000"
    [00:00:04.251,556] {1B}[0m<inf> asset_tracker: Connected to LTE network.{1B}[0m
    [00:00:04.257,995] {1B}[0m<inf> asset_tracker: Connecting to cloud, attempt 1 of 8{1B}[0m
    [00:00:04.265,289] {1B}[0m<inf> asset_tracker: Cloud connection request sent.{1B}[0m
    [00:00:04.272,094] {1B}[0m<inf> asset_tracker: Connection response timeout is set to 30 seconds.{1B}[0m
    [00:00:04.280,609] {1B}[0m<inf> asset_tracker: Network registration status: Connected - roaming{1B}[0m
    [00:00:04.289,001] {1B}[0m<inf> asset_tracker: LTE cell changed: Cell ID: 137323275, Tracking area: 12384{1B}[0m
    [00:00:04.298,278] {1B}[0m<inf> asset_tracker: PSM parameter update: TAU: -1, Active time: 16{1B}[0m
    [00:00:04.306,732] {1B}[0m<dbg> nrf_cloud.api_event_handler: NRF_CLOUD_EVT_TRANSPORT_CONNECTING{1B}[0m
    [00:00:04.315,124] {1B}[0m<inf> asset_tracker: CLOUD_EVT_CONNECTING{1B}[0m
    [00:00:29.882,019] {1B}[1;33m<wrn> date_time: getaddrinfo, error: -11{1B}[0m
    [00:00:55.483,123] {1B}[0m<dbg> nrf_cloud_transport.nct_connect: getaddrinfo failed -11{1B}[0m
    [00:00:55.490,814] {1B}[0m<dbg> nrf_cloud.api_event_handler: NRF_CLOUD_EVT_TRANSPORT_CONNECTING{1B}[0m
    [00:00:55.499,206] {1B}[0m<inf> asset_tracker: CLOUD_EVT_CONNECTING{1B}[0m
    [00:00:55.505,279] {1B}[1;31m<err> asset_tracker: Failed to connect to cloud, error -3{1B}[0m
    [00:00:55.512,878] {1B}[1;31m<err> asset_tracker: Network error, check cloud configuration{1B}[0m
    [00:00:55.520,874] {1B}[1;31m<err> asset_tracker: Device will reboot in 300 seconds{1B}[0m
    [00:00:55.528,289] {1B}[1;31m<err> asset_tracker: LTE link disconnect{1B}[0m
    +CEREG: 0,"3060","082F630B",7,0,0,"11100000","11100000"
    [00:00:58.683,258] {1B}[1;33m<wrn> date_time: getaddrinfo, error: -11{1B}[0m
    [00:00:58.695,861] {1B}[1;33m<wrn> date_time: getaddrinfo, error: -11{1B}[0m
    [00:00:58.708,557] {1B}[1;33m<wrn> date_time: getaddrinfo, error: -11{1B}[0m
    [00:00:58.721,160] {1B}[1;33m<wrn> date_time: getaddrinfo, error: -11{1B}[0m
    [00:00:58.727,264] {1B}[1;33m<wrn> date_time: Not getting time from any NTP server{1B}[0m
    +CSCON: 0
    [00:01:00.543,884] {1B}[0m<inf> asset_tracker: RRC mode: Idle{1B}[0m
    [00:01:00.657,653] {1B}[1;31m<err> asset_tracker: Shutdown modem{1B}[0m
    [00:01:00.670,227] {1B}[0m<inf> asset_tracker: DATE_TIME_NOT_OBTAINED{1B}[0m

    In case anyone is interested...this is the code I used for the https basic example. I added some retries to some of the connections and implemented some button functionality for restarting the app and doing additional https queries for latency testing. I also replaced all LOG_INF and LOG_ERR etc to printk in at_cmd.c in the toolchain for showing all logging messages.

    /*
     * Copyright (c) 2020 Nordic Semiconductor ASA
     *
     * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
     */
    
    #include <string.h>
    #include <zephyr.h>
    #include <stdlib.h>
    #include <net/socket.h>
    #include <modem/nrf_modem_lib.h>
    #include <net/tls_credentials.h>
    #include <modem/lte_lc.h>
    #include <modem/at_cmd.h>
    #include <modem/at_notif.h>
    #include <modem/modem_key_mgmt.h>
    
    #include "hal/nrf_gpio.h"
    #include "sys/reboot.h"
    
    //#include "logging/log.h"
    // uint32_t __log_level __unused = Z_LOG_RESOLVED_LEVEL(LOG_LEVEL_DBG, 0);
    
    #define HTTPS_PORT 443
    
    #define HTTPS_HOSTNAME "example.com"
    
    #define HTTP_HEAD                      \
    	"HEAD / HTTP/1.1\r\n"              \
    	"Host: " HTTPS_HOSTNAME ":443\r\n" \
    	"Connection: close\r\n\r\n"
    
    #define HTTP_HEAD_LEN (sizeof(HTTP_HEAD) - 1)
    
    #define HTTP_HDR_END "\r\n\r\n"
    
    #define RECV_BUF_SIZE 2048
    #define TLS_SEC_TAG 42
    
    static const char send_buf[] = HTTP_HEAD;
    static char recv_buf[RECV_BUF_SIZE];
    
    /* Certificate for `example.com` */
    static const char cert[] = {
    #include "../cert/DigiCertGlobalRootCA.pem"
    };
    
    BUILD_ASSERT(sizeof(cert) < KB(4), "Certificate too large");
    
    bool Attempt_Connection(void);
    static void PrintResetReason(void);
    
    /* Initialize AT communications */
    int at_comms_init(void)
    {
    	int err;
    
    	err = at_cmd_init();
    	if (err)
    	{
    		printk("Failed to initialize AT commands, err %d\n", err);
    		return err;
    	}
    
    	err = at_notif_init();
    	if (err)
    	{
    		printk("Failed to initialize AT notifications, err %d\n", err);
    		return err;
    	}
    
    	return 0;
    }
    
    /* Provision certificate to modem */
    int cert_provision(void)
    {
    	int err;
    	bool exists;
    	uint8_t unused;
    
    	err = modem_key_mgmt_exists(TLS_SEC_TAG,
    								MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN,
    								&exists, &unused);
    	if (err)
    	{
    		printk("Failed to check for certificates err %d\n", err);
    		return err;
    	}
    
    	if (exists)
    	{
    		/* For the sake of simplicity we delete what is provisioned
    		 * with our security tag and reprovision our certificate.
    		 */
    		err = modem_key_mgmt_delete(TLS_SEC_TAG, MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN);
    		if (err)
    		{
    			printk("Failed to delete existing certificate, err %d\n",
    				   err);
    		}
    	}
    
    	printk("Provisioning certificate\n");
    
    	/*  Provision certificate to the modem */
    	err = modem_key_mgmt_write(TLS_SEC_TAG,
    							   MODEM_KEY_MGMT_CRED_TYPE_CA_CHAIN,
    							   cert, sizeof(cert) - 1);
    	if (err)
    	{
    		printk("Failed to provision certificate, err %d\n", err);
    		return err;
    	}
    
    	return 0;
    }
    
    /* Setup TLS options on a given socket */
    int tls_setup(int fd)
    {
    	int err;
    	int verify;
    
    	/* Security tag that we have provisioned the certificate with */
    	const sec_tag_t tls_sec_tag[] = {
    		TLS_SEC_TAG,
    	};
    
    	/* Set up TLS peer verification */
    	enum
    	{
    		NONE = 0,
    		OPTIONAL = 1,
    		REQUIRED = 2,
    	};
    
    	verify = REQUIRED;
    
    	err = setsockopt(fd, SOL_TLS, TLS_PEER_VERIFY, &verify, sizeof(verify));
    	if (err)
    	{
    		printk("Failed to setup peer verification, err %d\n", errno);
    		return err;
    	}
    
    	/* Associate the socket with the security tag
    	 * we have provisioned the certificate with.
    	 */
    	err = setsockopt(fd, SOL_TLS, TLS_SEC_TAG_LIST, tls_sec_tag,
    					 sizeof(tls_sec_tag));
    	if (err)
    	{
    		printk("Failed to setup TLS sec tag, err %d\n", errno);
    		return err;
    	}
    
    	err = setsockopt(fd, SOL_TLS, TLS_HOSTNAME, HTTPS_HOSTNAME, sizeof(HTTPS_HOSTNAME) - 1);
    	if (err)
    	{
    		printk("Failed to setup TLS hostname, err %d\n", errno);
    		return err;
    	}
    	return 0;
    }
    
    void button_thread(void *, void *, void *);
    void SendTask(void *, void *, void *);
    
    K_THREAD_STACK_DEFINE(but_stack, 4096);
    struct k_thread but_data;
    
    K_THREAD_STACK_DEFINE(connect_stack, 4096);
    struct k_thread connect_data;
    
    struct k_sem my_sem;
    void button_thread(void *a, void *b, void *c)
    {
    	const int long_threshold = 800; // 800ms
    	nrf_gpio_cfg_input(26, NRF_GPIO_PIN_PULLUP);
    	int elapsed = 0;
    	const int sleep_interval = 50;
    
    	while (true)
    	{
    		bool but_pressed = (0 == nrf_gpio_pin_read(26));
    		if (but_pressed)
    		{
    			elapsed += sleep_interval;
    		}
    		else
    		{
    			if (elapsed >= long_threshold)
    			{
    				// reset on butt on press
    				printk("\n---rebooting---\n");
    				k_sleep(K_MSEC(sleep_interval));
    				sys_reboot(0);
    			}
    			else if (elapsed > 0)
    			{
    				printk("Button query pressed\n");
    				bool working = Attempt_Connection();
    				printk("\n\n----------------------------\n");
    				if (working)
    				{
    					printk("---> Started <-----\n");
    				}
    				else
    				{
    					printk("---> BUSY <-----\n");
    				}
    			}
    			elapsed = 0;
    		}
    		k_sleep(K_MSEC(sleep_interval));
    	}
    }
    
    #include <nrf_socket.h>
    
    int fd;
    int err;
    char *p;
    int bytes;
    size_t off;
    struct addrinfo *res;
    struct addrinfo hints = {
    	.ai_family = AF_INET,
    	.ai_socktype = SOCK_STREAM,
    };
    
    void main(void)
    {
    	// get reset reason
    	PrintResetReason();
    	k_sem_init(&my_sem, 0, 1);
    
    	k_tid_t my_tid = k_thread_create(&but_data, but_stack, K_THREAD_STACK_SIZEOF(but_stack), button_thread, NULL, NULL, NULL, 1, 0, K_NO_WAIT);
    	k_tid_t my_tid1 = k_thread_create(&connect_data, connect_stack, K_THREAD_STACK_SIZEOF(connect_stack), SendTask, NULL, NULL, NULL, 1, 0, K_NO_WAIT);
    	printk("HTTPS client sample started\n\r");
    
    	err = nrf_modem_lib_init(NORMAL_MODE);
    	if (err)
    	{
    		printk("Failed to initialize modem library!");
    		return;
    	}
    
    	/* Initialize AT comms in order to provision the certificate */
    	err = at_comms_init();
    	if (err)
    	{
    		return;
    	}
    
    	// check signal strength
    	enum at_cmd_state state;
    	at_cmd_write("AT%CESQ=1", NULL, 0, &state);
    
    	/* Provision certificates before connecting to the LTE network */
    	err = cert_provision();
    	if (err)
    	{
    		return;
    	}
    
    	struct nrf_in_addr dns;
    	dns.s_addr = 0x08080808; // Google DNS, 8.8.8.8
    	err = nrf_setdnsaddr(2, &dns);
    	printk("-----> DNS set result %d\n", err);
    
    	printk("-----> Waiting for network.. \n");
    	err = lte_lc_init_and_connect();
    	while (true)
    	{
    		if (err)
    		{
    			printk("-----> Failed to connect to the LTE network, err %d\n", err);
    			err = lte_lc_connect();
    		}
    		else
    		{
    			break;
    		}
    	}
    	printk("-----> CONNECTED\n");
    
    	// start first connection
    	k_sem_give(&my_sem);
    
    	printk("\n\n----------------------------\n");
    	printk("-----> APP COMPLETE <-------\n");
    	printk("----------------------------\n");
    }
    
    bool busy = true;
    
    bool Attempt_Connection(void)
    {
    	if (busy)
    	{
    		return false;
    	}
    	else
    	{
    		k_sem_give(&my_sem); // allow semaphore connections now
    		return true;
    	}
    }
    
    void SendTask(void *a, void *b, void *c)
    {
    	while (true)
    	{
    		bool ret = true;
    		if (k_sem_take(&my_sem, K_FOREVER) == 0)
    		{
    			fd = -1;
    			res = NULL;
    			busy = true;
    
    			printk("-----> Waiting for ip addr.. \n");
    			err = getaddrinfo(HTTPS_HOSTNAME, NULL, &hints, &res);
    			if (err)
    			{
    				printk("getaddrinfo() failed, err %d\n", errno);
    				enum lte_lc_nw_reg_status reg_status;
    				if (0 == lte_lc_nw_reg_status_get(&reg_status))
    				{
    					printk("----->reg status %d\n", (int)reg_status);
    				}
    
    				if (reg_status != LTE_LC_NW_REG_REGISTERED_ROAMING)
    				{
    					printk("----->Attemping connection\n");
    					lte_lc_connect();
    					printk("----->Connected\n");
    				}
    				ret = false;
    				goto cleanup;
    			}
    			printk("-----> GOT IP\n");
    
    			((struct sockaddr_in *)res->ai_addr)->sin_port = htons(HTTPS_PORT);
    
    			fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TLS_1_2);
    			if (fd == -1)
    			{
    				printk("----->Failed to open socket!\n");
    				ret = false;
    				goto cleanup;
    			}
    
    			/* Setup TLS socket options */
    			err = tls_setup(fd);
    			if (err)
    			{
    				ret = false;
    				goto cleanup;
    			}
    
    			printk("-----> Connecting to %s\n", HTTPS_HOSTNAME);
    			err = connect(fd, res->ai_addr, sizeof(struct sockaddr_in));
    			if (err)
    			{
    				printk("----->connect() failed, err: %d\n", errno);
    				ret = false;
    				goto cleanup;
    			}
    
    			off = 0;
    			do
    			{
    				bytes = send(fd, &send_buf[off], HTTP_HEAD_LEN - off, 0);
    				if (bytes < 0)
    				{
    					printk("----->send() failed, err %d\n", errno);
    					ret = false;
    					goto cleanup;
    				}
    				off += bytes;
    			} while (off < HTTP_HEAD_LEN);
    
    			printk("-----> Sent %d bytes\n", off);
    
    			off = 0;
    			do
    			{
    				bytes = recv(fd, &recv_buf[off], RECV_BUF_SIZE - off, 0);
    				if (bytes < 0)
    				{
    					printk("----->recv() failed, err %d\n", errno);
    					ret = false;
    					goto cleanup;
    				}
    				off += bytes;
    			} while (bytes != 0 /* peer closed connection */);
    
    			printk("-----> Received %d bytes\n", off);
    
    			/* Print HTTP response */
    			p = strstr(recv_buf, "\r\n");
    			if (p)
    			{
    				off = p - recv_buf;
    				recv_buf[off + 1] = '\0';
    				printk("\n>\t %s\n\n", recv_buf);
    			}
    
    			printk("-----> Finished, closing socket.\n");
    
    		cleanup:
    			if (res != NULL)
    			{
    				freeaddrinfo(res);
    			}
    
    			if (fd != -1)
    			{
    				(void)close(fd);
    			}
    
    			if (ret)
    			{
    				printk("---> CONN ATTEMPT SUCCESS <-----\n");
    			}
    			else
    			{
    				printk("---> CONN ATTEMPT FAIL <-----\n");
    			}
    			busy = false;
    		}
    	}
    }
    
    static void PrintResetReason(void)
    {
    	uint32_t reset_reason = NRF_POWER->RESETREAS;
    	NRF_POWER->RESETREAS = 0xffffffff;
    	printk("rst reason 0x%x\n", reset_reason);
    	if (reset_reason & 1 << 18)
    	{
    		printk("Rst source: CTRL-AP\n");
    	}
    
    	if (reset_reason & 1 << 17)
    	{
    		printk("Rst source: CPU LockUp\n");
    	}
    
    	if (reset_reason & 1 << 16)
    	{
    		printk("Rst source: AIRCR.SYSRESETREQ\n");
    	}
    
    	if (reset_reason & 1 << 4)
    	{
    		printk("Rst source: Wakeup from System OFF triggered by debug\n");
    	}
    
    	if (reset_reason & 1 << 2)
    	{
    		printk("Rst source: Wakeup from System OFF triggered by gpio\n");
    	}
    
    	if (reset_reason & 1 << 1)
    	{
    		printk("Rst source: Watchdog\n");
    	}
    
    	if (reset_reason & 1 << 0)
    	{
    		printk("Rst source: internal?\n");
    	}
    }

  • Hi,

     

    Could it be that there's network related errors in your connection? Could you try using at_client, in combination with the LTE Link Monitor PC application? This automatically enables network related error/cause codes to be printed if any appear.

    Issue these commands from the PC application:

    AT+CEREG=5
    AT+CFUN=1
    AT+CFUN?

     

    And please post the log from letting this run for some time.

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Could it be that there's network related errors in your connection? Could you try using at_client, in combination with the LTE Link Monitor PC application? This automatically enables network related error/cause codes to be printed if any appear.

    Issue these commands from the PC application:

    AT+CEREG=5
    AT+CFUN=1
    AT+CFUN?

     

    And please post the log from letting this run for some time.

     

    Kind regards,

    Håkon

Children
No Data
Related