This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220: AWS IoT SDK Plugin - Error #-12 (NETWORK_SSL_READ_ERROR)

Part Number: CC3220


Hi There,

I am trying to connect CC3220S Launchpad board to AWS IoT.

I have followed instruction from the following threads.

But, I do not have success connecting the board to AWS.

Following is the detailed log with ENABLE_IOT_TRACE macro.

startSNTP: Current time: Wed Oct 10 00:12:02 2018


CC32XX has connected to AP and acquired an IP address.

IP Address: 10.160.3.35

Flashing certificate file ...
Successfully wrote file /cert/ca.pem to flash

Flashing certificate file ...
Successfully wrote file /cert/cert.pem to flash

Flashing certificate file ...
Successfully wrote file /cert/key.pem to flash


AWS IoT SDK Version 3.0.1-

FUNC_ENTRY: aws_iot_mqtt_init L#210

FUNC_ENTRY: aws_iot_mqtt_set_connect_params L#139

FUNC_EXIT: aws_iot_mqtt_set_connect_params L#169 Return Code : 0

FUNC_EXIT: aws_iot_mqtt_init L#281 Return Code : 0

Connecting...


FUNC_ENTRY: aws_iot_mqtt_connect L#461

FUNC_ENTRY: aws_iot_mqtt_get_client_state L#63

FUNC_EXIT: aws_iot_mqtt_get_client_state L#68 Return Code : 1

FUNC_ENTRY: aws_iot_mqtt_set_client_state L#110

FUNC_ENTRY: aws_iot_mqtt_get_client_state L#63

FUNC_EXIT: aws_iot_mqtt_get_client_state L#68 Return Code : 1

FUNC_EXIT: aws_iot_mqtt_set_client_state L#135 Return Code : 0

FUNC_ENTRY: _aws_iot_mqtt_internal_connect L#391

FUNC_ENTRY: aws_iot_mqtt_set_connect_params L#139

FUNC_EXIT: aws_iot_mqtt_set_connect_params L#169 Return Code : 0

FUNC_ENTRY: _aws_iot_mqtt_serialize_connect L#161

FUNC_ENTRY: _aws_iot_get_connect_packet_length L#124

FUNC_EXIT: _aws_iot_get_connect_packet_length L#141 Return Code : 52

FUNC_ENTRY: aws_iot_mqtt_internal_init_header L#188

FUNC_EXIT: aws_iot_mqtt_internal_init_header L#264 Return Code : 0

FUNC_ENTRY: aws_iot_mqtt_internal_write_len_to_buffer L#59

FUNC_EXIT: aws_iot_mqtt_internal_write_len_to_buffer L#70 Return Code : 1

FUNC_EXIT: _aws_iot_mqtt_serialize_connect L#245 Return Code : 0

FUNC_ENTRY: aws_iot_mqtt_internal_send_packet L#272

FUNC_EXIT: aws_iot_mqtt_internal_send_packet L#315 Return Code : 0

FUNC_ENTRY: aws_iot_mqtt_internal_wait_for_read L#657

FUNC_EXIT: aws_iot_mqtt_internal_wait_for_read L#674 Return Code : -12

FUNC_EXIT: _aws_iot_mqtt_internal_connect L#426 Return Code : -12

FUNC_ENTRY: aws_iot_mqtt_set_client_state L#110

FUNC_ENTRY: aws_iot_mqtt_get_client_state L#63

FUNC_EXIT: aws_iot_mqtt_get_client_state L#68 Return Code : 2

FUNC_EXIT: aws_iot_mqtt_set_client_state L#135 Return Code : 0

FUNC_EXIT: aws_iot_mqtt_connect L#490 Return Code : -12

ERROR: runAWSClient L#108
Error(-12) connecting to xxxxxxxxxxx.iot.us-west-2.amazonaws.com:8883


FUNC_ENTRY: aws_iot_mqtt_autoreconnect_set_status L#337

FUNC_EXIT: aws_iot_mqtt_autoreconnect_set_status L#342 Return Code : 0

Subscribing...


FUNC_ENTRY: aws_iot_mqtt_subscribe L#301

FUNC_ENTRY: aws_iot_mqtt_is_client_connected L#292

FUNC_EXIT: aws_iot_mqtt_is_client_connected L#323 Return Code : 0

FUNC_EXIT: aws_iot_mqtt_subscribe L#308 Return Code : -13

ERROR: runAWSClient L#126
Error subscribing (-13)


ERROR: runAWSClient L#178
An error occurred in the loop. Error code = -13

I have also updated service pack of the launchpad.

Based on the error, it looks like there is an error while writing/reading to the socket.

Please provide support to solve the issue.

  • Hi Jay,

    Which version of the AWS plugin and SimpleLink SDK are you using? Make sure you have updated your device with the service pack for CC3220 provided in your SDK. From the trace, it looks like the TLS handshake was successful, and the error (-12) occurs when reading from the socket subsequently. Could you set a breakpoint on line 366 in network_sl.c to see what is the return code of recv()? It'd also be helpful to find out what errno is set to at that point (you can try adding IOT_DEBUG("errno=%d\n", errno); to print it out). That may give a hint as to why NETWORK_SSL_READ_ERROR was returned.

    In addition, it also doesn't hurt to double-check that your certificates in certs.h are typed in and formatted correctly (with '\r\n' at the end of each line), as that is a common mistake. To get the example to work, you should only need to fill out certs.h, modify wificonfig.h with your WIFI credentials, and update aws_iot_config.h with the correct AWS_IOT_MQTT_HOST and AWS_IOT_MY_THING_NAME.

    Best regards,
    Vincent

  • Jay,

    Can I mark this as closed?

    Todd
  • hi posting for Jay,

    1-AWS IOT plugin version :AWS IoT SDK Version 3.0.1-
    2- simple link SDK : simplelink_cc32xx_sdk_2_30_00_05
    3- service pack : sp_3.9.0.6_2.0.0.0_2.2.0.6.bin

    As you mentioned I put debug message and got errno=145 and recv() function is returning 0 bytesRcvd, and I also checked certificates , they are formatted correctly ,
    here is sample code

    while (bytesLeft > 0) {
    bytesRcvd = recv(skt, pMsg, bytesLeft, 0);
    IOT_DEBUG("errno=%d\n", errno);

    And I am also attaching detail log of application

    tartSNTP: Current time: Thu Oct 18 22:38:33 2018

    CC32XX has connected to AP and acquired an IP address.
    IP Address: 10.160.2.233
    Flashing certificate file ...
    Successfully wrote file /cert/ca.pem to flash
    Flashing certificate file ...
    Successfully wrote file /cert/cert.pem to flash
    Flashing certificate file ...
    Successfully wrote file /cert/key.pem to flash

    AWS IoT SDK Version 3.0.1-
    FUNC_ENTRY:   aws_iot_mqtt_init L#210
    FUNC_ENTRY:   aws_iot_mqtt_set_connect_params L#139
    FUNC_EXIT:   aws_iot_mqtt_set_connect_params L#169 Return Code : 0
    FUNC_EXIT:   aws_iot_mqtt_init L#281 Return Code : 0
    Connecting...

    FUNC_ENTRY:   aws_iot_mqtt_connect L#461
    FUNC_ENTRY:   aws_iot_mqtt_get_client_state L#63
    FUNC_EXIT:   aws_iot_mqtt_get_client_state L#68 Return Code : 1
    FUNC_ENTRY:   aws_iot_mqtt_set_client_state L#110
    FUNC_ENTRY:   aws_iot_mqtt_get_client_state L#63
    FUNC_EXIT:   aws_iot_mqtt_get_client_state L#68 Return Code : 1
    FUNC_EXIT:   aws_iot_mqtt_set_client_state L#135 Return Code : 0
    FUNC_ENTRY:   _aws_iot_mqtt_internal_connect L#391
    FUNC_ENTRY:   aws_iot_mqtt_set_connect_params L#139
    FUNC_EXIT:   aws_iot_mqtt_set_connect_params L#169 Return Code : 0
    FUNC_ENTRY:   _aws_iot_mqtt_serialize_connect L#161
    FUNC_ENTRY:   _aws_iot_get_connect_packet_length L#124
    FUNC_EXIT:   _aws_iot_get_connect_packet_length L#141 Return Code : 38
    FUNC_ENTRY:   aws_iot_mqtt_internal_init_header L#188
    FUNC_EXIT:   aws_iot_mqtt_internal_init_header L#264 Return Code : 0
    FUNC_ENTRY:   aws_iot_mqtt_internal_write_len_to_buffer L#59
    FUNC_EXIT:   aws_iot_mqtt_internal_write_len_to_buffer L#70 Return Code : 1
    FUNC_EXIT:   _aws_iot_mqtt_serialize_connect L#245 Return Code : 0
    FUNC_ENTRY:   aws_iot_mqtt_internal_send_packet L#272
       iot_tls_write L#324
    FUNC_EXIT:   aws_iot_mqtt_internal_send_packet L#315 Return Code : 0
    FUNC_ENTRY:   aws_iot_mqtt_internal_wait_for_read L#657
    DEBUG:   iot_tls_read L#367
    errno=145
    FUNC_EXIT:   aws_iot_mqtt_internal_wait_for_read L#674 Return Code : -12
    FUNC_EXIT:   _aws_iot_mqtt_internal_connect L#426 Return Code : -12
    FUNC_ENTRY:   aws_iot_mqtt_set_client_state L#110
    FUNC_ENTRY:   aws_iot_mqtt_get_client_state L#63
    FUNC_EXIT:   aws_iot_mqtt_get_client_state L#68 Return Code : 2
    FUNC_EXIT:   aws_iot_mqtt_set_client_state L#135 Return Code : 0
    FUNC_EXIT:   aws_iot_mqtt_connect L#490 Return Code : -12
    ERROR: runAWSClient L#108
    Error(-12) connecting to a1cf4lrifg61fv-ats.iot.us-west-2.amazonaws.com:8883

    FUNC_ENTRY:   aws_iot_mqtt_autoreconnect_set_status L#337
    FUNC_EXIT:   aws_iot_mqtt_autoreconnect_set_status L#342 Return Code : 0
    Subscribing...

    FUNC_ENTRY:   aws_iot_mqtt_subscribe L#301
    FUNC_ENTRY:   aws_iot_mqtt_is_client_connected L#292
    FUNC_EXIT:   aws_iot_mqtt_is_client_connected L#323 Return Code : 0
    FUNC_EXIT:   aws_iot_mqtt_subscribe L#308 Return Code : -13
    ERROR: runAWSClient L#126
    Error subscribing (-13)

    ERROR: runAWSClient L#178
    An error occurred in the loop. Error code = -13




    please let me know any other suggestion that I could try

    Best,
    Darshan

  • Hi Vincent,
    Thank you for suggestion.
    As Darshan mentioned in above post, it is still failing.
    Darshan and I both work on this task so in future you may see some updates from him as well.

    Please let us know how can we resolve this issue?

    Thanks,
    Jay
  • Hi Darshan and Jay,

    Did you get the plugin directly from https://git.ti.com/iotdev/aws-iot-device-sdk-embedded-c or did you download TI''s SimpleLink AWS IoT plugin? I was expecting a version string of this form for the TI plugin for AWS on CC32xx: aws_cc32xx_2_00_00_09, which would be the case if you used the TI plugin.

    recv() returning 0 means the server hung up in an orderly fashion. Incidentally, this post also reported an issue where recv() returned 0 (they were using an older stack and an older device, but the underlying cause could be the same): 

    Specifically, look at Steven Connell's response on Jan 25, 2017. Double-check the AWS policy for your thing on the portal and see if it helps.

    Best regards,

    Vincent

  • Hi Vincent,
    We have aws_cc32xx_2_00_00_09 version.
    And we got the source code using Code Composer Studio -> View -> Resource Explorer -> Software -> SimpleLink SDK Plugins -> SimpleLink CC32XX SDK AWS IoT Plugin - v:2.00.00.09 -> Examples -> Development Tools -> CC3200S-LAUNCHXL.

    Also, verified that the policy on AWS IoT is the same as Steven (from the suggested post).

    Following is the policy document:
    {
    "Version": "2012-10-17",
    "Statement": [
    {
    "Effect": "Allow",
    "Action": "iot:*",
    "Resource": "*"
    }
    ]
    }

  • Hi Jay,

    I have installed your versions of the TI AWS plugin and SimpleLink SDK, and was successful in connecting to AWS using the subscribe publish sample.

    How did you obtain your certificates? Did you obtain them from AWS according to the procedure in the Quick Start Guide's (C:/ti/aws_cc32xx_2_00_00_09/docs/aws/AWS_Quick_Start_Guide.html) AWS IoT Developer Setup section?

    The trace seems to indicate that the TLS handshake with AWS has successfully completed. Then _aws_iot_mqtt_serialize_connect() created a packet with the connection parameters in pConnectParams, and sent them via aws_iot_mqtt_internal_send_packet().  aws_iot_mqtt_internal_wait_for_read() is then called to wait for a reply, but AWS decided to disconnect instead of sending a reply packet. So my guess is that there is something in the connection parameters sent out that AWS did not like. I'd suggest you verify that the connection parameters (connectParams) set up in runAWSClient() make sense to you based on what has been set up on the portal. Start by trying a different AWS_IOT_MQTT_CLIENT_ID in aws_iot_config.h, since that seems to be one of the few things that are being transmitted. From the comments that string needs to be unique.

    On the portal side, verify that your certificate is active, and that the same certificate is listed under the policy you sent out.

    The AWS IoT forums may also be able to give you additional tips on what to look for.

    Best regards,

    Vincent

  • Hi Vincent,

    Thank you for confirming that.

    We went ahead and troubleshooted and found out that URL for MQTT HOST (AWS_IOT_MQTT_HOST) that we were getting from the AWS IoT portal is different than what we get from AWS CLI.

    From AWS IoT portal, under AWS IoT -> Settings, under custom endpoint, the value is a1cfxxxxxxx-ats.iot.us-west-2.amazonaws.com

    and when we got from AWS CLI using aws iot describe-endpoint command, the value is a1cfxxxxxxx.iot.us-west-2.amazonaws.com.

    If we use the endpoint retrieved from the portal, it gets error #-12 or #13.

    But, by using the value from AWS CLI, it works as expected.

    Again, thank you for your support.

    Thanks,

    Jay

  • Hi Jay,

    Glad to hear you were able to get to the bottom of it! And thank you for getting back to us - this is very valuable information for others who might run into the same issue.

    Best regards,

    Vincent