TCP Packet Creation Fails in ThreadX

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

cross mob
Anonymous
Not applicable

Every so often, while sending tcp packets, the function wiced_packet_create_tcp fails.  When this happens, it never seems to recover, but closing the tcp socket and reconnecting clears the problem.  This isn't really good enough, since my company needs to stream audio live.  The time between packet creation failures seems to decrease when the rate of packets being sent is higher, but I've seen this problem even with a packet every second.  There doesn't seem to be any correlation with actual data rate, as I've verified that doubling packet length while halving packet rate improves up time.

My best guess is it seems like NetX_Duo has problems cleaning up after itself?  It appears that serveral other people have had this problem, but I haven't seen a solution besides "buy a different router." I'd use LwIP/FreeRTOS, but that has its own problems (at least in 3.0.1).

Has anyone encountered this and actually fixed it?

My tcp send function is below:

wiced_result_t send_packet(char* payload, uint16_t length, packet_type_t type){

    wiced_packet_t*          packet;

    char*                    tx_data;

    uint16_t                 available_data_length;

    int                      data_len;

    int                      packet_len = 40 + length;

    if (net_status != NETWORK_STATUS_SERVER_CONNECTED && net_status != NETWORK_STATUS_SERVER_RESPONDING)

    {

        return WICED_ABORTED;

    }

    // Create the TCP packet. Memory for the tx_data is automatically allocated /

    if (wiced_packet_create_tcp(&tcp_client_socket, packet_len, &packet, (uint8_t**)&tx_data, &available_data_length) != WICED_SUCCESS)

    {

        WPRINT_APP_INFO(("TCP packet creation failed\n"));

        //if this fails, it doesn't seem to recover...

        mimo_tcp_disconnect();

        return WICED_ERROR;

    }

    if(packet_len > available_data_length){

#if VERBOSITY >= 2

        WPRINT_APP_INFO(("No space for tx packet!\n"));

#endif

        return WICED_ABORTED;

    }

    char server_packet_type = type==TYPE_H? 'H' :

            type==TYPE_D ? 'D' :

            type==TYPE_A ? 'A' : 'F';

    // Write the message into tx_data"  /

    data_len = sprintf(tx_data, "GET /?d=[");

    data_len += sprintf(tx_data+data_len, "%s", payload);

    data_len += sprintf(tx_data+data_len, "] HTTP/1.1 \r\n\r\n");

    // Set the end of the data portion /

    wiced_packet_set_data_end(packet, (uint8_t*)tx_data + data_len);

    // Send the TCP packet /

    if (wiced_tcp_send_packet(&tcp_client_socket, packet) != WICED_SUCCESS)

    {

        WPRINT_APP_INFO(("TCP packet send failed\n"));

        // Delete packet, since the send failed */

        wiced_packet_delete(packet);

        // Close the connection */

        my_tcp_disconnect();

        return WICED_ERROR;

    }

    return WICED_SUCCESS;

}

0 Likes
1 Reply
Anonymous
Not applicable

Seems to be fixed in sdk3.1.1.

0 Likes