WiFi Client Service

API Reference


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.

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 );
}
else if ( LE_BUSY == result )
{
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.

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

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:

The Access Points signal strength can be read with the following function:

static void MyHandleScanResult
(
void
)
{
uint8 ssid[MAX_SSID_BYTES];
 
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;
}
}
}

Connecting to Access Point

First of all, an Access Point reference should be created using the SSID of the target Access Point. Use the following function to create a reference:

To set the pass phrase prior for the Access Point use the function:

WPA-Enterprise requires a username and password to authenticate. To set them use the function:

If an Access Point is hidden, it does not announce its presence and will not show up in scan. So, the SSID of this Access Point must be known in advance. Then, use the following function to allow connections to hidden Access Points: le_wifiClient_SetHiddenNetworkAttribute(): returns the function execution status.

Finally and when the Access Point parameters have been configured, use the following function to attempt a connection:

static void MyConnectTo
(
)
{
le_result_t result;
le_wifiClient_SetPassphrase ( accessPointRef, "Secret1" );
result = le_wifiClient_Connect( accessPointRef );
if (result == LE_OK)
{
LE_INFO("Connecting to AP.");
}
}