Migration Example#

This section provides an example of rewriting a WiSeConnect SDK v2.x Wi-Fi client (station mode) application with the v3.x API.

Some code, such as that for event handlers, is omitted for brevity.

In the example below:

  • In the main() function, we replaced the v2.x rsi_task_create() API call with the FreeRTOS osThreadNew() API call, to create a new FreeRTOS task to run the application.

  • In the initialization function, we replaced the v2.x rsi_task_create() and rsi_wireless_init() API calls with the v3.x sl_net_init() API call, to initialize the WiSeConnect SDK and SiWx917 device.

  • In the initialization function, we replaced the v2.x rsi_wlan_scan(), rsi_wlan_set(), rsi_wlan_connect(), and rsi_config_ipaddress() API calls with the v3.x sl_net_set_profile(), sl_net_set_credential(), and sl_net_up() API calls, to scan for a wireless access point, connect to it, and configure an IP address.

  • In v3.x, no task needs to be created by the application to process events, as compared with v2.x where an rsi_wireless_driver_task must be created. The v3.x SDK automatically creates a bus_thread and event_thread to manage events.

v2.x API Code

v3.x API Code

int32_t application_start() {

static void application_start(void *argument) {

rsi_task_create((rsi_task_function_t) rsi_wireless_driver_task, (uint8_t) "driver_task", RSI_DRIVER_TASK_STACK_SIZE, NULL, RSI_DRIVER_TASK_PRIORITY), &driver_task_handle);

int32_t status = rsi_wireless_init(0, 0);

sl_status_t status = sl_net_init(SL_NET_DEFAULT_WIFI_CLIENT_INTERFACE, NULL, NULL, NULL);

status = rsi_wlan_scan((int8_t *) SSID, (uint8_t) CHANNEL_NO, NUlL, 0);

uint8_t join_bssid[6] = AP_BSSID;

status = rsi_wlan_set(CMD_TYPE, join_bssid, 6);

sl_net_set_profile(SL_NET_WIFI_CLIENT_INTERFACE, SL_NET_DEFAULT_WIFI_CLIENT_PROFILE_ID, &wifi_client_profile);

status = rsi_wlan_connect((int8_t *) SSID, SECURITY_TYPE, PSK);

sl_net_set_credential(SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID, SL_NET_WIFI_PSK, &(wifi_client_credential.data), sizeof(wifi_client_credential.data));

status = rsi_config_ipaddress(RSI_IP_VERSION_4, RSI_STATIC, (uint8_t *) &ip_addr, (uint8_t *) &network_mask, (uint8_t *) &gateway, NULL, 0, 0);

status = sl_net_up(SL_NET_DEFAULT_WIFI_CLIENT_INTERFACE, SL_NET_DEAULT_WIFI_CLIENT_PROFILE_ID);

while (1) { rsi_wireless_driver_task(); }

while(1) { osDelay(osWaitForever); }

}

}

int main() {

void main(const void *unused) {

sl_system_init();

rsi_task_handle_t wlan_task_handle = NULL;

UNUSED_PARAMETER(unused);

rsi_task_create((rsi_task_function_t) application_start, (uint8_t *) "wlan_task", RSI_WLAN_TASK_STACK_SIZE, NULL, RSI_WLAN_TASK_PRIORITY, &wlan_task_handle);

osThreadNew((osThreadFunc_t) application_start, NULL,, &thread_attributes);

rsi_os_start_scheduler();

sl_system_kernel_start();

}

}