This snip demonstrates how a WICED device can be configured to work simultaneously as an access point and station.


Testing the snip step by step

Launch WICED Studio and open the apsta.c file. It is available at 43xxx_Wi-Fi/apps/snip/apsta as shown below.

apsta location.jpg

When the WICED device would work as STA, it will join the access point configured in the Wi-Fi configuration DCT. Change the Client AP SSID and Client AP passphrase so that they match with your access point as shown below. The Wi-Fi DCT configuration file wifi_config_dct.h is available at 43xxx_Wi-Fi/include.

apsta dct.jpg

We will run this snip on the platform BCM943438WCD1. Create a new make target and write the target name “snip.apsta- BCM943438WCD1 download run” without the double quotes as shown below.

Modify make target.jpg

To build and run the target, double click on the target name that we just made as shown below.

select make target.jpg

WICED will build the project and display the various steps that it is executing during the build process in the console window. The apsta snip will start running after the console displays the “Target running” message.

apsta target running.jpg

Open a UART terminal such as Tera term and select the COM port of the BCM943438WCD1 platform and configure the baud rate to 115200. The following output will be displayed on the UART terminal.

apsta terminal output.jpg

As shown above, the STA pings the gateway periodically using its IP address.


We shall test the WICED SoftAP interface. Connect the Wi-Fi of your computer to the SSID of the SoftAP interface configured in wifi_config_dct.h. By default, the SSID is "WICED Soft AP" and the passphrase is "abcd1234" without quotes. Open a web browser and type The server should redirect you to a page with the extension "/apps/apsta/ap_top.html" as shown below.

apsta web page.jpg

This completes the testing of the apsta snip. We shall try to understand the application code written in apsta.c.


Understanding the application code

In the application code, the function wiced_init() is used for initializing the RTOS, platform, WLAN radio of the WICED device.

The STA interface is brought up using wiced_network_up(WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL); The last field is basically used for configuring the IP settings of the WICED device. It is assigned “NULL” because we configured the network to use external DHCP server. This uses the Dynamic Host Configuration Protocol (DHCP) to assign IP address to the STA. The STA attempts to join the AP configured in wifi_config_dct.h under the Client AP settings. If the join is successful, it obtains the IPv4 address for the STA using DHCP protocol.


The IPv4 address of the gateway to which the STA had connected to is then obtained using wiced_ip_get_gateway_address( WICED_STA_INTERFACE, &ping_target_ip ); This address will be used by the STA to ping the gateway.


An RTOS event is registered using wiced_rtos_register_timed_event( &ping_timed_event, WICED_NETWORKING_WORKER_THREAD, &send_ping, PING_PERIOD, 0 ); with a callback function send_ping( void *arg ). This callback will be triggered every PING_PERIOD ms and the function wiced_ping( WICED_STA_INTERFACE, &ping_target_ip, PING_TIMEOUT, &elapsed_ms ); will be called to ping the gateway with timeout equal to PING_TIMEOUT ms. This callback will be executed in the networking worker thread.


Subsequently the SoftAP interface is brought up using wiced_network_up(WICED_AP_INTERFACE, WICED_USE_INTERNAL_DHCP_SERVER, &ap_ip_settings); The ap_ip_settings contains the IP address, gateway address and netmask settings for the SoftAP. The SoftAP settings in DCT are read and the AP is started using these settings. The NetX API nx_ip_create() is used for creating an IP instance during the bring-up. Specifically the IPv4 settings, packet pools, softAP interface driver, memory, network object and priority of the IP thread are defined by the API. An RTOS thread is created to start a DHCP server and then NetX determines whether the IP address has been resolved or not. If it has been successfully resolved, NetX obtains the IPv4 address and it is displayed on UART terminal. The function wiced_dns_redirector_start( &dns_redirector, WICED_AP_INTERFACE ); is used for redirecting the URL to in the HTTP page database. Subsequently the function wiced_http_server_start ( &ap_http_server, 80, max_sockets, ap_web_pages, WICED_AP_INTERFACE, DEFAULT_URL_PROCESSOR_STACK_SIZE ) starts an HTTP webserver. The instance ap_web_pages of struct wiced_http_page_t encapsulates the redirect link "/apps/apsta/ap_top.html" which is basically found in 43xxx_Wi-Fi/resources/apps/apsta/ap_top.html. It also contains the HTTP MIME type; for instance the MIME type for "/apps/apsta/ap_top.html" is "text/html". WICED_RESOURCE_URL_CONTENT in the structure specifies that the http page ap_top.html is provided by WICED resource. It provides a resource handle structure specifying the location (whether it is in memory, filesystem or external storage), the appropriate resource handle depending on location.