aws / aws-iot-device-sdk-embedded-C

SDK for connecting to AWS IoT from a device using embedded C.
MIT License
977 stars 628 forks source link

Is the max size of MQTT_Subscribe's second parameter 8? #1903

Closed hassan-intretech closed 6 months ago

hassan-intretech commented 6 months ago

I build and test the demo 'mqtt_demo_mutual_auth' when I call 'MQTT_Subscribe' to subscribe a pGlobalSubscriptionList with size is more then 8, I got an error:

[ERROR] [Transport_OpenSSL_Sockets] [openssl_posix.c:845] Failed to receive data over network: SSL_read failed: ErrorStatus=EVP lib.
[ERROR] [DEMO] [feeder_mqtt.c:1631] MQTT_ProcessLoop failed to receive ACK packet: Expected ACK Packet ID=01, LoopDuration=819, Status=MQTTRecvFailed

But if the size of pGlobalSubscriptionList is less than 8, I can subscribe and publish success.

Here is my code of subscribeToTopic function:


static int subscribeToTopic( MQTTContext_t * pMqttContext )
{
    int returnStatus = EXIT_SUCCESS;
    MQTTStatus_t mqttStatus;

    assert( pMqttContext != NULL );

    /* Start with everything at 0. */
    ( void ) memset( ( void * ) pGlobalSubscriptionList, 0x00, sizeof( pGlobalSubscriptionList ) );

    /* This example subscribes to only one topic and uses QOS1. */

    /* Generate packet identifier for the SUBSCRIBE packet. */
    globalSubscribePacketIdentifier = MQTT_GetPacketId( pMqttContext );
    for(int i=0;i<11;i++)
        printf("============================topic:%s, len:%d, id:%d\r\n",pGlobalSubscriptionList[ i ].pTopicFilter,pGlobalSubscriptionList[ i ].topicFilterLength,globalSubscribePacketIdentifier);

    printf("==================pGlobalSubscriptionList size:%d\r\n", sizeof( pGlobalSubscriptionList ) / sizeof( MQTTSubscribeInfo_t ));

    /* Send SUBSCRIBE packet. */
    mqttStatus = MQTT_Subscribe( pMqttContext,
                                 pGlobalSubscriptionList,
                                 sizeof( pGlobalSubscriptionList ) / sizeof( MQTTSubscribeInfo_t ),

```                              globalSubscribePacketIdentifier );

    if( mqttStatus != MQTTSuccess )
    {
        LogError( ( "Failed to send SUBSCRIBE packet to broker with error = %s.",
                    MQTT_Status_strerror( mqttStatus ) ) );
        returnStatus = EXIT_FAILURE;
    }
    else
    {
        LogInfo( ( "SUBSCRIBE sent for topic %.*s to broker.\n\n",
                   MQTT_EXAMPLE_TOPIC_LENGTH,
                   MQTT_EXAMPLE_TOPIC ) );
    }

    return returnStatus;
}
chinglee-iot commented 6 months ago

@hassan-intretech AWS IoT Core limits a single SUBSCRIBE request has a quota of 8 subscriptions. Please reference this document. https://docs.aws.amazon.com/general/latest/gr/iot-core.html#iot-protocol-limits