Cleanest/correct way to manage a daemon (HTTP server) start/stop?

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

cross mob
AnPu_3825896
Level 1
Level 1
First like given

I am adding an HTTP server to an existing product that uses WiFi STA mode.
We already have some code around connection management, that does `wiced_network_up()` and `wiced_network_down()` to toggle network operation. Other parts also do `wwd_wifi_disassoc()` as part of the same operation.

Is there an existing facility or mechanism to handle the bringing up and down of the server daemon?

It appears as though the wifi_link_up callback is not called at the time of first association with the wifi network, and wifi_link_down is not called when a network becomes disassociated.

It also looks like the ip_address_change callback is not called on the first acquisition of an IP, nor as an IP is lost as the network is going down.

Is it the app's responsibility to poll connection status and bring the daemon up and down?

0 Likes
1 Reply
Zhengbao_Zhang
Moderator
Moderator
Moderator
250 sign-ins First comment on KBA 10 questions asked

hello:

if below code is a good reference for http_server start and stop?

        /* Start the DNS redirect server */

        wiced_dns_redirector_start( &dns_redirector, WICED_CONFIG_INTERFACE );

        /* Start the HTTP server */

#ifdef USE_HTTPS

        {

            platform_dct_security_t* dct_security = NULL;

            /* Lock the DCT to allow us to access the certificate and key */

            result = wiced_dct_read_lock( (void**) &dct_security, WICED_FALSE, DCT_SECURITY_SECTION, 0, sizeof( *dct_security ) );

            if ( result != WICED_SUCCESS )

            {

                WPRINT_APP_INFO(("Unable to lock DCT to read certificate\n"));

                return result;

            }

            /* Setup TLS identity */

            result = wiced_tls_init_identity( &tls_identity, dct_security->private_key, (uint8_t*)dct_security->certificate, strlen(dct_security->certificate) );

            if ( result != WICED_SUCCESS )

            {

                WPRINT_APP_INFO(( "Unable to initialize TLS identity. Error = [%d]\n", result ));

                return result;

            }

            wiced_https_server_start(http_server, HTTPS_PORT, 10, config_http_page_database, &tls_identity, WICED_CONFIG_INTERFACE, DEFAULT_URL_PROCESSOR_STACK_SIZE );

            /* Finished accessing the certificates */

            wiced_dct_read_unlock( dct_security, WICED_FALSE );

        }

#else

        wiced_http_server_start(http_server, HTTP_PORT, 10, config_http_page_database, WICED_CONFIG_INTERFACE, DEFAULT_URL_PROCESSOR_STACK_SIZE );

#endif

        wiced_http_server_register_callbacks(http_server , aws_http_receive_callback, NULL );

        /* Wait for configuration to complete */

        wiced_rtos_get_semaphore(&aws_config_semaphore, WICED_WAIT_FOREVER);

        /* Cleanup HTTP server */

#ifdef USE_HTTPS

        wiced_https_server_stop(http_server);

#else

        wiced_http_server_stop(http_server);

#endif

        free( http_server );

        wiced_rtos_deinit_semaphore(&aws_config_semaphore);

        /* Cleanup DNS server */

        wiced_dns_redirector_stop(&dns_redirector);

        /* Turn off AP */

        wiced_network_down( WICED_CONFIG_INTERFACE );

0 Likes