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.

CC3220SF-LAUNCHXL: Enabling ALPN extension for MQTT connection in AWS TI code

Part Number: CC3220SF-LAUNCHXL
Other Parts Discussed in Thread: CC3220SF

Even though I have read that TI is not supporting ALPN extension for MQTT connection, I have tried by adding the ALPN option as below for CC3220SF:

#define socketsAWS_IOT_ALPN_MQTT    "x-amzn-mqtt-ca"

const char * ppcALPNProtos[] = { socketsAWS_IOT_ALPN_MQTT };

sTIRetCode = sl_SetSockOpt( pxSocketContext->sSocketDescriptor, SL_SOL_SOCKET, SL_SO_SECURE_ALPN, ppcALPNProtos, sizeof( ppcALPNProtos ) );

This was done as read through some TI's documentation to enable ALPN socket option. So after doing this, I have come to know through debugging that this socket option gets set successfully and a socket connection is also successfully established. But the issue comes with MQTT connection which results in timeout waiting for CONNACK packet thereby resulting in failure.

So, Can I get a help in this process of establishing MQTT connection over 443 port and the necessary changes required in doing so.

Regards,

Kishore.

  • Hi Kishore,

    If you are using the text ALPN, you should use the SL_SO_SECURE_ALPN_GENERAL option.

    Br,

    Kobi

  • Hi Kobi,

    As suggested I have added this piece of code to try out

    #define SL_SO_SECURE_ALPN_GENERAL                             (44) /* set ALPN protocol name by string - only one protocol name can be set */

    sTIRetCode = sl_SetSockOpt( pxSocketContext->sSocketDescriptor, SL_SOL_SOCKET, SL_SO_SECURE_ALPN_GENERAL, "x-amzn-mqtt-ca", strlen( "x-amzn-mqtt-ca" ) );

    But sl_SetSockOpt returns -92 in this case which is "Protocol not available".

    Regards,

    Kishore.

  • Hi,

    What SDK and SP are you using.

    I've just tested the command (with your setting) and got successful return code.

    If i understand correctly, the error is when you set the option and not when you are connecting.

    Br,

    Kobi

  • Hi,

    I am using the demo code base downloaded from AWS for CC3220SF LAUNCHXL.

    Yes, the error code -92 is returned while setting the socket option and eventually it fails in making MQTT connection too.

    Regards,

    Kishore.

  • Hi Kobe,

    Hope you are doing well. It's been a long time since my last query. Can I have any update on this?

    Regards,

    Kishore.

  • Please show your entire socket handling code (from socket creation to getting the -92). As i said before, I added the SL_SO_SECURE_ALPN_GENERAL successfully, so need to understand the source of your issue.

    Are you using the latest SDK and SP? if not, please update.

    Br,

    Kobi

  • Hi,

    Sorry for a late follow up.

    I have added below piece of code in MQTT demo code downloaded from AWS  in the function SOCKETS_SetSocketOpt which is in the file iot_secure_sockets.c by changing clientcredentialMQTT_BROKER_PORT to 443 in aws_clientcredential.h. I have just added a case SOCKETS_SO_ALPN_PROTOCOLS which is previously not present in the code.

    #define socketsAWS_IOT_ALPN_MQTT    "x-amzn-mqtt-ca"

    switch( lOptionName )
    {
    case SOCKETS_SO_ALPN_PROTOCOLS:
    {

    const char * ppcALPNProtos[] = { socketsAWS_IOT_ALPN_MQTT };

    sTIRetCode = sl_SetSockOpt( pxSocketContext->sSocketDescriptor,
    SL_SOL_SOCKET,
    SL_SO_SECURE_ALPN_GENERAL,
    ppcALPNProtos,
    sizeof( ppcALPNProtos ) );

    /* If the above sl_SetSockOpt succeeded, return success to the user. */
    if( sTIRetCode >= 0 )
    {
    lRetCode = SOCKETS_ERROR_NONE;
    }
    else
    {
    /* See vendors/ti/SimpleLink_CC32xx/v2_10_00_04/source/ti/drivers/net/wifi/errors.h */
    SOCKETS_PRINT( ( "ERROR: %d SockOpt ALPN failed.\r\n", sTIRetCode ) );
    }
    }

    break;

    Can I also know which example and SDK are you using?

    Regards,

    Kishore.

  • The API allows one ALPN string as a parameter.

    sTIRetCode = sl_SetSockOpt ( pxSocketContext->sSocketDescriptor,

                                                      SL_SOL_SOCKET, SL_SO_SECURE_ALPN_GENERAL, socketsAWS_IOT_ALPN_MQTT,

                                                       strlen( socketsAWS_IOT_ALPN_MQTT));

    
    

    Br,

    Kobi