TCP P2P 200ms Response time too big

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

cross mob
MaFa_974161
Level 5
Level 5
100 sign-ins 50 replies posted 50 questions asked

Hello.

I initialize WICED as P2P GC.

After successful WiFi P2P connection my firmware running on WICED creates a thread that

1. connects to a server

2. receive TCP packets called requests (one request is 8 bytes wide) and sends TCP packets called answers (one answer is 8 bytes wide).

On server's side I measure time between one request and the relative response and this time is about 200ms. It's too big, I expect about 10ms for example.

I report my thread code.

#define ANSWER_LEN  8

static void tcpConnect(uint args)

{

    wiced_spi_message_segment_t segment;

    wiced_tcp_socket_t  tcp_socket;

    wiced_packet_t*     request_packet;

    wiced_packet_t*     answer_packet;

    wiced_result_t      result;

    wiced_ip_address_t  gateway;

    uint16_t            request_data_length;

    uint16_t            available_data_length;

    int                 connection_retries;

    char*               request_data;

    char*               answer_data;

   

    /* Get gateway */

    wiced_ip_get_gateway_address ( WICED_P2P_INTERFACE, &gateway );

    /* Create TCP socket */

wiced_tcp_create_socket ( &tcp_socket, WICED_P2P_INTERFACE );

    /* Bind to the socket */

wiced_tcp_bind ( &tcp_socket, TCP_TARGET_PORT );

/* Connect to server */

    do

    {

        result = wiced_tcp_connect ( &tcp_socket, &gateway, TCP_TARGET_PORT, 500);

        connection_retries++;

    }

    while ( ( result != WICED_SUCCESS ) );

    /* Loop */

    while(WICED_TRUE)

    {

        /* Receive Server's Request */

        wiced_tcp_receive ( &tcp_socket, &request_packet, WICED_NEVER_TIMEOUT );

        /* Get the contents of the received packet */

        wiced_packet_get_data ( request_packet, 0, (uint8_t**)&request_data, &request_data_length, &available_data_length );

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

     wiced_packet_create_tcp ( &tcp_socket, ANSWER_LEN, &answer_packet, (uint8_t**)&answer_data, &available_data_length );

        /* Set the end of the data portion */

        wiced_packet_set_data_end ( answer_packet, (uint8_t*)answer_data + ANSWER_LEN );

        /* Delete the REQUEST */

        wiced_packet_delete ( request_packet );

        /* Send the TCP packet */

        wiced_tcp_send_packet ( &tcp_socket, answer_packet );

    }

}

What I'm wrong ?

0 Likes
5 Replies
Zhengbao_Zhang
Moderator
Moderator
Moderator
250 sign-ins First comment on KBA 10 questions asked

Hello:

  I am using sta mode to have a TCP test,  I think we need to prove the tcp stack layer has no problem to influence the delay.

so I add the host time code in this method.

wiced_result_t tcp_client( void* arg )

{

    wiced_result_t           result;

    wiced_packet_t*          packet;

    wiced_packet_t*          rx_packet;

    char*                    tx_data;

    char*                    rx_data;

    uint16_t                 rx_data_length;

    uint16_t                 available_data_length;

    const wiced_ip_address_t INITIALISER_IPV4_ADDRESS( server_ip_address, TCP_SERVER_IP_ADDRESS );

    int                      connection_retries;

    uint32_t temp_time =0;

    uint32_t temp_time1 =0;

    uint32_t temp_time2 =0;

    UNUSED_PARAMETER( arg );

    /* Connect to the remote TCP server, try several times */

    connection_retries = 0;

    do

    {

        result = wiced_tcp_connect( &tcp_client_socket, &server_ip_address, TCP_SERVER_PORT, TCP_CLIENT_CONNECT_TIMEOUT );

        connection_retries++;

    }

    while( ( result != WICED_SUCCESS ) && ( connection_retries < TCP_CONNECTION_NUMBER_OF_RETRIES ) );

    if( result != WICED_SUCCESS)

    {

        WPRINT_APP_INFO(("Unable to connect to the server! Halt.\n"));

    }

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

   temp_time=host_rtos_get_time(  );

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

    {

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

        return WICED_ERROR;

    }

    /* Write the message into tx_data"  */

    sprintf(tx_data, "%s", "Hello from WICED\n");

    host_rtos_delay_milliseconds(10);

    /* Set the end of the data portion */

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

    /* Send the TCP packet */

    temp_time1=host_rtos_get_time(  );

    WPRINT_APP_INFO(("wiced_packet_create_tcp delta after create%d\n",temp_time1-temp_time));

    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 */

        wiced_tcp_disconnect(&tcp_client_socket);

        return WICED_ERROR;

    }

    /* Receive a response from the server and print it out to the serial console */

    result = wiced_tcp_receive(&tcp_client_socket, &rx_packet, TCP_CLIENT_RECEIVE_TIMEOUT);

    temp_time2=host_rtos_get_time(  );

    WPRINT_APP_INFO(("wiced_tcp_receive delta after send%d\n",temp_time2-temp_time1));

    if( result != WICED_SUCCESS )

    {

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

        /* Delete packet, since the receive failed */

        wiced_packet_delete(rx_packet);

        /* Close the connection */

        wiced_tcp_disconnect(&tcp_client_socket);

        return WICED_ERROR;

    }

    /* Get the contents of the received packet */

    wiced_packet_get_data(rx_packet, 0, (uint8_t**)&rx_data, &rx_data_length, &available_data_length);

    if (rx_data_length != available_data_length)

    {

        WPRINT_APP_INFO(("Fragmented packets not supported\n"));

        /* Delete packet, since the receive failed */

        wiced_packet_delete(rx_packet);

        /* Close the connection */

        wiced_tcp_disconnect(&tcp_client_socket);

        return WICED_ERROR;

    }

    /* Null terminate the received string */

    rx_data[rx_data_length] = '\x0';

    WPRINT_APP_INFO(("%s", rx_data));

    /* Delete the packet and terminate the connection */

    wiced_packet_delete(rx_packet);

    wiced_tcp_disconnect(&tcp_client_socket);

    return WICED_SUCCESS;

}

here are the prints :

You will see the delta time between send and recieve is 10, 9, 14, 9

pastedImage_4.png

I think you can take a reference from tcp_client.c and add more prints to find where takes the time.

0 Likes

Are you using WIFi ?

Or Ethernet ?

0 Likes

Hello:

  I am using wifi , one is wiced board acted as TCP client, one is PC with tcp_echo_server.py as TCP server.

0 Likes

Can you change the order of Receive and Send ?

I explain better :

My situation is that the PC (acting as the Server) is the first actor that sends TCP packet to WICED board, then the WICED reply to PC with another TCP packet ...

Can you test this situation ?

0 Likes

Thanks for your support.

With WireShark and WiFi sniffer I realize that WICED WiFi go to power save mode ...

If I disable power save mode with this API :

     wiced_wifi_disable_powersave_interface ( WICED_P2P_INTERFACE );

in "p2p_result_callback" in the case where "connection_p2p_result_t" is equal to CONNECTION_P2P_CONNECTED

I observe no 200ms delay.