Connect to nRF Cloud using the nRF52840 and OpenThread network via MQTT over TLS failed

Hi All,

I am unable to establish a successful connection to nRF Cloud using the nRF52840 and OpenThread network via MQTT over TLS.

Sensitive information in the project, such as certificates, will be invalidated by deleting devices after the issue is resolved.


My NCS version is v2.5.2, and I aim to connect to nRF Cloud using the nRF52840 with the OpenThread network.

I am aware of the ncs\v2.5.2\nrf\samples\cellular\nrf_cloud_multi_service example, but it is complex and not specifically tailored for the Thread network. Therefore, I initially attempted to use the relatively simpler ncs\v2.5.2\nrf\samples\net\aws_iot example.

According to the nRF Cloud documentation, I first created a device using the CreateDeviceCertificate API and obtained the device certificate. The returned content is as follows:

{
    "clientId": "device001",
    "caCert": "-----BEGIN CERTIFICATE-----\nMIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\nADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\nb24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL\nMAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\nb3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj\nca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM\n9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw\nIFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6\nVOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L\n93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm\njgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC\nAYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA\nA4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI\nU5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs\nN+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv\no/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU\n5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy\nrqXRfboQnoZsG4q5WTP468SQvvG5\n-----END CERTIFICATE-----\n",
    "privateKey": "-----BEGIN EC PARAMETERS-----\nBggqhkjOPQMBBw==\n-----END EC PARAMETERS-----\n-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIFYf7XHeemu6d+i3sInjMB+sfaRc4388kB77CCUqxJlwoAoGCCqGSM49\nAwEHoUQDQgAEREwfetVI+bXNsdcEhrijYMnsgsqR2aNDNWnKDmlsVAh7BohJ8sLB\nLROSzhg2TgdSMmP85utf+odzTsHv1uxJ8w==\n-----END EC PRIVATE KEY-----\n",
    "clientCert": "-----BEGIN CERTIFICATE-----\nMIICoDCCAYgCCQCaZE9v50In9jANBgkqhkiG9w0BAQsFADBsMQswCQYDVQQGEwJO\nTzEPMA0GA1UECAwGTm9yd2F5MRIwEAYDVQQHDAlUcm9uZGhlaW0xHTAbBgNVBAoM\nFE5vcmRpYyBTZW1pY29uZHVjdG9yMRkwFwYDVQQLDBBHZW5lcmljLTE0YTE4Yjkw\nMCAXDTI0MDIyOTA3NDMwMloYDzIwNTQwMjIxMDc0MzAyWjCBgDELMAkGA1UEBhMC\nTk8xEjAQBgNVBAgMCVRyb25kZWxhZzESMBAGA1UEBwwJVHJvbmRoZWltMSEwHwYD\nVQQKDBhOb3JkaWMgU2VtaWNvbmR1Y3RvciBBU0ExEjAQBgNVBAMMCWRldmljZTAw\nMTESMBAGA1UELhMJZGV2aWNlMDAxMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE\nREwfetVI+bXNsdcEhrijYMnsgsqR2aNDNWnKDmlsVAh7BohJ8sLBLROSzhg2TgdS\nMmP85utf+odzTsHv1uxJ8zANBgkqhkiG9w0BAQsFAAOCAQEAnrOOM440DEzLvrdH\nFPbLZfjgS/qxZG41kGm6zR6TRGRaORAIOocwkrnGpaGcqFHWIvcP4l1nKe3DAnDj\n4QLnmEiogvS2aB7TBTokd67KCjt/mP+6w9SIaSph7I6+yjjcxasABDbYb0kd9X99\npvZ5OAMLLbSmIQan9lXakONFeE6iZVDMp9gL0DdB1CP3ydEQm9oG+Y6CnQhU3egS\nOLqVSNZNPlGx2Y35kwu6HmAcRoYCuLQXXbPw8lPLvuJXdA6+mQP6Uufc77AzPuvv\nKQv+EtmTAmv3r4GBCIij1I38MWQeMNTi79uOK4TOZvAl75TEv0boaa9gwIFNCXgA\nrpm+Uw==\n-----END CERTIFICATE-----\n-----BEGIN CERTIFICATE-----\nMIIDqzCCApOgAwIBAgIJAOXo6/ALtz+gMA0GCSqGSIb3DQEBCwUAMGwxCzAJBgNV\nBAYTAk5PMQ8wDQYDVQQIDAZOb3J3YXkxEjAQBgNVBAcMCVRyb25kaGVpbTEdMBsG\nA1UECgwUTm9yZGljIFNlbWljb25kdWN0b3IxGTAXBgNVBAsMEEdlbmVyaWMtMTRh\nMThiOTAwHhcNMjMwMzE2MDMzODAwWhcNMjYwMTAzMDMzODAwWjBsMQswCQYDVQQG\nEwJOTzEPMA0GA1UECAwGTm9yd2F5MRIwEAYDVQQHDAlUcm9uZGhlaW0xHTAbBgNV\nBAoMFE5vcmRpYyBTZW1pY29uZHVjdG9yMRkwFwYDVQQLDBBHZW5lcmljLTE0YTE4\nYjkwMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2CE46Te7DvZxfauo\nCZhNGpvJ/RNP5cfunU3qnzhpnpDwbgMT8lU2zMe14kolzNr2LQN09EYSDmBYh5je\nszKUT1FKKvMAs59UnPrdLiwWG6tWhfa5CzsNgMi+TjGcqK8K7D+Gv+b7EzDqtYFM\ng5FovJE6wYO/DIHRq7dVa21B3GB2vqiQZCXuef8kc1NCAXFm2MX5lkV6MQxyXYBo\nV8+/jNTiXSriGFJVG6MvF4lRTKC0TTV2NBFaJmRDwEuBoUSpbNoNDhhNOm+kbVBH\nlfXP81YwNOl+RVNbjGmA2lG3SEf/42jsCiaKjXp1cozF+EKGI8/H7ryMyoq0a3dG\nEFy7zwIDAQABo1AwTjAdBgNVHQ4EFgQU8QcvSXGLHmKmu6LrgIobANmjQ6IwHwYD\nVR0jBBgwFoAU8QcvSXGLHmKmu6LrgIobANmjQ6IwDAYDVR0TBAUwAwEB/zANBgkq\nhkiG9w0BAQsFAAOCAQEAAuXJuAx2BBDh44ljxqQsfLfhDNN3J8LZeoG5wbcSKQw6\nXCBp4BO/oeL8SWZ8G7WmTIxxpWyf5wBEvVGqmUnKj+skRXKVsHon63+ihomGDZTM\nb+lsPJFH0XYvmFhYhRMnDJC5FVyhsyRloyWgmRcsFoXqlkySPD8qN7/EXvHdcQwI\nB4d6mfcN9943Oywh72GdlMPxvmdBsOoRDP46Hb8NoVlEcgvNT4SWfjh6AHZiqO5r\n2NOCvvbO8S2r1NzCXBuBPtm5dY/hmbZOCiTBnK7SX6Aol24rVH7vuYOW0iLv30O2\nqke6pyCrthgdokfe2kd94L/Saos6cR8phmH5SqkZFg==\n-----END CERTIFICATE-----\n"
}

I converted it to a standard PEM format certificate and validated the certificate's functionality by testing the connection using client software like mqttx. The test results showed a successful connection with a proper TLS handshake, and the simulated device appeared online on the nRF Cloud platform.


Next, I started modifying the configuration settings and code in the aws_iot example, including:

  • adjustments related to net txrx/log buffer sizes
  • net tls/offload configurations
  • enabling IPv6/TCP/OpenThread
  • configuring aws_iot to use IPv6 addresses/a specific client_id/a specific server address/device certificate
  • setting mbedtls-related parameters such as heap size/CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN
  • updating certificate information with the actual data obtained earlier (ca-cert.pem, client-cert.pem, private-key.pem)

These changes are mostly from existing issues with devzone:

My target IPv6 address involved ping mqtt.nrfcloud.com on my PC to obtain its IPv4 address and then using CONFIG_OPENTHREAD_SHELL=y on th device to ping this address and acquire the NAT64 address.

ubuntu@guoyuchao-vm:~$ ping mqtt.nrfcloud.com
PING a2n7tk1kp18wix-ats.iot.us-east-1.amazonaws.com (54.160.125.106) 56(84) bytes of data.
64 bytes from ec2-54-160-125-106.compute-1.amazonaws.com (54.160.125.106): icmp_seq=1 ttl=62 time=1.59 ms
64 bytes from ec2-54-160-125-106.compute-1.amazonaws.com (54.160.125.106): icmp_seq=2 ttl=62 time=1.03 ms
64 bytes from ec2-54-160-125-106.compute-1.amazonaws.com (54.160.125.106): icmp_seq=3 ttl=62 time=0.481 ms
^C
--- a2n7tk1kp18wix-ats.iot.us-east-1.amazonaws.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
rtt min/avg/max/mdev = 0.481/1.033/1.589/0.452 ms


uart:~$ ot ping 54.160.125.106
Pinging synthesized IPv6 address: fd12:6809:36e5:2:0:0:36a0:7d6a
16 bytes from fd12:6809:36e5:2:0:0:36a0:7d6a: icmp_seq=2 hlim=60 time=16ms
1 packets transmitted, 1 packets received. Packet loss = 0.0%. Round-trip min/avg/max = 16/16.0/16 ms.
Done

uart:~$ ot ping fd12:6809:36e5:2::36a0:7d6a
16 bytes from fd12:6809:36e5:2:0:0:36a0:7d6a: icmp_seq=1 hlim=60 time=14ms
1 packets transmitted, 1 packets received. Packet loss = 0.0%. Round-trip min/avg/max = 14/14.0/14 ms.
Done

uart:~$ net ping fd12:6809:36e5:2::36a0:7d6a
PING fd12:6809:36e5:2::36a0:7d6a
8 bytes from fd12:6809:36e5:2::36a0:7d6a to fd11:3a::da96:b69:20e0:1d5d: icmp_seq=1 ttl=60 rssi=-174 time=29 ms
8 bytes from fd12:6809:36e5:2::36a0:7d6a to fd11:3a::da96:b69:20e0:1d5d: icmp_seq=2 ttl=60 rssi=-174 time=14 ms
8 bytes from fd12:6809:36e5:2::36a0:7d6a to fd11:3a::da96:b69:20e0:1d5d: icmp_seq=3 ttl=60 rssi=-174 time=13 ms


The only code modification made was in the client_broker_init function within the "ncs\v2.5.2\nrf\subsys\net\lib\aws_iot\src\aws_iot.c" file.

I manually changed tls_cfg->hostname to "iot.us-east-1.amazonaws.com," which is the CNAME record obtained from ping mqtt.nrfcloud.com.

This modification was necessary because it seemed that nRF Cloud did not accept mqtt.nrfcloud.com during the TLS handshake but accepted iot.us-east-1.amazonaws.com (although I also attempted to modify it to mqtt.nrfcloud.com).


Despite various adjustments, I have been unsuccessful in establishing a successful handshake and connection with nRF Cloud.

To rule out any issues related to OpenThread+TCP+MQTT, I tried disabling the mbedtls configurations, changing the MQTT server address to a public one (e.g., broker.emqx.io), and successfully connected without TLS. This indicated that my network environment, IP address connection method, and openthread functionalities like otbr/nat64 were functioning correctly.


My OpenThread network dataset information is as follows:

uart:~$ ot dataset active -x
35060004001fffe00c0402a0f7f8000300001a010212340208ce3544d81bfd9d8c030f484f4f5249495f4155544f54455354051080123a4556560aae5077abd2dd61b6610410655cbb7bb85d51b84d1b0c39c481e0c80708fdc56bfdb7900c9a0e080000000000010000
Done

uart:~$ ot dataset active
Active Timestamp: 1
Channel: 26
Channel Mask: 0x07fff800
Ext PAN ID: ce3544d81bfd9d8c
Mesh Local Prefix: fdc5:6bfd:b790:c9a::/64
Network Key: 80123a4556560aae5077abd2dd61b661
Network Name: HOORII_AUTOTEST
PAN ID: 0x1234
PSKc: 655cbb7bb85d51b84d1b0c39c481e0c8
Security Policy: 672 onrc 0
Done


My prj.conf is as follows:

#
# Copyright (c) 2020 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

# General
CONFIG_LOG=y
CONFIG_LOG_BUFFER_SIZE=2048
CONFIG_HW_ID_LIBRARY=y
CONFIG_ASSERT=y
CONFIG_JSON_LIBRARY=y
# CONFIG_LOG_MODE_IMMEDIATE=y

# Heap and stacks
CONFIG_HEAP_MEM_POOL_SIZE=8192
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
CONFIG_NET_MGMT_EVENT_QUEUE_SIZE=16
CONFIG_NET_MGMT_EVENT_STACK_SIZE=4096

CONFIG_AWS_IOT_POLL_THREAD_STACK_SIZE=4096

# Network
CONFIG_NETWORKING=y
CONFIG_NET_NATIVE=y
CONFIG_NET_IPV4=n
CONFIG_NET_CONNECTION_MANAGER=y

# AWS IoT library
CONFIG_AWS_IOT=y
CONFIG_AWS_IOT_APP_SUBSCRIPTION_LIST_COUNT=2
CONFIG_AWS_IOT_TOPIC_UPDATE_DELTA_SUBSCRIBE=y
CONFIG_AWS_IOT_TOPIC_GET_ACCEPTED_SUBSCRIBE=y
CONFIG_AWS_IOT_TOPIC_GET_REJECTED_SUBSCRIBE=y

CONFIG_AWS_IOT_CLIENT_ID_STATIC="device001"
CONFIG_AWS_IOT_CLIENT_ID_MAX_LEN=128
CONFIG_AWS_IOT_SEC_TAG=16842753

# ----------------------------------------------------
CONFIG_NET_TCP=y

CONFIG_AWS_IOT_IPV6=y
CONFIG_AWS_IOT_BROKER_HOST_NAME="fd12:6809:36e5:2:0:0:36a0:7d6a"
CONFIG_AWS_IOT_PROVISION_CERTIFICATES=y

CONFIG_NET_L2_OPENTHREAD=y
CONFIG_OPENTHREAD_SLAAC=y
CONFIG_OPENTHREAD_MTD=y
CONFIG_OPENTHREAD_TCP_ENABLE=n

CONFIG_OPENTHREAD_MANUAL_START=n
CONFIG_OPENTHREAD_PANID=4660
CONFIG_OPENTHREAD_XPANID="ce:35:44:d8:1b:fd:9d:8c"
CONFIG_OPENTHREAD_NETWORK_NAME="HOORII_AUTOTEST"
CONFIG_OPENTHREAD_NETWORKKEY="80:12:3a:45:56:56:0a:ae:50:77:ab:d2:dd:61:b6:61"
CONFIG_OPENTHREAD_CHANNEL=26

CONFIG_NET_SHELL=y
CONFIG_OPENTHREAD_SHELL=y

CONFIG_NET_LOG=y
CONFIG_NET_CONTEXT_LOG_LEVEL_DBG=y
CONFIG_MQTT_LOG_LEVEL_DBG=y
CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y
CONFIG_NET_TCP_LOG_LEVEL_DBG=y
CONFIG_AWS_IOT_LOG_LEVEL_DBG=y

# Enable Mbed TLS logs
CONFIG_MBEDTLS_DEBUG=y
CONFIG_MBEDTLS_LOG_LEVEL_DBG=y

# START NET

#Socket settings
CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
CONFIG_POSIX_MAX_FDS=8
CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=10

CONFIG_NET_PKT_RX_COUNT=16
CONFIG_NET_PKT_TX_COUNT=16
CONFIG_NET_BUF_RX_COUNT=100
CONFIG_NET_BUF_TX_COUNT=100

CONFIG_NET_SOCKETS_POSIX_NAMES=y
CONFIG_NET_SOCKETS_POLL_MAX=10

CONFIG_NET_CONTEXT_RCVTIMEO=y
CONFIG_NET_CONTEXT_SNDTIMEO=y

CONFIG_NET_MAX_CONTEXTS=10

CONFIG_NET_CONTEXT_NET_PKT_POOL=y

CONFIG_NET_SOCKETS_OFFLOAD=n

CONFIG_NET_RX_STACK_SIZE=4096


# MBEDTLS

# FROM DEVZONE
# https://devzone.nordicsemi.com/f/nordic-q-a/86632/openthread-and-mqtt-over-tls-is-single-program
# https://devzone.nordicsemi.com/f/nordic-q-a/95781/adaption-to-tcp-tls-on-top-of-openthread
# https://devzone.nordicsemi.com/f/nordic-q-a/90352/error--22-in-mqtt_connect---nrf52840dk-with-azure-iot-hub-using-openthread-and-tcp

#MBEDTLS and security configuration 
CONFIG_NORDIC_SECURITY_BACKEND=n
CONFIG_NRF_SECURITY=n
CONFIG_NET_TCP_ISN_RFC6528=n

CONFIG_NRF_SECURITY=n
CONFIG_OPENTHREAD_MBEDTLS_CHOICE=y
CONFIG_MBEDTLS_TLS_VERSION_1_2=y
CONFIG_MBEDTLS_CIPHER_MODE_CBC_ENABLED=y
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_PSK_ENABLED=y
CONFIG_OPENTHREAD_NRF_SECURITY_CHOICE=n

CONFIG_MBEDTLS_ECDSA_C=y
CONFIG_MBEDTLS_SHA256_C=y
CONFIG_MBEDTLS_RSA_C=y
CONFIG_MBEDTLS_AES_C=y
CONFIG_MBEDTLS_PKCS1_V21=y

CONFIG_MBEDTLS_PEM_CERTIFICATE_FORMAT=y
CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED=y
CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=y
CONFIG_MBEDTLS_CIPHER_AES_ENABLED=y
CONFIG_MBEDTLS_CIPHER_CCM_ENABLED=y
CONFIG_MBEDTLS_CIPHER_GCM_ENABLED=y
CONFIG_MBEDTLS_GCM_C=y

CONFIG_MBEDTLS=y
CONFIG_MBEDTLS_BUILTIN=y
CONFIG_MBEDTLS_ENABLE_HEAP=y
CONFIG_MBEDTLS_HEAP_SIZE=64000
CONFIG_MBEDTLS_ENTROPY_ENABLED=y
# certificate must fit into one message, fragmenting is not supported
CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=16384

#Credentials
CONFIG_TLS_CREDENTIALS=y


I will share my complete project, hoping to help you analyze the problem.

My goal was to get some code or configuration changes I needed to make in order to connect to nRF Cloud, such as:

  • openthread configuration
  • network configuration
  • mbedtls configuration,
  • etc.

aws_iot_devzone.zip

  • Hi,

    Can you provide device logs and describe the problem in more details? Do you get any error codes reported in your application? More details will make it easier to ask internal teams for help on possible root causes.

    Here are some suggestions that might try out:

    • Our MQTT Sample have support for MQTT and TLS. It should be relatively easy to port the WiFi config over to OpenThread for the nRF52840. This sample should already have the certificates setup correctly.
    • The Kconfig CONFIG_MBEDTLS_KEY_EXCHANGE_ALL_ENABLED often helps with TLS-related issues.
    • The PSA API can now be used for crypto in Thread. This would likely change the TLS config quite a bit. This might not be an easier route, but it might resolving the issue by looking at it from a different angle. See this page for more details.
    • There is a snippet available for enabling Thread Commissioning Over Authenticated TLS in the CLI sample, which might be useful. 

    Best regards,
    Jørgen

  • Hi, Jørgen

    Thanks for your reply!

    I can't do exactly what you suggest, because it would cause a lot of compile errors that seem to be due to conflicting or missing configuration items. But I have made some progress on another path and I hope you can give me some advice on this.

    According to the overlay-tls-nrf91.conf.conf configuration, I could have used the aws_iot example to connect to nRF Cloud.

    aws_iot_success.zip


    But the same configuration in nrf_cloud_multi_service would have resulted in a connection failure error with the following log:

    *** Booting nRF Connect SDK v2.5.2 ***
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Image index: 0, Swap type: none
    I: Bootloader chainload address offset: 0xc000
    ▒[00:00:00.011,383] <inf> ieee802154_nrf5: nRF5 802154 radio initialized
    [00:00:00.109,436] <inf> net_l2_openthread: State changed! Flags: 0x00038200 Current role: disabled
    [00:00:00.110,351] <inf> net_l2_openthread: OpenThread version: OPENTHREAD/57ef721ee; Zephyr; Mar  6 2024 16:32:23
    [00:00:00.112,609] <inf> net_l2_openthread: Network name: HOORII_AUTOTEST
    [00:00:00.113,037] <inf> net_l2_openthread: State changed! Flags: 0x3107d11d Current role: detached
    *** Booting nRF Connect SDK v2.5.2 ***
    [00:00:00.117,828] <inf> main: nRF Cloud multi-service sample has started, version: 1.0.0, protocol: MQTT
    [00:00:00.117,858] <dbg> led_control: start_led_pattern: LED Pattern Requested
    [00:00:00.117,889] <inf> cloud_connection: Setting up nRF Cloud library...
    [00:00:00.118,286] <wrn> nrf_cloud_transport: CONFIG_NRF_CLOUD_PROVISION_CERTIFICATES is not secure and should be used only for testing purposes
    [00:00:00.118,347] <inf> cloud_connection: Waiting for network ready...
    [00:00:00.118,377] <dbg> led_control: led_animation_thread_fn: LED Management Started
    [00:00:00.118,408] <dbg> led_control: led_animation_thread_fn: LED Pattern Started
    [00:00:00.118,469] <dbg> message_queue: consume_device_message: Consuming an enqueued device message
    [00:00:01.110,412] <inf> net_l2_openthread: State changed! Flags: 0x301032b7 Current role: child
    [00:00:01.111,175] <inf> net_l2_openthread: State changed! Flags: 0x00000001 Current role: child
    [00:00:01.111,907] <inf> cloud_connection: Network connectivity gained!
    [00:00:02.112,091] <inf> cloud_connection: Network is ready
    [00:00:02.112,091] <inf> cloud_connection: Connecting to nRF Cloud
    [00:00:02.112,152] <inf> cloud_connection: Connected to nRF Cloud
    [00:00:02.112,152] <dbg> cloud_connection: start_readiness_timeout: Starting cloud connection readiness timeout for 600 seconds
    [00:00:02.112,182] <dbg> cloud_connection: cloud_connection_thread_fn: Awaiting disconnection from nRF Cloud
    [00:00:02.132,598] <dbg> cloud_connection: cloud_event_handler: NRF_CLOUD_EVT_TRANSPORT_CONNECTING
    [00:00:04.913,513] <inf> net_mqtt: Connect completed
    [00:00:05.525,451] <dbg> cloud_connection: cloud_event_handler: NRF_CLOUD_EVT_TRANSPORT_CONNECTED
    [00:00:06.780,426] <inf> nrf_cloud_codec_internal: LogLvl changed to 4
    [00:00:06.780,914] <dbg> cloud_connection: cloud_event_handler: NRF_CLOUD_EVT_RX_DATA_SHADOW
    [00:00:06.789,520] <dbg> cloud_connection: cloud_event_handler: NRF_CLOUD_EVT_USER_ASSOCIATED
    [00:00:07.803,741] <dbg> cloud_connection: cloud_event_handler: NRF_CLOUD_EVT_RX_DATA_SHADOW
    [00:00:10.525,604] <err> net_mqtt_rx: [CID 0x2000c984]: Connection closed.
    [00:00:10.525,634] <inf> net_mqtt_sock_tls: Closing socket 0
    [00:00:10.531,524] <dbg> cloud_connection: cloud_event_handler: NRF_CLOUD_EVT_TRANSPORT_DISCONNECTED
    [00:00:10.531,524] <dbg> cloud_connection: clear_readiness_timeout: Stopping cloud connection readiness timeout
    [00:00:10.531,555] <inf> cloud_connection: Disconnecting from nRF Cloud
    [00:00:10.531,585] <dbg> cloud_connection: disconnect_cloud: Already disconnected from nRF Cloud
    [00:00:10.531,616] <inf> cloud_connection: Disconnected from nRF Cloud
    [00:00:10.531,616] <inf> cloud_connection: Retrying in 30 seconds...
    [00:00:10.531,677] <err> nrf_cloud_transport: MQTT input error: -128
    [00:00:10.531,799] <err> nrf_cloud_transport: Error disconnecting from cloud: -128
    


    By scratching packets on OTBR, I could see that it appeared to have completed the TLS handshake, but for some reason the connection eventually dropped.nrfcloud_fail.pcapng


    Currently, the full prj.conf and project I'm using at nrf_cloud_multi_service is as follows:

    #
    # Copyright (c) 2022 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    
    # Log level
    # For more verbose and detailed log output, set the log level to
    # CONFIG_MULTI_SERVICE_LOG_LEVEL_DBG=y instead.
    CONFIG_MULTI_SERVICE_LOG_LEVEL_DBG=y
    
    # General config
    CONFIG_EVENTS=y
    CONFIG_PICOLIBC=y
    CONFIG_PICOLIBC_IO_FLOAT=y
    CONFIG_RESET_ON_FATAL_ERROR=y
    CONFIG_NCS_SAMPLES_DEFAULTS=y
    
    # LED indication
    # Uncomment these to minimize LED state indication when power savings are necessary
    # CONFIG_LED_VERBOSE_INDICATION=n
    # CONFIG_LED_CONTINUOUS_INDICATION=n
    
    # Or, uncomment this to completely disable LED state indication
    # CONFIG_LED_INDICATION_DISABLED=y
    
    # Improved Logging
    # CONFIG_LOG_MODE_DEFERRED allows logging from multiple threads simultaneously without creating
    # splintered log entries, at the cost of needing a buffer for storing logs.
    CONFIG_LOG_MODE_DEFERRED=y
    
    # CONFIG_LOG_BUFFER_SIZE is the aforementioned buffer. A size of 4096 bytes is useful for debugging
    # and prototyping, but is probably more than necessary for production-ready firmware.
    CONFIG_LOG_BUFFER_SIZE=4096
    
    # Heap and stacks
    # CONFIG_AT_MONITOR_HEAP_SIZE=1024
    # Extended memory heap size needed both for PGPS and for encoding JSON-based nRF Cloud Device Messages.
    CONFIG_HEAP_MEM_POOL_SIZE=24576
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=3072
    
    # Enable Networking and Connection Manager.
    CONFIG_NETWORKING=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_OFFLOAD=n
    CONFIG_NET_MGMT_EVENT_STACK_SIZE=4096
    CONFIG_NET_MGMT_EVENT_QUEUE_SIZE=16
    CONFIG_NET_CONNECTION_MANAGER_MONITOR_STACK_SIZE=1024
    CONFIG_MAIN_STACK_SIZE=4096
    
    # Enable LTE Connectivity using Connection Manager
    CONFIG_NET_IPV4=n
    CONFIG_NET_IPV6=y
    CONFIG_NET_IPV6_NBR_CACHE=n
    CONFIG_NET_IPV6_MLD=n
    CONFIG_NET_CONNECTION_MANAGER=y
    CONFIG_LTE_CONNECTIVITY=n
    # CONFIG_NRF_MODEM_LIB_ON_FAULT_APPLICATION_SPECIFIC=y
    # Enable power savings mode
    # CONFIG_LTE_PSM_REQ=y
    
    # Modem library
    # CONFIG_NRF_MODEM_LIB=n
    
    # AT commands interface
    # CONFIG_UART_INTERRUPT_DRIVEN=y
    # CONFIG_AT_HOST_LIBRARY=n
    
    # nRF Cloud
    CONFIG_NRF_CLOUD_MQTT=y # This also enables FOTA by implicitly setting CONFIG_NRF_CLOUD_FOTA=y
    
    # MQTT
    CONFIG_MQTT_KEEPALIVE=120
    
    # MCUBOOT - Needed by FOTA
    CONFIG_BOOTLOADER_MCUBOOT=y
    CONFIG_IMG_MANAGER=y
    CONFIG_MCUBOOT_IMG_MANAGER=y
    CONFIG_STREAM_FLASH_ERASE=y
    
    # # Location Services configuration
    # CONFIG_LOCATION=y
    # CONFIG_LOCATION_METHOD_GNSS=y
    # CONFIG_LOCATION_METHOD_CELLULAR=y
    # CONFIG_NRF_CLOUD_AGNSS=y
    # CONFIG_NRF_CLOUD_LOCATION=y
    # CONFIG_MODEM_INFO=y
    # CONFIG_MODEM_INFO_ADD_NETWORK=y
    # CONFIG_NRF_CLOUD_PGPS=y
    # CONFIG_NRF_CLOUD_PGPS_REPLACEMENT_THRESHOLD=4
    # CONFIG_NRF_CLOUD_PGPS_REQUEST_UPON_INIT=y
    CONFIG_NRF_CLOUD_LOCATION=n
    CONFIG_MODEM_INFO=n
    CONFIG_LOCATION_TRACKING=n
    
    CONFIG_NRF_CLOUD_FOTA=n
    
    CONFIG_TEMP_TRACKING=n
    CONFIG_LED_VERBOSE_INDICATION=n
    CONFIG_LED_CONTINUOUS_INDICATION=n
    CONFIG_TEST_COUNTER=n
    CONFIG_AT_CMD_REQUESTS=n
    
    # Date Time lib - Used by PGPS and main application
    CONFIG_DATE_TIME=y
    
    # # LTE link control - used by PGPS and main application
    # CONFIG_LTE_LINK_CONTROL=y
    # CONFIG_LTE_NETWORK_MODE_LTE_M_GPS=y
    
    # Settings - used by nRF Cloud library and PGPS
    CONFIG_SETTINGS=y
    CONFIG_SETTINGS_FCB=y
    CONFIG_FCB=y
    
    # # Download Client - used by FOTA and PGPS
    # CONFIG_DOWNLOAD_CLIENT=y
    # CONFIG_DOWNLOAD_CLIENT_HTTP_FRAG_SIZE_1024=y
    # CONFIG_DOWNLOAD_CLIENT_STACK_SIZE=4096
    # CONFIG_DOWNLOAD_CLIENT_BUF_SIZE=2300
    # CONFIG_DOWNLOAD_CLIENT_MAX_HOSTNAME_SIZE=128
    
    # Flash - Used by FOTA and PGPS
    CONFIG_FLASH=y
    CONFIG_FLASH_PAGE_LAYOUT=y
    CONFIG_FLASH_MAP=y
    CONFIG_STREAM_FLASH=y
    CONFIG_MPU_ALLOW_FLASH_WRITE=y
    # CONFIG_PM_EXTERNAL_FLASH_MCUBOOT_SECONDARY=n
    CONFIG_NRF_CLOUD_ALERT=n
    CONFIG_NRF_CLOUD_LOG_DIRECT=y
    CONFIG_NRF_CLOUD_LOG_OUTPUT_LEVEL=3
    # CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS=y
    # CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS_NETWORK=y
    # CONFIG_NRF_CLOUD_SEND_DEVICE_STATUS_SIM=y
    
    # -------------------------------------------------------------------------------------------
    CONFIG_NET_TCP=y
    
    CONFIG_NRF_CLOUD_IPV6=y
    CONFIG_NRF_CLOUD_HOST_NAME="fd12:6809:36e5:2:0:0:36a0:7d6a"
    CONFIG_NRF_CLOUD_PROVISION_CERTIFICATES=y
    CONFIG_NRF_CLOUD_CLIENT_ID_SRC_COMPILE_TIME=y
    CONFIG_NRF_CLOUD_CLIENT_ID="device001"
    
    CONFIG_NET_L2_OPENTHREAD=y
    CONFIG_OPENTHREAD_SLAAC=y
    CONFIG_OPENTHREAD_MTD=y
    CONFIG_OPENTHREAD_TCP_ENABLE=n
    
    CONFIG_OPENTHREAD_MANUAL_START=n
    CONFIG_OPENTHREAD_PANID=4660
    CONFIG_OPENTHREAD_XPANID="ce:35:44:d8:1b:fd:9d:8c"
    CONFIG_OPENTHREAD_NETWORK_NAME="HOORII_AUTOTEST"
    CONFIG_OPENTHREAD_NETWORKKEY="80:12:3a:45:56:56:0a:ae:50:77:ab:d2:dd:61:b6:61"
    CONFIG_OPENTHREAD_CHANNEL=26
    
    # CONFIG_NET_SHELL=y
    # CONFIG_OPENTHREAD_SHELL=y
    
    CONFIG_NET_LOG=y
    # CONFIG_NET_CONTEXT_LOG_LEVEL_DBG=y
    # CONFIG_MQTT_LOG_LEVEL_DBG=y
    # CONFIG_NET_SOCKETS_LOG_LEVEL_DBG=y
    # CONFIG_NET_TCP_LOG_LEVEL_DBG=y
    # CONFIG_AWS_IOT_LOG_LEVEL_DBG=y
    
    CONFIG_MBEDTLS_DEBUG=y
    CONFIG_MBEDTLS_LOG_LEVEL_DBG=y
    CONFIG_OPENTHREAD_MBEDTLS_DEBUG=y
    
    # START NET
    
    #Socket settings
    
    CONFIG_NET_PKT_RX_COUNT=16
    CONFIG_NET_PKT_TX_COUNT=16
    CONFIG_NET_BUF_RX_COUNT=100
    CONFIG_NET_BUF_TX_COUNT=100
    
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    CONFIG_NET_SOCKETS_POLL_MAX=10
    
    CONFIG_NET_CONTEXT_RCVTIMEO=y
    CONFIG_NET_CONTEXT_SNDTIMEO=y
    
    CONFIG_NET_MAX_CONTEXTS=10
    
    CONFIG_NET_CONTEXT_NET_PKT_POOL=y
    
    CONFIG_NET_SOCKETS_OFFLOAD=n
    
    CONFIG_NET_RX_STACK_SIZE=4096
    
    CONFIG_NET_TCP_ISN_RFC6528=n
    
    # Credentials
    CONFIG_TLS_CREDENTIALS=y
    
    # MBEDTLS
    
    # FROM https://github.com/nrfconnect/sdk-nrf/blob/main/samples/net/http_server/overlay-tls-nrf91.conf
    
    CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
    CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=10
    
    # nRF Security legacy MBed TLS
    
    CONFIG_NORDIC_SECURITY_BACKEND=y
    
    CONFIG_POSIX_MAX_FDS=10
    CONFIG_MBEDTLS_ENABLE_HEAP=y
    CONFIG_MBEDTLS_HEAP_SIZE=64000
    CONFIG_MBEDTLS_RSA_C=y
    CONFIG_MBEDTLS_PSA_CRYPTO_C=y
    CONFIG_MBEDTLS=y
    CONFIG_MBEDTLS_TLS_LIBRARY=y
    CONFIG_MBEDTLS_SSL_SRV_C=y
    CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384
    CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=16384
    
    # Enable TLS protocol options
    CONFIG_NET_SOCKETS_TLS_SET_MAX_FRAGMENT_LENGTH=y
    CONFIG_MBEDTLS_SSL_SERVER_NAME_INDICATION=y
    
    # Enable AES
    CONFIG_MBEDTLS_AES_C=y
    CONFIG_MBEDTLS_CCM_C=y
    CONFIG_MBEDTLS_GCM_C=y
    CONFIG_MBEDTLS_CIPHER_MODE_CBC=y
    CONFIG_MBEDTLS_CIPHER_PADDING_PKCS7=y
    
    # Enable ECC
    CONFIG_MBEDTLS_ECP_C=y
    CONFIG_PSA_WANT_ECC_SECP_R1_256=y
    
    # Enable ECDSA
    CONFIG_MBEDTLS_ECDSA_C=y
    CONFIG_PSA_WANT_ALG_ECDSA=y
    CONFIG_MBEDTLS_ECDSA_DETERMINISTIC=y
    CONFIG_PSA_WANT_ALG_DETERMINISTIC_ECDSA=y
    CONFIG_PSA_WANT_ALG_HMAC=y # dependency for DETERMINISTIC_ECDSA
    CONFIG_PSA_WANT_KEY_TYPE_ECC_KEY_PAIR=y # dependency for DETERMINISTIC_ECDSA
    
    # Enable ECDH
    CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA_ENABLED=y
    CONFIG_MBEDTLS_ECDH_C=y
    CONFIG_PSA_WANT_ALG_ECDH=y
    
    # Enable EDCHE
    CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED=y
    CONFIG_MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED=y
    
    # Enable RSA
    CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED=y
    CONFIG_MBEDTLS_PKCS1_V15=y
    CONFIG_MBEDTLS_MPI_MAX_SIZE=512
    
    # Enable SHA
    CONFIG_MBEDTLS_SHA256_C=y
    CONFIG_MBEDTLS_SHA512_C=y
    
    # Disable MBEDTLS modules
    CONFIG_MBEDTLS_CTR_DRBG_C=n
    CONFIG_MBEDTLS_CHACHA20_C=n
    CONFIG_MBEDTLS_POLY1305_C=n
    CONFIG_MBEDTLS_DHM_C=n
    CONFIG_MBEDTLS_CMAC_C=n
    CONFIG_MBEDTLS_CIPHER_MODE_CTR=n
    CONFIG_MBEDTLS_CIPHER_MODE_CFB=n
    CONFIG_MBEDTLS_CIPHER_MODE_OFB=n
    CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_PSK_ENABLED=n
    CONFIG_MBEDTLS_KEY_EXCHANGE_DHE_RSA_ENABLED=n
    CONFIG_MBEDTLS_SHA1_C=n
    

    Note that the "nct.tls_config.hostname" parameter in "ncs\v2.5.2\nrf\subsys\net\lib\nrf_cloud\src\nrf_cloud_transport.c" file has also been changed to "iot.us-east-1.amazonaws.com".

    nrf_cloud_multi_service_devzone.zip

    Also, how should I decrypted a packet caught via wireshark, does this help to determine the reason for the connection disconnection and what information do I need to provide?

    Best regards,
    Yuchao

  • Hi, Jørgen


    Any progress to share? If there's anything I can do for you, please let me know


    Best regards,
    Yuchao

  • Hi,

    I'm checking internally if anyone have experience with the behavior you are experiencing, or if any working sample is available.

    Best regards,
    Jørgen

  • Hi, Jørgen


    Thank you for your feedback, and I hope you will find efficient help from the nrf cloud staff.

    Best regards,
    Yuchao

Related