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

Wi-Fi Combo Forum Discussions

Anonymous
Not applicable

Hi team,

I am a new embedded engineer developing a wireless lighting control unit which we hope to use Broadcom hardware in for the mass manufacture of a wifi home automation product. I am new to WICED and am using the 3.5.2 SDK with the BCM943362WCD4_EVB wifi board. At the moment, I am trying to understand the process of how the wifi board connects to a local wifi network and stores that information. Specifically, I am trying to achieve the following:

Modify the temp_control example app to display the current wifi network SSID on the main.html page. Is the Wifi SSID stored somewhere that I can pass to the front end?

Looking at the scan and appliance examples, I can see that it is possible to search, find, display and connect to available wifi networks. I am just unable to replicate the process myself. I have been hunting through those examples which led me to look in the wifi.c and device_configuration_http_content.c files for the appropriate code to copy but am getting really confused with all of the functions and variables which seem to be defined elsewhere and are not commented very thoroughly.

Is anyone able to demystify this for me? Alternatively, are there any tutorials or well commented pieces of code that I can follow? Any guidance would be much appreciated!!

Cheers,

Matt

0 Likes
1 Solution
JaeyoungY_71
Employee
100 likes received 50 likes received 25 likes received
Employee

Hi Matthew,

Your comments on the code look right. The default for wifi config information is in

<WICED_SDK>/include/default_wifi_config_dct.h.

Some applications such as apps/apsta have a file wifi_config_dct.h and you can change the information here to download your board with a certain SSID/password/security.

If you want to change the ap you are connecting to dynamically, you can take a look at the function

wifi_join_specific() in /<WICED_SDK>/libraries/utilities/command_console/wifi/command_console_wifi.c.

You can test this code out if you download apps/test/console to your board. Once the app is downloaded, open up a terminal and type in "help" for a list of commands and you will see how to join an ap. I hope this helps.

Thanks,

Jaeyoung

View solution in original post

4 Replies
JeGu_2199941
Level 5
25 likes received 10 likes received 10 likes given
Level 5

In WICED we store information that we wish to keep in Device Configuration Table (DCT).

There is a DCT_WIFI_CONFIG region in DCT for WIFI information.

typedef struct

{

    wiced_bool_t              device_configured;

    wiced_config_ap_entry_t   stored_ap_list[CONFIG_AP_LIST_SIZE];

    wiced_config_soft_ap_t    soft_ap_settings;

    wiced_config_soft_ap_t    config_ap_settings;

    wiced_country_code_t      country_code;

    wiced_mac_t               mac_address;

    uint8_t                   padding[2];  /* to ensure 32bit aligned size */

} platform_dct_wifi_config_t;

The SSID you want is in wiced_config_ap_entry_t   stored_ap_list[CONFIG_AP_LIST_SIZE]

Look at snip.dct_read_write as sample code, especially

static wiced_result_t print_wifi_config_dct( void )

{

    platform_dct_wifi_config_t* dct_wifi_config = NULL;

    if ( wiced_dct_read_lock( (void**) &dct_wifi_config, WICED_FALSE, DCT_WIFI_CONFIG_SECTION, 0, sizeof( *dct_wifi_config ) ) != WICED_SUCCESS )

    {

        return WICED_ERROR;

    }

    /* since we passed ptr_is_writable as WICED_FALSE, we are not allowed to write in to memory pointed by dct_security */

    WPRINT_APP_INFO( ( "\r\n----------------------------------------------------------------\r\n\r\n") );

    /* Wi-Fi Config Section */

    WPRINT_APP_INFO( ( "Wi-Fi Config Section \r\n") );

    WPRINT_APP_INFO( ( "    device_configured               : %d \r\n", dct_wifi_config->device_configured ) );

    WPRINT_APP_INFO( ( "    stored_ap_list[0]  (SSID)       : %s \r\n", dct_wifi_config->stored_ap_list[0].details.SSID.value ) );

    WPRINT_APP_INFO( ( "    stored_ap_list[0]  (Passphrase) : %s \r\n", dct_wifi_config->stored_ap_list[0].security_key ) );

    WPRINT_APP_INFO( ( "    soft_ap_settings   (SSID)       : %s \r\n", dct_wifi_config->soft_ap_settings.SSID.value ) );

    WPRINT_APP_INFO( ( "    soft_ap_settings   (Passphrase) : %s \r\n", dct_wifi_config->soft_ap_settings.security_key ) );

    WPRINT_APP_INFO( ( "    config_ap_settings (SSID)       : %s \r\n", dct_wifi_config->config_ap_settings.SSID.value ) );

    WPRINT_APP_INFO( ( "    config_ap_settings (Passphrase) : %s \r\n", dct_wifi_config->config_ap_settings.security_key ) );

    WPRINT_APP_INFO( ( "    country_code                    : %c%c%d \r\n", ((dct_wifi_config->country_code) >>  0) & 0xff,

                                                                            ((dct_wifi_config->country_code) >>  😎 & 0xff,

                                                                            ((dct_wifi_config->country_code) >> 16) & 0xffff));

    WPRINT_APP_INFO( ( "    DCT mac_address                 : ") );

    print_mac_address( (wiced_mac_t*) &dct_wifi_config->mac_address );

    WPRINT_APP_INFO( ("\r\n") );

    /* Here ptr_is_writable should be same as what we passed during wiced_dct_read_lock() */

    wiced_dct_read_unlock( dct_wifi_config, WICED_FALSE );

    return WICED_SUCCESS;

}

Anonymous
Not applicable

xavier@candyhouse

Thanks for the quick reply. After reading this and a few hours of tinkering, I've managed to get it working! I have tried to comment my code so that others in my company can understand how it works. If you have a moment, would you be able to let me know if you agree with the comments I have entered? (note that my app name is lightstone3)

    //this initialises a variable to write from the dct

    platform_dct_wifi_config_t* dct_wifi_config = NULL;

    //unlock the dct so you can read from it

    wiced_dct_read_lock( (void**) &dct_wifi_config, WICED_FALSE, DCT_WIFI_CONFIG_SECTION, 0, sizeof( *dct_wifi_config ));

    //this section writes the connected WiFi SSID as defined in platform_dct.h to the html page

    wiced_http_response_stream_write_resource( stream, &resources_apps_DIR_lightstone3_DIR_data_html_SSID_start );

    //this is how you address the SSID value and other values in the dct_wifi_config structure

    temp_char_buffer_length = sprintf(temp_char_buffer, "%s", dct_wifi_config->stored_ap_list[0].details.SSID.value);

    wiced_http_response_stream_write(stream, temp_char_buffer, temp_char_buffer_length );

    wiced_http_response_stream_write_resource( stream, &resources_apps_DIR_lightstone3_DIR_data_html_SSID_end );

    //lock the dct after using

    wiced_dct_read_unlock( dct_wifi_config, WICED_FALSE );

Also, where is the wifi config SSID actually set? I can see the structure in the platform_dct.h file, but cannot find the actual code that populates the wifi config information.

0 Likes
JaeyoungY_71
Employee
100 likes received 50 likes received 25 likes received
Employee

Hi Matthew,

Your comments on the code look right. The default for wifi config information is in

<WICED_SDK>/include/default_wifi_config_dct.h.

Some applications such as apps/apsta have a file wifi_config_dct.h and you can change the information here to download your board with a certain SSID/password/security.

If you want to change the ap you are connecting to dynamically, you can take a look at the function

wifi_join_specific() in /<WICED_SDK>/libraries/utilities/command_console/wifi/command_console_wifi.c.

You can test this code out if you download apps/test/console to your board. Once the app is downloaded, open up a terminal and type in "help" for a list of commands and you will see how to join an ap. I hope this helps.

Thanks,

Jaeyoung

Anonymous
Not applicable

Thanks mate

0 Likes