Issue when starting/stopping HTTP server

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

cross mob
ClMa_3563786
Level 2
Level 2

Hello,

I'm using WICED SDK 6.1 and I have an issue when I start then stop then start again my HTTP server.

I'm using FreeRTOS and LwIP

I'm using HTTP_Server from WICED (librairies/daemons/HTTP_Server).

When my application goes into AP mode, I start my webserver using the function wiced_http_server_start.

Then I goes off the AP mode, I call the function wiced_http_server_stop.

A few minutes after, I goes back to AP mode, I call the wiced_http_server_start function again, but I have a result error ADDRESS_ALREADY_IN_USE.

I've check that I correctly call the function wiced_http_server_stop.

This return goes from the function err_t netconn_bind(struct netconn *conn, ip_addr_t *addr, u16_t port).

My issue is very similar to this one:

Re: Re: Problem stopping/starting webserver

The code I use:

void Network_start_AP(void)

{

    wiced_result_t    result_function = WICED_ERROR;

    // Power On the AP network

    if(WICED_TRUE != wiced_network_is_up(WICED_AP_INTERFACE)){

        result_function = wiced_network_up( WICED_AP_INTERFACE,

                                            WICED_USE_INTERNAL_DHCP_SERVER,

                                            &ap_ip_settings);

        // If success start the http server

        if(WICED_SUCCESS == result_function){

            result_function = wiced_http_server_start(

                &ap_http_server,

                PORT,

                NB_CLIENT,

                ap_web_pages,

                WICED_AP_INTERFACE,

                STACK_SIZE

                );

            // If start failed Then close http server properly

            if(WICED_SUCCESS != result_function){

                wiced_http_server_stop(&ap_http_server);

                wiced_network_down(WICED_AP_INTERFACE);

            }

        }

        // If Power On failed, then power off the AP network properly

        else{

            wiced_http_server_stop(&ap_http_server);

            wiced_network_down(WICED_AP_INTERFACE);

        }

    }

    else{

        // network already in AP mode

    }

}

void Network_close_AP(void){

    // Power Off the AP network if necessary

    if(WICED_FALSE != wiced_network_is_up(WICED_AP_INTERFACE)){

        WPRINT_APP_INFO( ( "Network_close_AP - stop http server\n" ) );

        wiced_http_server_stop(&ap_http_server);

        wiced_network_down(WICED_AP_INTERFACE);

        while(wiced_network_is_up(WICED_AP_INTERFACE) == WICED_TRUE ){}

    }

    else{

        // AP network already Power Off

    }

}


Unfortunately for me, the issue goes away by magic

If you have any suggestion, I would greatly appreciate

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

Hello,

I have tried to replicate the mentioned problem and written a sample code for testing. Kindly check with the attached snip and revert back with the problems you are facing in starting the server again. I tested the snip and I am able to connect to the server after stop -> start cycle.

Console commands added for stopping and starting the server are similar to what you have added in response 1:

Network_close_AP and Network_start_AP

Also kindly attach the UART log for analysis.

View solution in original post

0 Likes
3 Replies
PriyaM_16
Moderator
Moderator
Moderator
250 replies posted 100 replies posted 50 replies posted

Kindly check the return value of wiced_http_server_stop() to make sure that the server has stopped before starting the server again.

0 Likes

Thanks for this. I've done that first, but reading the code, the return can't be other than WICED_SUCCESS.

wiced_result_t wiced_http_server_stop( wiced_http_server_t* server )

{

    server_event_message_t current_event;

    wiced_assert( "bad arg", ( server != NULL ) );

    current_event.event_type = SERVER_STOP_EVENT;

    current_event.socket     = 0;

    wiced_rtos_push_to_queue( &server->event_queue, &current_event, WICED_NO_WAIT );

    if ( wiced_rtos_is_current_thread( &server->event_thread ) != WICED_SUCCESS )

    {

        /* Wakeup HTTP event thread */

        wiced_rtos_thread_force_awake( &server->event_thread );

    }

    /* Wait for the event to completely get processed for closing the server smoothly */

    wiced_rtos_thread_join( &server->event_thread );

    /* Delete the threads */

    wiced_rtos_delete_thread( &server->event_thread );

    wiced_rtos_delete_worker_thread( &server->connect_thread );

    linked_list_deinit( &server->inactive_stream_list );

    linked_list_deinit( &server->active_stream_list );

    free( server->streams );

    server->streams = NULL;

    return WICED_SUCCESS;

}

I've even checked in the http_server_event_thread_main function that managed the HTTP server.

We correctly receive the STOP message, and exit the thread after cleaning the socket using function:

wiced_result_t wiced_tcp_server_stop( wiced_tcp_server_t* tcp_server )

{

    ...

        netconn_delete( tcp_server->accept_socket[ i ].accept_handler );

    ...

    netconn_disconnect( tcp_server->listen_socket.conn_handler );

    netconn_delete( tcp_server->listen_socket.conn_handler );

}

0 Likes
lock attach
Attachments are accessible only for community members.

Hello,

I have tried to replicate the mentioned problem and written a sample code for testing. Kindly check with the attached snip and revert back with the problems you are facing in starting the server again. I tested the snip and I am able to connect to the server after stop -> start cycle.

Console commands added for stopping and starting the server are similar to what you have added in response 1:

Network_close_AP and Network_start_AP

Also kindly attach the UART log for analysis.

0 Likes