1.4.3.16 SYS_WIFI_Initialize Function

C

SYS_MODULE_OBJ SYS_WIFI_Initialize
(
SYS_WIFI_CONFIG *config,
SYS_WIFI_CALLBACK callback,
void *cookie
)

Summary

Initializes the System Wi-Fi module.

Description

Wi-Fi service supports only one single instance of Wi-Fi.

Parameters

ParamDescription
configWi-Fi device configuration structure.
callbackThe client callback function pointer.
cookieThe pointer which will be passed to the customer application when the customer callback function is invoked.

Returns

If successful, returns a valid handle to an object. Otherwise, it returns SYS_MODULE_OBJ_INVALID.

Example

#define WIFI_DEV_SSID "DEMO_AP"
#define WIFI_DEV_PSK "password"

SYS_WIFI_CONFIG wifiSrvcConfig;

// Set mode as STA
wifiSrvcConfig.mode = SYS_WIFI_STA;

// Disable saving wifi configuration
wifiSrvcConfig.saveConfig = false;

// Set the auth type to SYS_WIFI_WPA2
wifiSrvcConfig.staConfig.authType = SYS_WIFI_WPA2;

// Enable all the channels(0)
wifiSrvcConfig.staConfig.channel = 0;

// Device doesn't wait for user request
wifiSrvcConfig.staConfig.autoConnect = 1;

// Set SSID
memcpy(wifiSrvcConfig.staConfig.ssid,WIFI_DEV_SSID,sizeof(WIFI_DEV_SSID));

// Set PSK
memcpy(wifiSrvcConfig.staConfig.psk,WIFI_DEV_PSK,sizeof(WIFI_DEV_PSK));

sysObj.syswifi = SYS_WIFI_Initialize(&wifiSrvcConfig, WiFiServCallback, 0);
if (sysObj.syswifi == SYS_MODULE_OBJ_INVALID)
{
    // Handle error
}

Remarks

This routine can only be called once during system initialization. If the Wi-Fi system service is enabled using MHC, then auto generated code will take care of system wi-fi initialization.