WiFi Client Service
This API provides WiFi Client setup. Please note that the WiFi Client cannot be used at the same time as the WiFi Access Points service, due to the sharing of same wifi hardware.
IPC interfaces binding
Here's a code sample binding to WiFi service:
bindings: { clientExe.clientComponent.le_wifiClient -> wifiService.le_wifiClient }
Starting the WiFi Client
First of all the function le_wifiClient_Start() must be called to start the WiFi Service.
- le_wifiClient_Start(): returns LE_OK if the call went ok. If WiFi Access Point is active, this will fail.
To subscribe to wifi events le_wifiClient_AddNewEventHandler() is to be called.
- le_wifiClient_AddNewEventHandler(): returns the handler reference if the call went ok.
static void EventHandler(le_wifiClient_Event_t clientEvent,void *contextPtr){switch( clientEvent ){{LE_INFO("WiFi Client Connected.");}break;{LE_INFO("WiFi Client Disconnected.");}break;{LE_INFO("WiFi Client Scan is done.");MyHandleScanResult();}break;}}le_wifiClient_NewEventHandler WiFiEventHandlerRef = NULL;static void MyInit(void){le_result_t result = le_wifiClient_start();if ( LE_OK == result ){LE_INFO("WiFi Client started.");WiFiEventHandlerRef = le_wifiClient_AddNewEventHandler( EventHandler, NULL );}{LE_INFO("ERROR: WiFi Client already started.");}else{LE_INFO("ERROR: WiFi Client not started.");}}
Scanning Access Points with WiFi Client
To start a scan for Access Points, the le_wifiClient_Scan() should be called.
- le_wifiClient_Scan(): returns the LE_OK if the call went ok.
Processing the WiFi scan results
Once the scan results are available, the event LE_WIFICLIENT_EVENT_SCAN_DONE is received. The found Access Points can then be gotten with
- le_wifiClient_GetFirstAccessPoint(): returns the Access Point if found. Else NULL.
- le_wifiClient_GetNextAccessPoint(): returns the next Access Point if found. Else NULL.
The Access Points SSID, Service Set Identifier, is not a string. It does however often contain human readable ASCII values. It can be read with the following function:
- le_wifiClient_GetSsid() : returns the LE_OK if the SSID was read ok.
The Access Points signal strength can be read with the following function:
- le_wifiClient_GetSignalStrength() : returns the signal strength in dBm of the AccessPoint
static void MyHandleScanResult(void){uint8 ssid[MAX_SSID_BYTES];le_wifiClient_AccessPointRef_t accessPointRef = le_wifiClient_GetFirstAccessPoint();while( NULL != accessPointRef ){result = le_wifiClient_GetSsid( accessPointRef, ssid, MAX_SSID_BYTES );if (( result == LE_OK ) && ( memcmp( ssid, "MySSID", 6) == 0 )){LE_INFO("WiFi Client found.");break;}accessPointRef = le_wifiClient_GetNextAccessPoint();}}
Connecting to Access Point
To connect to an Access Point use the function:
- le_wifiClient_Connect() : returns the LE_OK if the function was called ok.
To set the pass phrase prior for the Access Point use the function:
- le_wifiClient_SetPassphrase() : returns the LE_OK if the function was called ok.
WPA-Enterprise requires a username and password to authenticate. To set them use the function :
- le_wifiClient_SetUserCredentials() : returns the LE_OK if the function was called ok.
If an Access Point is hidden, it does not announce it's presence, it will not show up in the scan. To be able to connect to it, the SSID must be known. Use the following function to get an Access Point that can be used to connect to:
- le_wifiClient_Create() : returns Access Point.
static void MyConnectTo(le_wifiClient_AccessPointRef_t accessPointRef){le_result_t result;le_wifiClient_SetPassphrase ( accessPointRef, "Secret1" );result = le_wifiClient_Connect( accessPointRef );if (result == LE_OK){LE_INFO("Connecting to AP.");}}
Copyright (C) Sierra Wireless Inc. Use of this work is subject to license.