AWS IoT Core Connection

Modem Firmware: mfw_nrf91x1_2.0.3

SDK Version: 3.1.1

nrf9151

Using the aws_iot sample as a reference, I'm trying to get my device to connect to an IoT instance that I've confirmed operational using mosquitto.  Turning on some of the debug I'm getting;

[00:00:41.125,183] <dbg> aws_iot: aws_iot_connect: No hostname provided, using Kconfig value: a1bl2ugg7axw2v-ats.iot.us-east-1.amazonaws.com
[00:00:41.125,427] <dbg> mqtt_helper: broker_init: Resolving IP address for a1bl2ugg7axw2v-ats.iot.us-east-1.amazonaws.com
[00:00:42.141,967] <dbg> mqtt_helper: broker_init: IPv4 Address found 18.211.66.210 (AF_INET)
[00:00:42.141,998] <dbg> mqtt_helper: client_connect: Using build-time provided security tag value from Kconfig
[00:00:42.142,059] <dbg> mqtt_helper: mqtt_state_set: State transition: MQTT_STATE_DISCONNECTED --> MQTT_STATE_TRANSPORT_CONNECTING
[00:00:46.932,403] <dbg> mqtt_helper: mqtt_state_set: State transition: MQTT_STATE_TRANSPORT_CONNECTING --> MQTT_STATE_TRANSPORT_CONNECTED
[00:00:46.932,464] <dbg> mqtt_helper: mqtt_state_set: State transition: MQTT_STATE_TRANSPORT_CONNECTED --> MQTT_STATE_CONNECTING
[00:00:46.932,495] <dbg> mqtt_helper: client_connect: Using send socket timeout of 60 seconds
[00:00:46.932,525] <dbg> mqtt_helper: mqtt_helper_connect: MQTT connection request sent
[00:00:46.932,922] <dbg> mqtt_helper: mqtt_helper_poll_loop: Took connection_poll_sem
[00:00:46.932,952] <dbg> mqtt_helper: mqtt_helper_poll_loop: Starting to poll on socket, fd: 3
[00:00:46.932,952] <dbg> mqtt_helper: mqtt_helper_poll_loop: Polling on socket fd: 3
[00:00:49.479,522] <dbg> mqtt_helper: mqtt_evt_handler: MQTT_EVT_DISCONNECT: result = -128
[00:00:49.479,583] <dbg> mqtt_helper: mqtt_state_set: State transition: MQTT_STATE_CONNECTING --> MQTT_STATE_DISCONNECTED
[00:00:49.479,614] <dbg> aws_iot: on_disconnect: MQTT client disconnected: result = -128
[00:00:49.479,644] <inf> aws: AWS_IOT_EVT_DISCONNECTED
[00:00:49.479,644] <inf> aws: AWS Disconnected
[00:00:49.479,675] <err> mqtt_helper: Cloud MQTT input error: -128

I'm trying to get modem tracing working but the snippet breaks under my static partition manager setup and changing it would require some redo of my nvs section.  so I'm a bit stuck on that at the moment.  I'm hoping this is a typical issue even though i haven't found the exact situation in a ticket search.  I'm sure it's a simple setup problem and I was hoping for some basic suggestions or perhaps some alternate means of setting up modem tracing.

Parents
  • One thing that's becoming painfully obvious is that I seem to be having no luck enabling 

    CONFIG_MBEDTLS_SSL_SERVER_NAME_INDICATION
    Is that a problem when trying to use the modem TLS stack?
  • Hello, 

    rtphilipson said:
    CONFIG_MBEDTLS_SSL_SERVER_NAME_INDICATION

    Yes, this is not needed in your application. 

    The nRF91 Series modem includes a dedicated certificate storage and integrated TLS/DTLS driver. The application can write (provision) certificates to slots in the modem and choose which slots the modem should use for TLS in communication. This offload the TLS to the modem.

    Using the aws_iot sample as a reference, I'm trying to get my device to connect to an IoT instance that I've confirmed operational using mosquitto.  Turning on some of the debug I'm getting;

    Have you followed the steps provided under AWS IoT library on Setup and Configuration? Did you test AWS IoT connection with only the AWS IoT sample?

    From nrfxlib\nrf_modem\include\nrf_errno.h we find that errno -128 means:

    #define NRF_ENOTCONN 128        /**< The socket is not connected */

    What device are you using, i.e. Thingy, DK, or custom HW? It would be good to have modem traces from the device to verify issues with e.g. credentials. Have you ensure that the device name is correct in the application and AWS IoT dashboard?

    Kind regards,
    Øyvind

  • It's a custom board using the nrf9151.  I built and programmed the aws_iot sample and got the same errors when trying to connect.  Attached is the trace file

    trace-2025-11-18T14-19-57.081Z.mtrace

    I was able to verify the keys, client_id and topic by using the following command;
    mosquitto_pub \
    --cafile ./AmazonRootCA1.pem \
    --cert ./228662373310838519760369278267439319841272507988.crt \
    --key ./228662373310838519760369278267439319841272507988.key \
    -h a1bl2ugg7axw2v-ats.iot.us-east-1.amazonaws.com \
    -p 8883 \
    -q 1 \
    -t "seal/228662373310838519760369278267439319841272507988/telemetry" \
    -f payload.json \
    -i "228662373310838519760369278267439319841272507988" \
    -d

    when I run openssl dgst on the keys, the has matches what I get when I list;
    %CMNG: 201,0,"56AE01E6773BDAEC4BFB216D4005ADB06E4F680BD8BFB8BE4C683CE921681897"
    %CMNG: 201,1,"A2069C8A79DF808599B9865F2D3E726E7651C4C1413068FDC98DC6219C5021EE"
    %CMNG: 201,2,"95A72A0750E9D783D773598B118C80F547E538F12128AC8D64DB9782C964BF8E"

    Now, I am putting keys in a little different than what is standard.  I didn't want a huge set of RX buffers and I didn't want to have to load AT Client as a separate step to get keys in.  So, I created command line operations that allowed me to chunk them in.  A consequence of this, is the credentials are written in with the carriage return\new line characters in place.  But I wouldn't think that should be a problem with the modem 




  • Discovered that 

    CONFIG_AWS_IOT_CLIENT_ID_MAX_LEN

    defaults to 40. Upped it to 64.  Still didn't help.

    But enabling MQTT Debug, it looks like it's successfully connecting but then loses the connection before the information gets back to the AWS IoT library before it acknowledges the connection;

    sojo> [00:01:00.954,711] <dbg> net_mqtt_sock_tls: mqtt_client_tls_connect: (sysworkq): Created socket 3
    sojo> sojo> [00:01:05.741,577] <dbg> net_mqtt_sock_tls: mqtt_client_tls_connect: (sysworkq): Connect completed
    sojo> [00:01:05.741,821] <dbg> net_mqtt_enc: connect_request_encode: Encoding Protocol Description.
    4d 51 54 54 |MQTT
    sojo> [00:01:05.741,851] <dbg> net_mqtt_enc: pack_utf8_str: (sysworkq): >> str_size:00000006 cur:0x2001a244, end:0x2001aa3f
    sojo> [00:01:05.741,882] <dbg> net_mqtt_enc: pack_uint16: (sysworkq): >> val:0004 cur:0x2001a244, end:0x2001aa3f
    sojo> [00:01:05.741,943] <dbg> net_mqtt_enc: connect_request_encode: (sysworkq): Encoding Protocol Version 04.
    sojo> [00:01:05.741,973] <dbg> net_mqtt_enc: pack_uint8: (sysworkq): >> val:04 cur:0x2001a24a, end:0x2001aa3f
    sojo> [00:01:05.742,004] <dbg> net_mqtt_enc: pack_uint8: (sysworkq): >> val:00 cur:0x2001a24b, end:0x2001aa3f
    sojo> [00:01:05.742,034] <dbg> net_mqtt_enc: connect_request_encode: (sysworkq): Encoding Keep Alive Time 04b0.
    sojo> [00:01:05.742,065] <dbg> net_mqtt_enc: pack_uint16: (sysworkq): >> val:04b0 cur:0x2001a24c, end:0x2001aa3f
    sojo> [00:01:05.742,095] <dbg> net_mqtt_enc: connect_request_encode: Encoding Client Id.
    32 32 38 36 36 32 33 37 33 33 31 30 38 33 38 35 |22866237 33108385
    31 39 37 36 30 33 36 39 32 37 38 32 36 37 34 33 |19760369 27826743
    39 33 31 39 38 34 31 32 37 32 35 30 37 39 38 38 |93198412 72507988
    sojo> [00:01:05.742,156] <dbg> net_mqtt_enc: pack_utf8_str: (sysworkq): >> str_size:00000032 cur:0x2001a24e, end:0x2001aa3f
    sojo> [00:01:05.742,187] <dbg> net_mqtt_enc: pack_uint16: (sysworkq): >> val:0030 cur:0x2001a24e, end:0x2001aa3f
    sojo> [00:01:05.742,218] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (sysworkq): << msg type:0x10 length:0x0000003c
    sojo> [00:01:05.742,279] <dbg> net_mqtt_enc: pack_variable_int: (sysworkq): >> value:0x0000003c cur:0, end:0
    sojo> [00:01:05.742,309] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (sysworkq): Fixed header length = 02
    sojo> [00:01:05.742,340] <dbg> net_mqtt_enc: pack_uint8: (sysworkq): >> val:10 cur:0x2001a242, end:0x2001aa3f
    sojo> [00:01:05.742,370] <dbg> net_mqtt_enc: pack_variable_int: (sysworkq): >> value:0x0000003c cur:0x2001a243, end:0x2001aa3f
    sojo> [00:01:05.743,682] <inf> net_mqtt: Connect completed
    sojo> sojo> sojo> [00:01:06.378,570] <dbg> net_mqtt: mqtt_input: (mqtt_helper_thread): state:0x00000002
    sojo> --- 1 messages dropped ---
    [00:01:06.378,662] <dbg> net_mqtt_dec: unpack_uint8: (mqtt_helper_thread): >> cur:0x2001aa3f, end:0x2001aa41
    sojo> --- 2 messages dropped ---
    [00:01:06.378,692] <dbg> net_mqtt_dec: unpack_uint8: (mqtt_helper_thread): << val:20
    sojo> [00:01:06.378,723] <dbg> net_mqtt_dec: unpack_variable_int: (mqtt_helper_thread): variable int:0x00000002
    sojo> [00:01:06.378,845] <dbg> net_mqtt_rx: mqtt_handle_packet: (mqtt_helper_thread): [CID 0x20017ffc]: Received MQTT_PKT_TYPE_CONNACK!
    sojo> [00:01:06.378,875] <dbg> net_mqtt_dec: unpack_uint8: (mqtt_helper_thread): >> cur:0x2001aa41, end:0x2001aa43
    sojo> [00:01:06.378,936] <dbg> net_mqtt_dec: unpack_uint8: (mqtt_helper_thread): << val:00
    sojo> [00:01:06.378,967] <dbg> net_mqtt_dec: unpack_uint8: (mqtt_helper_thread): >> cur:0x2001aa42, end:0x2001aa43
    sojo> [00:01:06.378,997] <dbg> net_mqtt_dec: unpack_uint8: (mqtt_helper_thread): << val:00
    sojo> [00:01:06.379,089] <dbg> net_mqtt_rx: mqtt_handle_packet: (mqtt_helper_thread): [CID 0x20017ffc]: return_code: 0
    sojo> [00:01:06.379,394] <dbg> net_mqtt_enc: pack_utf8_str: (mqtt_helper_thread): >> str_size:00000041 cur:0x2001a246, end:0x2001aa3f
    sojo> [00:01:06.379,455] <dbg> net_mqtt_enc: pack_uint16: (mqtt_helper_thread): >> val:003f cur:0x2001a246, end:0x2001aa3f
    sojo> [00:01:06.379,486] <dbg> net_mqtt_enc: pack_uint8: (mqtt_helper_thread): >> val:01 cur:0x2001a287, end:0x2001aa3f
    sojo> [00:01:06.379,516] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (mqtt_helper_thread): << msg type:0x82 length:0x00000044
    sojo> [00:01:06.379,577] <dbg> net_mqtt_enc: pack_variable_int: (mqtt_helper_thread): >> value:0x00000044 cur:0, end:0
    sojo> [00:01:06.379,608] <dbg> net_mqtt_enc: mqtt_encode_fixed_header: (mqtt_helper_thread): Fixed header length = 02
    sojo> [00:01:06.379,638] <dbg> net_mqtt_enc: pack_uint8: (mqtt_helper_thread): >> val:82 cur:0x2001a242, end:0x2001aa3f
    sojo> [00:01:06.379,669] <dbg> net_mqtt_enc: pack_variable_int: (mqtt_helper_thread): >> value:0x00000044 cur:0x2001a243, end:0x2001aa3f
    sojo> [00:01:06.379,699] <dbg> net_mqtt: client_write: (mqtt_helper_thread): [0x20017ffc]: Transport writing 70 bytes.
    sojo> [00:01:06.381,225] <dbg> net_mqtt: client_write: (mqtt_helper_thread): [0x20017ffc]: Transport write complete.
    sojo> [00:01:06.381,256] <dbg> net_mqtt: mqtt_subscribe: (mqtt_helper_thread): [CID 0x20017ffc]:[State 0x06]: << result 0x00000000
    sojo> [00:01:06.381,317] <dbg> net_mqtt: mqtt_subscribe: (mqtt_helper_thread): [CID 0x20017ffc]:[State 0x06]: >> message id 0x07c0 topic count 0x0003
    sojo> [00:01:06.381,561] <dbg> net_mqtt_enc: pack_uint16: (mqtt_helper_thread): >> val:07c0 cur:0x2001a244, end:0x2001aa3f
    sojo> [00:01:06.381,591] <dbg> net_mqtt_enc: pack_utf8_str: (mqtt_helper_thread): >> str_size:00000052 cur:0x2001a246, end:0x2001aa3f
    sojo> [00:01:06.381,622] <dbg> net_mqtt_enc: pack_uint16: (mqtt_helper_thread): >> val:0050 cur:0x2001a246, end:0x2001aa3f
    sojo> [00:01:06.381,683] <dbg> net_mqtt_enc: pack_uint8: (mqtt_helper_thread): >> val:01 cur:0x2001a298, end:0x2001aa3f
    sojo> [00:01:06.381,713] <dbg> net_mqtt_enc: pack_utf8_str: (mqtt_helper_thread): >> str_size:00000052 cur:0x2001a299, end:0x2001aa3f
    sojo> [00:01:06.381,744] <dbg> net_mqtt_enc: pack_uint16: (mqtt_helper_thread): >> val:0050 cur:0x2001a299, end:0x2001aa3f
    sojo> [00:01:06.381,805] <dbg> net_mqtt_encm[00:01:08.926,757] <dbg> net_mqtt: mqtt_input: (mqtt_helper_thread): state:0x00000006
    sojo> [00:01:08.926,818] <err> net_mqtt_rx: [CID 0x20017ffc]: Connection closed.
    sojo> [00:01:08.926,818] <inf> net_mqtt_sock_tls: Closing socket 3
    sojo> [00:01:08.927,642] <inf> aws: AWS_IOT_EVT_DISCONNECTED

  • OK, it appears to be the CLIENT_ID_MAX_LEN, some instability with the IoT setup by cloud team and them not opening up the shadow topics.  So I simply disabled them in the code.  I appear to be connecting and communicating now.

    Thank you for your assistance.

Reply Children
Related