Problem with MQTT Subscriber snip

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
chli_2118906
Level 3
Level 3
First like received

While working with the MQTT libraries I discovered an apparent error. 

Compiling snip.mqtt_subscriber... creates a nearly working solution, but unfortunately the fix is down below the application in the MQTT libraries.  When running the subscriber solution in SDK-3.3.1, one will find that the function appears to get a new packet, just like the last packet received every minute. It does not matter if the packet was a ping response or a valid message, the function appears to continue to receive these messages.  Without going into the entire problem, the apparent solution is to change the return value that is returned from “wiced_read” in MQTTWiced.c

My fix:

int wiced_read( Network* n, unsigned char* buffer, int len, int timeout_ms )

{

    char* request;

    uint16_t request_length;

    wiced_result_t result;

    wiced_packet_t* rx_packet = NULL;

    uint16_t available_data_length;

    wiced_tcp_socket_t* tcp_socket = (wiced_tcp_socket_t*) &n->my_socket;

    uint32_t data_to_copy = 0;

    result = wiced_tcp_receive( tcp_socket, &rx_packet, 1000 );

    if ( result != WICED_SUCCESS )

    {

         return -1;      //CML this is my best guess

//       return result;  //old code returns the number of characters received or 2 if no characters

    }

    wiced_packet_get_data( rx_packet, 0, (uint8_t**) &request, &request_length, &available_data_length );

    data_to_copy = MIN(request_length, len);

    memcpy( buffer, request, data_to_copy );

    wiced_packet_delete( rx_packet );

    return (int) data_to_copy;

}

This satisfies the calling function that is looking for a negative number when no data is returned.  If there is data to return, the function returns a positive length and this too satisfies the calling function. 

Any chance of getting this fix in the "base" code to save me the headache of finding it again in the next release?

0 Likes
1 Solution
Anonymous
Not applicable

Hi,

Thanks for pointing out the bug and proposing a possible solution for it. Have you looked at the 3.4.0AWS SDK which has MQTT fixes from 3.3.1 SDK.

Our team will check it out and fix with your proposed solution if needed.

Best Regards,

AB

View solution in original post

0 Likes
1 Reply
Anonymous
Not applicable

Hi,

Thanks for pointing out the bug and proposing a possible solution for it. Have you looked at the 3.4.0AWS SDK which has MQTT fixes from 3.3.1 SDK.

Our team will check it out and fix with your proposed solution if needed.

Best Regards,

AB

0 Likes