3.1.7.1 Wi-Fi Service
The Wi-Fi service provides API’s to enable the following features:
- Station mode
- 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.Option/Command | Input | Description |
---|---|---|
RNWF_SET_WIFI_PARAMS | Mode, SSID, Passphrase, Security, Auto-connect | 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 |
| 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 |
RNWF_GET_WIFI_REGDOM | String to receive available regulatory domain values | Query available Wi-Fi Regulatory Domains |
RNWF_SET_WIFI_REGDOM | Regulatory domain value to set (String) | Configure the Wi-Fi Regulatory Domain |
RNWF_WIFI_SET_COEX | Co-Ex Enable/disable, Interface type, WLAN RX Priority, WLAN TX Priority, Antenna Mode | Configure Wi-Fi Bluetooth Co-existence (Co-Ex) |
RNWF_SET_WIFI_PSM | true or false (Wi-Fi Power Save Mode - ON/OFF) | Wi-Fi Power Save Mode ON |
RNWF_WIFI_PING_ENBL | Ping IP address (String) | Enable Wi-Fi Ping support |
The following list captures the Wi-Fi callback event codes and their arguments
Event | Response Components | Comments |
---|---|---|
RNWF_DHCP_LINK_LOCAL_IPV6_DONE | DHCP IPv6 (Local): String | Wi-Fi DHCP IPv6 (Local) address received event code |
RNWF_DHCP_GLOBAL_IPV6_DONE | DHCP IPv6 (Global): String | Wi-Fi DHCP IPv6 (Global) address received event code |
RNWF_SET_REGDOM | None | Wi-Fi Set regulatory domain event code |
RNWF_SNTP_UP |
ID : Parameter ID number VAL: Parameter value |
SNTP time synchronization complete event code |
RNWF_PING_ERROR | Ping failure/error code: String | Wi-Fi Ping Error event code |
RNWF_PING_SUCCESS | None | Wi-Fi Ping Success event code |
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_IPV4_DONE | DHCP IPv4: String | Wi-Fi DHCP IPv4 address received 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 | Scan results to report each scan list |
RNWF_SCAN_DONE | None | Scan complete event code |
The following figure illustrates the Station mode connection sequence
Following is the example of establishing connection in the Station
mode
#include <stdio.h> /* This section lists other files that are included in this file.*/ #include "rnwf_app.h" #include "rnwf_wifi_service.h" #include "rnwf_interface.h" void APP_WIFI_Callback(RNWF_WIFI_EVENT_t event, uint8_t *p_str) { switch(event) { case RNWF_SNTP_UP: { break; } 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_IPV4_DONE: { printf("DHCP IPv4: %s\n", &p_str[2]); break; } case RNWF_DHCP_LINK_LOCAL_IPV6_DONE: { printf("DHCP link-local IPv6:%s\n", &p_str[2]); break; } case RNWF_DHCP_GLOBAL_IPV6_DONE: { printf("DHCP global IPv6:%s\n", &p_str[2]); break; } case RNWF_SET_REGDOM: { RNWF_WIFI_SrvCtrl(RNWF_SET_WIFI_REGDOM, (void *)COUNTRY_CODE); break; } case RNWF_SCAN_INDICATION: { break; } case RNWF_SCAN_DONE: { break; } case RNWF_CONNECT_FAILED: { break; } default: { break; } } } int main(void) { RNWF_WIFI_PARAM_t wifi_sta_cfg = {RNWF_WIFI_MODE_STA, HOME_AP_SSID, HOME_AP_PASSPHRASE, HOME_AP_SECURITY, STA_AUTOCONNECT}; RNWF_WIFI_SrvCtrl(RNWF_WIFI_SET_CALLBACK, APP_WIFI_Callback); RNWF_WIFI_SrvCtrl(RNWF_SET_WIFI_PARAMS, &wifi_sta_cfg); while(1) { RNWF_EVENT_Handler(); } }