nRF Cloud Connection using COAP Protocol (err:-111)

Hello,

I want to request AGNSS information from nrf cloud services using my nRF9151DK board. As a first step, I flashed the nRF Cloud multi-service application onto my DK. Using this application, I successfully claimed my board in the cloud, and it is provisioned; I can now see my device under device management.

Using the nRF Cloud multi-service application as a base, I developed an application to connect to nRF Cloud using the COAP protocol. To connect to the cloud, I followed these steps:

  1. I initialize the modem library and connect to the network using the lte_lc_connect_async() function. (I can send and receive data to the echo server of nRF without an issue, so there isn't any problem with connectivity.)
  2. When the modem successfully connects to the network and is roaming, I initialize the nRF Cloud library using the nrf_cloud_coap_init() function. After initializing without error, I check credentials using nrf_cloud_credentials_configured_check(). I do not receive an error message from this step.
  3. I initialize date_time_event_handler using date_time_register_handler(date_time_event_handler). In any case, I get the current time using date_time_update_async(NULL).
  4. After confirming the date and time are valid, I try to connect using nrf_cloud_coap_connect(). At this step, I usually get the following error:

[00:01:09.221,893] <err> nrf_cloud_coap_transport: Could not connect to nRF Cloud CoAP server coap.nrfcloud.com, port: 13334. err: -111
[00:01:09.221,893] <err> cloud_connection: Could not connect to nRF Cloud, error: -111

When I activate the log in debug level, I see the error below. The application tries to get the IP of coap.nrfcloud.com using getaddrinfo(), but it could not retrieve the host's IP address. When I tried to get the IP address of coap.nrfcloud.com outside of the main application using the getaddrinfo() function, I received the same error.

[00:00:08.500,976] <inf> cloud_connection: Connecting to nRF Cloud
[00:00:08.501,007] <dbg> nrf_cloud_dns: nrf_cloud_connect_host: Connecting to nRF Cloud
[00:00:08.501,037] <dbg> nrf_cloud_dns: nrf_cloud_connect_host: Trying IPv6 addresses for coap.nrfcloud.com
[00:00:08.501,586] <dbg> nrf_cloud_dns: nrf_cloud_try_addresses: getaddrinfo for coap.nrfcloud.com, port: 13334 failed: -2, errno: 0
[00:00:08.501,617] <dbg> nrf_cloud_dns: nrf_cloud_connect_host: Trying IPv4 addresses for coap.nrfcloud.com
[00:00:08.502,014] <dbg> nrf_cloud_dns: nrf_cloud_try_addresses: getaddrinfo for coap.nrfcloud.com, port: 13334 failed: -2, errno: 0
[00:00:08.502,075] <dbg> nrf_cloud_dns: nrf_cloud_connect_host: Cannot connect to nRF Cloud host: coap.nrfcloud.com, error: -125
[00:00:08.502,136] <err> nrf_cloud_coap_transport: Could not connect to nRF Cloud CoAP server coap.nrfcloud.com, port: 13334. err: -111
[00:00:08.502,136] <err> cloud_connection: Could not connect to nRF Cloud, error: -111

The interesting part is that sometimes I can connect to nRF Cloud without any issues. On one occasion, I successfully sent a location message to the cloud and saw that message appear in the cloud.

Based on the successful message sending and connection to the cloud, I assume there isn't any configuration mistake in my application.

Could you help me understand if this problem is related to my device, or if the cloud side? If the problem is related to getaddrinfo(), can I connect to the cloud using a pre-defined socket rather than using getaddrinfo()? I tried to get address information of "udp-echo.nordicsemi.academy" using getaddrinfo() and when network is roaming and I could not get the information of this host too.

My SDK version is v3.0.0 and toolchain version is v2.9.0

Related