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.

CC3220S-LAUNCHXL: AWS IOT SDK - Broken

Part Number: CC3220S-LAUNCHXL
Other Parts Discussed in Thread: CC3220S, UNIFLASH

I have been playing around with the "subscribe_publish_sample_CC3220S_LAUNCHXL_tirtos_gcc" example from the AWS IOT SDK example and I am fairly confident this code does not work.

I keep getting  the following error:

/** A Generic write error based on the platform used */
NETWORK_SSL_WRITE_ERROR = -7,

Clearly there is a problem with the TLS connection, I have verified that my certificates, url, port and all other settings work using another program:  MQTT-SPY

Using MQTT-SPY I have verified everything is set-up correctly in AWS and I am using all the correct values in code.

I have also tried uploading cert files directly using Uniflash, because I was worried maybe it was not flashing correctly in the program, but that is not the problem.

I have also searched the forums and have seen others have problems with no resolution, any help would be much appreciated.

Thanks,

Adam

  • Console output with trace IOT_TRACE and IOT_DEBUG enabled:


    Starting the AWS IoT example application

    startSNTP: Current time: Mon Jan 21 18:09:27 2019


    CC32XX has connected to AP and acquired an IP address.

    IP Address: 10.0.0.74


    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 : 44

    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#318 Return Code : -7

    FUNC_EXIT: _aws_iot_mqtt_internal_connect L#420 Return Code : -7

    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 : -7

    ERROR: runAWSClient L#108
    Error(-7) connecting to xxxxxxxxxxxxxx-xxx.iot.us-east-1.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
  • Hi Adam,

    Which version of the AWS plugin and the SimpleLink SDK are you using?

    Thanks,
    Gerardo
  • Hi Gerado,

    SimpleLink: I tried using both CC32xx SDK 2.30.00.05 and 2.40.00.05.
    AWS: SimpleLink CC32XX SDK AWS IoT Plugin 2.10.00.04

    Any help would be much appreciated.

    Thanks,
    Adam
  • Hi Adam,

    Can you update your application with the attached network_sl? This has additional trace statements added so I'll need you to post the new output that results from running this.

    Thanks,
    Gerardo

    /*
     * Copyright 2015-2018 Texas Instruments Incorporated. All Rights Reserved.
     *
     * Licensed under the Apache License, Version 2.0 (the "License").
     * You may not use this file except in compliance with the License.
     * A copy of the License is located at
     *
     *  http://aws.amazon.com/apache2.0
     *
     * or in the "license" file accompanying this file. This file is distributed
     * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     * express or implied. See the License for the specific language governing
     * permissions and limitations under the License.
     */
    
    #include <stdlib.h>
    #include <string.h>
    
    #include <arpa/inet.h>
    #include <netdb.h>
    #include <netinet/in.h>
    #include <sys/socket.h>
    /*
     * TODO: Get definition of struct timeval from sys/select.h (workaround for
     * NS-93)
     */
    #include <sys/select.h>
    
    #include <errno.h>
    
    #include <ti/net/slnetsock.h>
    #include <ti/net/slnetif.h>
    
    #include <network_interface.h>
    #include <aws_iot_error.h>
    #include <aws_iot_log.h>
    
    extern void checkIfFileExists(uint8_t *certName);
    
    extern uint32_t NetWiFi_isConnected(void);
    
    static void iot_tls_set_connect_params(Network *pNetwork, char *pRootCALocation,
            char *pDeviceCertLocation, char *pDevicePrivateKeyLocation,
            char *pDestinationURL, uint16_t DestinationPort, uint32_t timeout_ms,
            bool ServerVerificationFlag) {
    
        pNetwork->tlsConnectParams.DestinationPort = DestinationPort;
        pNetwork->tlsConnectParams.pDestinationURL = pDestinationURL;
        pNetwork->tlsConnectParams.pDeviceCertLocation = pDeviceCertLocation;
        pNetwork->tlsConnectParams.pDevicePrivateKeyLocation =
                pDevicePrivateKeyLocation;
        pNetwork->tlsConnectParams.pRootCALocation = pRootCALocation;
        pNetwork->tlsConnectParams.timeout_ms = timeout_ms;
        pNetwork->tlsConnectParams.ServerVerificationFlag = ServerVerificationFlag;
    }
    
    IoT_Error_t iot_tls_init(Network *pNetwork, char *pRootCALocation,
            char *pDeviceCertLocation, char *pDevicePrivateKeyLocation,
            char *pDestinationURL, uint16_t DestinationPort, uint32_t timeout_ms,
            bool ServerVerificationFlag)
    {
        if (pNetwork == NULL) {
            return (NULL_VALUE_ERROR);
        }
    
        iot_tls_set_connect_params(pNetwork, pRootCALocation, pDeviceCertLocation,
                pDevicePrivateKeyLocation, pDestinationURL, DestinationPort,
                timeout_ms, ServerVerificationFlag);
    
        pNetwork->connect = iot_tls_connect;
        pNetwork->read = iot_tls_read;
        pNetwork->write = iot_tls_write;
        pNetwork->disconnect = iot_tls_disconnect;
        pNetwork->isConnected = iot_tls_is_connected;
        pNetwork->destroy = iot_tls_destroy;
    
        pNetwork->tlsDataParams.ifId = 0; /* init to invalid interface ID */
        pNetwork->tlsDataParams.skt = -1; /* INVALID socket */
        pNetwork->tlsDataParams.secAttrib = NULL;
    
        return (SUCCESS);
    }
    
    IoT_Error_t iot_tls_connect(Network *pNetwork, TLSConnectParams *TLSParams)
    {
        IoT_Error_t ret = SUCCESS;
        int status = 0;
        uint32_t certStore;
        uint8_t  securityMethod;
        uint32_t securityCipher;
        struct addrinfo hints;
        struct addrinfo *results = NULL;
        struct addrinfo *currAddr = NULL;
        char portStr[6]; /* 6 chars needed to hold a short (max 5 digits) + '\0' */
        TLSConnectParams *tlsParams;
        TLSDataParams *tlsDataParams;
        uint16_t clientSd;
        socklen_t sdlen = sizeof(clientSd);
    
    	FUNC_ENTRY;
        if (pNetwork == NULL) {
           // return (NULL_VALUE_ERROR);
    	    FUNC_EXIT_RC(NULL_VALUE_ERROR);
        }
    
        if (TLSParams != NULL) {
            iot_tls_set_connect_params(pNetwork, TLSParams->pRootCALocation,
                    TLSParams->pDeviceCertLocation,
                    TLSParams->pDevicePrivateKeyLocation,
                    TLSParams->pDestinationURL, TLSParams->DestinationPort,
                    TLSParams->timeout_ms, TLSParams->ServerVerificationFlag);
        }
    
        /* Use TLS params in Network struct */
        tlsParams = &pNetwork->tlsConnectParams;
        tlsDataParams = &pNetwork->tlsDataParams;
    
        /* Convert the AWS server's port number to a string */
        status = sprintf(portStr, "%d", tlsParams->DestinationPort);
        if (status < 0) {
            ret = FAILURE;
            goto QUIT;
        }
    
        /*
         * Perform host name look up on the AWS server name.
         * We need to connect using TCP over either IPv4 or IPv6
         */
        memset(&hints, 0, sizeof(hints));
        hints.ai_family = AF_UNSPEC;
        hints.ai_socktype = SOCK_STREAM;
        hints.ai_protocol = IPPROTO_TCP;
    
        status = getaddrinfo(tlsParams->pDestinationURL, portStr, &hints, &results);
        if (status != 0) {
            ret = NETWORK_ERR_NET_UNKNOWN_HOST;
            goto QUIT;
        }
    
        /* Cycle over results, use the first socket that connects successfully */
        for (currAddr = results; currAddr != NULL; currAddr = currAddr->ai_next) {
            tlsDataParams->skt = socket(currAddr->ai_family, currAddr->ai_socktype,
                    currAddr->ai_protocol);
            if (tlsDataParams->skt < 0) {
                /* socket failed; try again with the next result */
                ret = NETWORK_ERR_NET_SOCKET_FAILED;
                continue;
            }
    
            status = connect(tlsDataParams->skt, currAddr->ai_addr,
                    currAddr->ai_addrlen);
            if (status < 0) {
                /* connect failed for this address, try the next one */
                close(tlsDataParams->skt);
                tlsDataParams->skt = -1;
                ret = NETWORK_ERR_NET_CONNECT_FAILED;
            }
            else {
                /* connect succeeded, we're done */
                ret = SUCCESS;
                break;
            }
        }
    
        /* If we couldn't create and/or connect a socket, quit with failure */
        if (ret != SUCCESS) {
            goto QUIT;
        }
    
        if (getsockopt(tlsDataParams->skt, SLNETSOCK_LVL_SOCKET,
                SLNETSOCK_OPSOCK_SLNETSOCKSD, &clientSd, &sdlen) < 0) {
            ret = TCP_SETUP_ERROR;
            goto QUIT;
        }
    
        /* Get and save the associated interface ID for this socket */
        tlsDataParams->ifId = SlNetSock_getIfID(tlsDataParams->skt);
        if (tlsDataParams->ifId <= 0) {
            ret = TCP_SETUP_ERROR;
            goto QUIT;
        }
    
        tlsDataParams->secAttrib = SlNetSock_secAttribCreate();
        if (!(tlsDataParams->secAttrib)) {
            ret = NETWORK_SSL_INIT_ERROR;
            goto QUIT;
        }
    
        /* Set the root CA certificate */
        status = SlNetSock_secAttribSet(tlsDataParams->secAttrib,
                SLNETSOCK_SEC_ATTRIB_PEER_ROOT_CA,
                tlsParams->pRootCALocation,
                strlen(tlsParams->pRootCALocation));
    
        /* Set this device's private key */
        status |= SlNetSock_secAttribSet(tlsDataParams->secAttrib,
                SLNETSOCK_SEC_ATTRIB_PRIVATE_KEY,
                tlsParams->pDevicePrivateKeyLocation,
                strlen(tlsParams->pDevicePrivateKeyLocation));
    
        /* Set this device's certificate */
        status |= SlNetSock_secAttribSet(tlsDataParams->secAttrib,
                SLNETSOCK_SEC_ATTRIB_LOCAL_CERT,
                tlsParams->pDeviceCertLocation,
                strlen(tlsParams->pDeviceCertLocation));
    
        /* Disable the cert store */
        certStore = 1;
        status |= SlNetSock_secAttribSet(tlsDataParams->secAttrib,
               SLNETSOCK_SEC_ATTRIB_DISABLE_CERT_STORE, (void *)&certStore,
               sizeof(certStore));
    
        securityMethod = SLNETSOCK_SEC_METHOD_SSLv3_TLSV1_2;
        status |= SlNetSock_secAttribSet(tlsDataParams->secAttrib,
               SLNETSOCK_SEC_ATTRIB_METHOD, (void *)&(securityMethod),
               sizeof(securityMethod));
    
        securityCipher = SLNETSOCK_SEC_CIPHER_FULL_LIST;
        status |= SlNetSock_secAttribSet(tlsDataParams->secAttrib,
                SLNETSOCK_SEC_ATTRIB_CIPHERS, (void *)&(securityCipher),
                sizeof(securityCipher));
    
        /* Consolidate error checking for SlNetSock_secAttribSet calls here: */
        if (status < 0) {
            ret = NETWORK_SSL_INIT_ERROR;
            goto QUIT;
        }
    
        /* Bind the TLS context */
        status = SlNetSock_startSec(clientSd, tlsDataParams->secAttrib,
               SLNETSOCK_SEC_BIND_CONTEXT_ONLY);
    
        if (status < 0) {
            ret = NETWORK_SSL_INIT_ERROR;
            goto QUIT;
        }
    
        /* Start the TLS handshake */
        status = SlNetSock_startSec(clientSd, NULL,
               SLNETSOCK_SEC_START_SECURITY_SESSION_ONLY);
        if (status < 0) {
            switch (status) {
                /* Problem with root CA cert */
                case SLNETERR_ESEC_BAD_CA_FILE:
                    ret = NETWORK_X509_ROOT_CRT_PARSE_ERROR;
                    break;
    
                /* Problem with device cert */
                case SLNETERR_ESEC_BAD_CERTIFICATE:
                case SLNETERR_ESEC_BAD_CERT_FILE:
                    ret = NETWORK_X509_DEVICE_CRT_PARSE_ERROR;
                    break;
    
                /* Problem with private key */
                case SLNETERR_ESEC_BAD_PRIVATE_FILE:
                    ret = NETWORK_PK_PRIVATE_KEY_PARSE_ERROR;
                    break;
    
                /* SSL Handshake time out */
                case SLNETERR_ESEC_HAND_SHAKE_TIMED_OUT:
                    ret = NETWORK_SSL_CONNECT_TIMEOUT_ERROR;
                    break;
    
                default :
                    ret = SSL_CONNECTION_ERROR;
                    break;
            }
        }
    
    /*
     * Clean up and return
     */
    QUIT:
    
        if (results) {
            freeaddrinfo(results);
        }
    
        if (ret != SUCCESS) {
            if (tlsDataParams->secAttrib) {
                SlNetSock_secAttribDelete(tlsDataParams->secAttrib);
                tlsDataParams->secAttrib = NULL;
            }
    
            if (tlsDataParams->skt >= 0) {
                close(tlsDataParams->skt);
                tlsDataParams->skt = -1;
            }
        }
    
        // return (ret);
    	FUNC_EXIT_RC(ret);
    }
    
    IoT_Error_t iot_tls_is_connected(Network *pNetwork)
    {
        int32_t status;
        IoT_Error_t ret;
    
        status = SlNetIf_getConnectionStatus(pNetwork->tlsDataParams.ifId);
    
        if (status == SLNETIF_STATUS_CONNECTED) {
            ret = NETWORK_PHYSICAL_LAYER_CONNECTED;
        }
        else {
            /*
             * Although SlNetIf_getConnectionStatus() has more possible failure
             * codes, the AWS framework code only checks for success (i.e.
             * "connnected") when this function is called. Therefore, return
             * "disconnected" here generically:
             */
            ret = NETWORK_PHYSICAL_LAYER_DISCONNECTED;
        }
    
        return (ret);
    }
    
    IoT_Error_t iot_tls_write(Network *pNetwork, unsigned char *pMsg, size_t len,
                Timer *timer, size_t *numbytes)
    {
        int bytes = 0;
    
    	FUNC_ENTRY;
    
        if (pNetwork == NULL || pMsg == NULL ||
                pNetwork->tlsDataParams.skt == -1 || numbytes == NULL) {
            // return (NULL_VALUE_ERROR);
    	    FUNC_EXIT_RC(NULL_VALUE_ERROR);
        }
    
        bytes = send(pNetwork->tlsDataParams.skt, pMsg, len, 0);
        if (bytes > 0) {
            *numbytes = (size_t)bytes;
    	    FUNC_EXIT_RC(SUCCESS);
        }
        else {
            IOT_INFO("iot_tls_write: send failed (bytes = %d, errno = %d)\n", bytes, errno);
        }
    
        // return (NETWORK_SSL_WRITE_ERROR);
    	FUNC_EXIT_RC(NETWORK_SSL_WRITE_ERROR);
    }
    
    IoT_Error_t iot_tls_read(Network *pNetwork, unsigned char *pMsg, size_t len,
            Timer *timer, size_t *numbytes)
    {
        int bytesLeft;
        int bytesRcvd = 0;
        int totalBytes = 0;
        int skt;
        struct timeval tv;
        uint32_t timeout;
    
    	FUNC_ENTRY;
        if (pNetwork == NULL || pMsg == NULL ||
                pNetwork->tlsDataParams.skt == -1 || timer == NULL ||
                numbytes == NULL) {
            // return (NULL_VALUE_ERROR);
    	    FUNC_EXIT_RC(NULL_VALUE_ERROR);
        }
    
        timeout = left_ms(timer);
        if (timeout == 0) {
            /* sock timeout of 0 == block forever; just read + return if expired */
            timeout = 1;
        }
    
        IOT_INFO("iot_tls_read: socket timeout set to %d ms\n", timeout);
    
        tv.tv_sec = 0;
        tv.tv_usec = timeout * 1000;
    
        skt = pNetwork->tlsDataParams.skt;
    
        if (setsockopt(skt, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,
                sizeof(struct timeval)) == 0) {
    
            /* Receive all bytes requested */
            bytesLeft = len;
            while (bytesLeft > 0) {
                IOT_INFO("iot_tls_read: calling recv() (%d bytes)\n", bytesLeft);
    
                bytesRcvd = recv(skt, pMsg, bytesLeft, 0);
    
                IOT_INFO("iot_tls_read: recv() returned %d\n", bytesRcvd);
                if (bytesRcvd > 0) {
                    bytesLeft -= bytesRcvd;
                    totalBytes += bytesRcvd;
                    pMsg += bytesRcvd;
                }
                else {
                    IOT_INFO("iot_tls_read: recv() returned 0 or error \n");
                    /* recv() returned 0 or error */
                    break;
                }
            }
            /* Report back what was received, even if an error occurred. */
            *numbytes = (size_t)totalBytes;
            if (totalBytes == len) {
                /* All requested bytes received, success */
                // return (SUCCESS);
    	        FUNC_EXIT_RC(SUCCESS);
            }
            else if ((bytesRcvd == -1) && (errno == EAGAIN)) {
                /* nothing to read in the socket buffer */
                // return (NETWORK_SSL_NOTHING_TO_READ);
    	        FUNC_EXIT_RC(NETWORK_SSL_NOTHING_TO_READ);
            }
            /* else recv() failed or returned 0, fall through */
        }
        // return (NETWORK_SSL_READ_ERROR);
    	FUNC_EXIT_RC(NETWORK_SSL_READ_ERROR);
    }
    
    IoT_Error_t iot_tls_disconnect(Network *pNetwork)
    {
        /*
         * SlNetSock has no disconnect equivalent. AWS framework code always
         * calls disconnect()/destroy() back to back so OK to have this empty.
         */
        return (SUCCESS);
    }
    
    IoT_Error_t iot_tls_destroy(Network *pNetwork)
    {
        if (pNetwork == NULL) {
            return (NULL_VALUE_ERROR);
        }
    
        if (pNetwork->tlsDataParams.skt >= 0) {
            close(pNetwork->tlsDataParams.skt);
            pNetwork->tlsDataParams.skt = -1;
        }
    
        if (pNetwork->tlsDataParams.secAttrib) {
            SlNetSock_secAttribDelete(pNetwork->tlsDataParams.secAttrib);
            pNetwork->tlsDataParams.secAttrib = NULL;
        }
    
        return (SUCCESS);
    }
    

  • Hey Gerado - below is the output now:

    Starting the AWS IoT example application

    startSNTP: Current time: Tue Jan 22 18:13:17 2019


    CC32XX has connected to AP and acquired an IP address.

    IP Address: 10.0.0.74

    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: iot_tls_connect L#100

    FUNC_EXIT: iot_tls_connect L#292 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 : 44

    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_ENTRY: iot_tls_write L#323

    FUNC_EXIT: iot_tls_write L#334 Return Code : 0

    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_ENTRY: iot_tls_read L#354

    iot_tls_read: socket timeout set to 19924 ms

    iot_tls_read: calling recv() (1 bytes)

    iot_tls_read: recv() returned 0

    iot_tls_read: recv() returned 0 or error

    FUNC_EXIT: iot_tls_read L#412 Return Code : -12

    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-ats.iot.us-east-1.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

  • Hi Adam,

    Can you look at the thread below, I think this is the same issue you are facing. 
    https://e2e.ti.com/support/wireless-connectivity/wifi/f/968/t/759250

    Thanks,
    Gerardo

  • Hey Gerardo,

    I was able to make it work after looking through that post, and documenting below for others.

    But with that being said, the reason it works with the non "ats" url and legacy cert is that I imagine the SDK is using a older version of the SDK for AWS IOT and needs to be updated, as it causes much ocnfusion

    Here is what fixed it issues for reference for others:

    #define AWS_IOT_MQTT_HOST              "a14txyocysgy7g-ats.iot.us-east-1.amazonaws.com" ///  <---- does not work

    #define AWS_IOT_MQTT_HOST              "a14txyocysgy7g.iot.us-east-1.amazonaws.com" ///        <----works, remove ats from url

    Use RSA 2048 bit key: VeriSign Class 3 Public Primary G5 root CA certificate

    here: https://www.symantec.com/content/en/us/enterprise/verisign/roots/VeriSign-Class%203-Public-Primary-Certification-Authority-G5.pem

    Should be formatted as follows:

    unsigned char root_ca_pem[] =
    "-----BEGIN CERTIFICATE-----\r\n"
    "MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB\r\n"
    "yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL\r\n"
    "ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp\r\n"
    "U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW\r\n"
    "ZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0\r\n"
    "aG9yaXR5IC0gRzUwHhcNMDYxMTA4MDAwMDAwWhcNMzYwNzE2MjM1OTU5WjCByjEL\r\n"
    "MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZW\r\n"
    "ZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2ln\r\n"
    "biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJp\r\n"
    "U2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0aG9y\r\n"
    "aXR5IC0gRzUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCvJAgIKXo1\r\n"
    "nmAMqudLO07cfLw8RRy7K+D+KQL5VwijZIUVJ/XxrcgxiV0i6CqqpkKzj/i5Vbex\r\n"
    "t0uz/o9+B1fs70PbZmIVYc9gDaTY3vjgw2IIPVQT60nKWVSFJuUrjxuf6/WhkcIz\r\n"
    "SdhDY2pSS9KP6HBRTdGJaXvHcPaz3BJ023tdS1bTlr8Vd6Gw9KIl8q8ckmcY5fQG\r\n"
    "BO+QueQA5N06tRn/Arr0PO7gi+s3i+z016zy9vA9r911kTMZHRxAy3QkGSGT2RT+\r\n"
    "rCpSx4/VBEnkjWNHiDxpg8v+R70rfk/Fla4OndTRQ8Bnc+MUCH7lP59zuDMKz10/\r\n"
    "NIeWiu5T6CUVAgMBAAGjgbIwga8wDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8E\r\n"
    "BAMCAQYwbQYIKwYBBQUHAQwEYTBfoV2gWzBZMFcwVRYJaW1hZ2UvZ2lmMCEwHzAH\r\n"
    "BgUrDgMCGgQUj+XTGoasjY5rw8+AatRIGCx7GS4wJRYjaHR0cDovL2xvZ28udmVy\r\n"
    "aXNpZ24uY29tL3ZzbG9nby5naWYwHQYDVR0OBBYEFH/TZafC3ey78DAJ80M5+gKv\r\n"
    "MzEzMA0GCSqGSIb3DQEBBQUAA4IBAQCTJEowX2LP2BqYLz3q3JktvXf2pXkiOOzE\r\n"
    "p6B4Eq1iDkVwZMXnl2YtmAl+X6/WzChl8gGqCBpH3vn5fJJaCGkgDdk+bW48DW7Y\r\n"
    "5gaRQBi5+MHt39tBquCWIMnNZBU4gcmU7qKEKQsTb47bDN0lAtukixlE0kF6BWlK\r\n"
    "WE9gyn6CagsCqiUXObXbf+eEZSqVir2G3l6BFoMtEMze/aiCKm0oHw0LxOXnGiYZ\r\n"
    "4fQRbxC1lfznQgUy286dUV4otp6F01vvpX1FQHKOtw5rDgb7MzVIcbidJ4vEZV8N\r\n"
    "hnacRHr2lVz2XTIIM6RUthg/aFzyQkqFOFSDX9HoLPKsEdao7WNq\r\n"
    "-----END CERTIFICATE-----\r\n";