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/CommandInputDescription
RNWF_SET_WIFI_PARAMSMode, SSID, Passphrase, Security, AutoenableConfigures the provided Wi-Fi details and Triggers the connection based on auto enable flag
RNWF_STA_CONNECTNoneTriggers the Wi-Fi STA connection
RNWF_STA_DISCONNECTNoneDisconnects the connection
RNWF_AP_DISABLENoneDisables the SoftAP mode
RNWF_SET_WIFI_AP_CHANNELChannel numberConfigure the Wi-Fi channel
RNWF_SET_WIFI_BSSIDBSSID 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 falseConfigure Hidden mode SSID in SoftAP mode
RNWF_WIFI_PASSIVE_SCANNoneRequest/Trigger Wi-Fi passive scan
RNWF_WIFI_ACTIVE_SCANNoneRequest/Trigger Wi-Fi active scan
RNWF_WIFI_SET_CALLBACKCallback Function handlerRegister 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
EventResponse ComponentsComments
RNWF_CONNECTEDAssociation ID: Integer

Connected State: Integer

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

Connected State: Integer

Wi-Fi disconnected event code
RNWF_CONNECT_FAILEDFail event code: IntegerWi-Fi connection failure event code
RNWF_DHCP_DONEDHCP IP: StringWi-Fi DHCP complete event code
RNWF_SCAN_INDICATIONRSSI: 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_DONENoneScan complete event code
RNWF_SNTP_UPNTP Time: StringTime received from NTP server
The following figure illustrates the Station mode connection sequence
Figure 3-13. Station Mode Connection Sequence
Figure 3-14. Process Flow for Creating a Soft AP
Figure 3-15. 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();
    }
}