I'm working with subscribing to topics with MQTT (mutual authentication demo). My final intent is to exercise Fleet Provisioning.
The subscription routines allow the designer to statically create space for multiple topics. In the demo code, a call to MQTT_Subscribe calculates the size of the static array as follows:
/* Send SUBSCRIBE packet.
Note: reusing the value specified in globalSubscribePacketIdentifier is acceptable here
because this function is entered only after the receipt of a SUBACK, at which point
its associated packet id is free to use. */
mqttStatus = MQTT_Subscribe( pMqttContext,
pGlobalSubscriptionList,
sizeof( pGlobalSubscriptionList ) / sizeof( MQTTSubscribeInfo_t ),
globalSubscribePacketIdentifier );
The full size of the array is sent into the function BUT the function will fail when it tries to process an array entry that is invalid. The function doesn't stop processing at an empty entry. The return code is: MQTTBadParameter
The work-around must be to replace sizeof( pGlobalSubscriptionList ) / sizeof( MQTTSubscribeInfo_t ) with a hard number indicating the total number of subscription entries which are valid.
I assume you want the MQTT_Subscribe function to detect when an array element is not valid and stop processing the subscriptions at that point???
If this is NOT the intent, then you should use a variable like topic_count in place of sizeof( pGlobalSubscriptionList ) / sizeof( MQTTSubscribeInfo_t ) to indicate the intend of the parameter more clearly.
I'm working with subscribing to topics with MQTT (mutual authentication demo). My final intent is to exercise Fleet Provisioning.
The subscription routines allow the designer to statically create space for multiple topics. In the demo code, a call to MQTT_Subscribe calculates the size of the static array as follows:
/* Send SUBSCRIBE packet.
The full size of the array is sent into the function BUT the function will fail when it tries to process an array entry that is invalid. The function doesn't stop processing at an empty entry. The return code is: MQTTBadParameter
The work-around must be to replace sizeof( pGlobalSubscriptionList ) / sizeof( MQTTSubscribeInfo_t ) with a hard number indicating the total number of subscription entries which are valid.
I assume you want the MQTT_Subscribe function to detect when an array element is not valid and stop processing the subscriptions at that point???
If this is NOT the intent, then you should use a variable like topic_count in place of sizeof( pGlobalSubscriptionList ) / sizeof( MQTTSubscribeInfo_t ) to indicate the intend of the parameter more clearly.
Working with Windows / VSC in C++