3.1.7.1 Wi-Fi Service

The Wi-Fi service provides API’s to enable the following features:
  1. Station mode
  2. Soft AP mode
The Wi-Fi Service API prototype is as follows:
RNWF_RESULT_t RNWF_WIFI_SrvCtrl( RNWF_WIFI_SERVICE_t request, void *input)
It handles following services and reports the result to application over the return code or through the registered callback.
Table 3-2. Wi-Fi Services
Option/Command Input Description
RNWF_SET_WIFI_PARAMS Mode, SSID, Passphrase, Security, Autoenable Configures the provided Wi-Fi details and Triggers the connection based on auto enable flag
RNWF_STA_CONNECT None Triggers the Wi-Fi STA connection
RNWF_STA_DISCONNECT None Disconnects the connection
RNWF_AP_DISABLE None Disables the SoftAP mode
RNWF_SET_WIFI_AP_CHANNEL Channel number Configure the Wi-Fi channel
RNWF_SET_WIFI_BSSID BSSID of AP (String) Configure the Access point's BSSID to which RNWF needs to connect

RNWF_SET_WIFI_TIMEOUT

Seconds (int) Configure Wi-Fi connection timeout
RNWF_SET_WIFI_HIDDEN, true or false Configure Hidden mode SSID in SoftAP mode
RNWF_WIFI_PASSIVE_SCAN None Request/Trigger Wi-Fi passive scan
RNWF_WIFI_ACTIVE_SCAN None Request/Trigger Wi-Fi active scan
RNWF_WIFI_SET_CALLBACK Callback Function handler Register the call back for async events
The following list captures the Wi-Fi callback event codes and their arguments
Table 3-3. Callback Event Codes
Event Response Components Comments
RNWF_CONNECTED Association ID: Integer

Connected State: Integer

Wi-Fi connected event code. Reports the connection's Association ID and connected state
RNWF_DISCONNECTED Association ID: Integer

Connected State: Integer

Wi-Fi disconnected event code
RNWF_CONNECT_FAILED Fail event code: Integer Wi-Fi connection failure event code
RNWF_DHCP_DONE DHCP IP: String Wi-Fi DHCP complete event code
RNWF_SCAN_INDICATION RSSI: Received signal strength

Sec Type (Int): Recommended security type to use connecting to this AP (10 options)

Channel (Int): Channel # of device
BSSID (String): BSSID of detected device
SSID (String): SSID of detected device

Scan results to report each scan list
RNWF_SCAN_DONE None Scan complete event code
The following figure illustrates the Station mode connection sequence
Figure 3-25. Station Mode Connection Sequence
Figure 3-26. Process Flow for Creating a Soft AP
Figure 3-27. Scan Operation Sequence

Following is the example of establishing connection in the Station mode

#include <stdio.h>

#include <rnwf_wifi_service.h>

void APP_WIFI_Callback(RNWF_WIFI_EVENT_t event, uint8_t *p_str)
{        
    switch(event)
    {
        case RNWF_CONNECTED:
            printf("Wi-Fi Connected\n");            
            break;
        case RNWF_DISCONNECTED:
            printf("Wi-Fi Disconnected\nReconnecting... \n");
            RNWF_WIFI_SrvCtrl(RNWF_STA_CONNECT, NULL);
            break;
        case RNWF_DHCP_DONE:
            printf("DHCP IP:%s\n", p_str);                           
            break;
        default:
            break;                    
    }    
}

int main(void)
{
    RNWF_WIFI_PARAM_t wifi_sta_cfg = {RNWF_WIFI_MODE_STA, "HomeAP", "12345678", RNWF_WPA2, True};

    RNWF_WIFI_SrvCtrl(RNWF_WIFI_SET_CALLBACK, APP_WIFI_Callback);

    RNWF_WIFI_SrvCtrl(RNWF_SET_WIFI_PARAMS, &wifi_sta_cfg);

    while(True)
    {
	RNWF_EVENT_Handler();
    }
}