Wifi

The WiFi API provides an interface to find available WiFi networks and handle connecting and disconnecting the device from those networks.

Usage
Wifi.getConnectedSSID()
    .then(function(result) {
        console.log( result);
    })
    .catch(function(e) {
        console.error('Unable to get current SSID');
    });

...

Wifi.getWifiIPInfo()
    .then(function(result) {
        console.log(result.ip);
        console.log(result.subnet);
    })
    .catch(function(e) {
        console.error('Unable to get current IP Info');
    });
window.Wifi.getConnectedSSID()
    .then(function (result) {
        console.log(result);
    })
    .catch(function (e) {
        console.error("Unable to get current SSID");
    });

...

window.Wifi.getWifiIPInfo()
    .then(function (result) {
        console.log(result.ip);
        console.log(result.subnet);
    })
    .catch(function (e) {
        console.error("Unable to get current IP Info");
    });
window.Wifi.getConnectedSSID()
    .then(function (result) {
        console.log(result);
    })
    .catch(function (e) {
        console.error("Unable to get current SSID");
    });
                    
...
    
window.Wifi.getWifiIPInfo()
    .then(function (result) {
        console.log(result.ip);
        console.log(result.subnet);
    })
    .catch(function (e) {
        console.error("Unable to get current IP Info");
    });
(<any>window).Wifi.getConnectedSSID()
    .then(function (result) {
        console.log(result);
    })
    .catch(function (e) {
        console.error("Unable to get current SSID");
    });

...

(<any>window).Wifi.getWifiIPInfo()
    .then(function (result) {
        console.log(result.ip);
        console.log(result.subnet);
    })
    .catch(function (e) {
        console.error("Unable to get current IP Info");
    });
window.Wifi.getConnectedSSID()
    .then(function (result) {
        console.log(result);
    })
    .catch(function (e) {
        console.error("Unable to get current SSID");
    });

...

window.Wifi.getWifiIPInfo()
    .then(function (result) {
        console.log(result.ip);
        console.log(result.subnet);
    })
    .catch(function (e) {
        console.error("Unable to get current IP Info");
    });

Classes


Wifi

getConnectedSSID
getConnectedSSID(): Promise<string>

Returns connected network SSID.


RETURN
returns: Promise <string>
PERMISSIONS

This method requires LOCATION Permission set on Fawi Office - publish settings.

getConnectedBSSID
getConnectedBSSID(): Promise<string>

Same as above, except BSSID (mac) is returned.


RETURN
returns: Promise <string>
PERMISSIONS

This method requires LOCATION Permission set on Fawi Office - publish settings.

connect
connect(ssid: string, bindAll: boolean, password: string, algorithm: string, isHiddenSSID: boolean): Promise<any>

Connect network with specified SSID.

This method will first add the wifi configuration, then enable the network, returning promise when connection is verified.


PARAMETERS
ssid: string
bindAll: boolean
password: string
algorithm: string
isHiddenSSID: boolean

RETURN
returns: Promise <any>
disconnect
disconnect(ssid: string): Promise<any>

Disconnect (current if SSID not supplied)

This method, if passed an SSID, will first disable the network, and then remove it from the device. To only "disconnect", call Wifi.disable() instead of disconnect.


PARAMETERS
ssid: string

RETURN
returns: Promise <any>
formatWifiConfig
formatWifiConfig(ssid: string, bindAll: boolean, password: string, algorithm: string, isHiddenSSID: boolean): Promise<any>

Same as above for Connect, except in this situation, disconnect will first disable the network, and then attempt to remove it (if SSID is passed).


PARAMETERS
ssid: string
bindAll: boolean
password: string
algorithm: string
isHiddenSSID: boolean

RETURN
returns: Promise <any>
formatWPAConfig
formatWPAConfig(ssid: string, password: string, isHiddenSSID: boolean): Promise<any>

A helper method that calls formatWifiConfig


PARAMETERS
ssid: string
password: string
isHiddenSSID: boolean

RETURN
returns: Promise <any>
add
add(wifi: WifiOptions): Promise<any>

Add wifi network configuration.


PARAMETERS
wifi: WifiOptions

RETURN
returns: Promise <any>
remove
remove(ssid: string): Promise<any>

Remove wifi network configuration.


PARAMETERS
ssid: string

RETURN
returns: Promise <any>
listNetworks
listNetworks(): Promise<any>

RETURN
returns: Promise <any>
scan
scan(options?): Promise<any>

PARAMETERS
option[optional]: { numLevels: n }
  • if (n == true || n < 2) -> getScanResults({numLevels: n}) will return data as before, split in 5 levels;
  • if (n > 1) -> .getScanResults({numLevels: n}) will calculate the signal level, split in n levels;
  • if (n == false) -> getScanResults({numLevels: n}) will use the raw signal level;

RETURN
returns: Promise <any>
startScan
startScan(): Promise<any>

RETURN
returns: Promise <any>
getScanResults
getScanResults(options?): Promise<ScanResult>

PARAMETERS
option[optional]: { numLevels: n }
  • if (n == true || n < 2) -> getScanResults({numLevels: n}) will return data as before, split in 5 levels;
  • if (n > 1) -> .getScanResults({numLevels: n}) will calculate the signal level, split in n levels;
  • if (n == false) -> getScanResults({numLevels: n}) will use the raw signal level;

RETURN
returns: Promise <ScanResult>
PERMISSIONS

This method requires LOCATION Permission set on Fawi Office - publish settings.

isWifiEnabled
isWifiEnabled(): Promise<boolean>

RETURN
returns: Promise <boolean>
setWifiEnabled
setWifiEnabled(option: boolean): Promise<any>

PARAMETERS
option: boolean

RETURN
returns: Promise <any>
getConnectedNetworkID
getConnectedNetworkID(): Promise<int>

RETURN
returns: Promise <int>
resetBindAll
resetBindAll(): Promise<int>

RETURN
returns: Promise <int>
setBindAll
setBindAll(): Promise<int>

RETURN
returns: Promise <int>
canConnectToInternet
canConnectToInternet(): Promise<int>

RETURN
returns: Promise <int>
canConnectToRouter
canConnectToRouter(): Promise<boolean>

RETURN
returns: Promise <boolean>
isConnectedToInternet
isConnectedToInternet(): Promise<boolean>

RETURN
returns: Promise <boolean>
isConnectedToInternet
isConnectedToInternet(): Promise<boolean>

RETURN
returns: Promise <boolean>
canPingWifiRouter
canPingWifiRouter(): Promise<boolean>

RETURN
returns: Promise <boolean>
enableWifi
enableWifi(): Promise<any>

RETURN
returns: Promise <any>
disableWifi
disableWifi(): Promise<any>

RETURN
returns: Promise <any>
getWifiIP
getWifiIP(): Promise<string>

RETURN
returns: Promise <string>
getWifiRouterIP
getWifiRouterIP(): Promise<string>

RETURN
returns: Promise <string>
getWifiIPInfo
getWifiIPInfo(): Promise<GetWifiInfoResult>

RETURN
returns: Promise <GetWifiInfoResult>
reconnect
reconnect(): Promise<string>

RETURN
returns: Promise <string>
reassociate
reassociate(): Promise<string>

RETURN
returns: Promise <string>
getSSIDNetworkID
getSSIDNetworkID(ssid: string): Promise<string>

PARAMETERS
ssid: string

RETURN
returns: Promise <string>
disable
disable(ssid: string): Promise<string>

PARAMETERS
ssid: string

RETURN
returns: Promise <string>
requestPermission
requestPermission(): Promise<any>

RETURN
returns: Promise <any>
enable
enable(ssid: string, bindAll: boolean, waitForConnection: boolean): Promise<any>

PARAMETERS
ssid: string
bindAll: boolean
waitForConnection: boolean

RETURN
returns: Promise <any>
timeout
timeout(delay? : int): Promise<any>

Helper async timeout delay, delay is optional, default is 2000ms = 2 seconds


PARAMETERS
delay: int time in milliseconds to delay

RETURN
returns: Promise <any>

Interfaces Used

WifiOptions

interface WifiOptions {
    ssid: string,
    isHiddenSSID: boolean,
    auth:{
        password: string,
        algorithm: string
    } 
}

ScanResult

interface ScanResult {
    // Raw RSSI value
    "level": int,
    // SSID as string, with escaped double quotes: "\"ssid name\""
    "SSID": string,
    // MAC address of WiFi router as string
    "BSSID": string,
    "frequency": int,
    // // Describes the authentication, key management, and encryption schemes supported by the access point
    "capabilities": string,
    // Timestamp of when the scan was completed
    "timestamp": int 
    "channelWidth": int,
    "centerFreq0": int,
    "centerFreq1": int
}

GetWifiInfoResult

interface GetWifiInfoResult {
    "ip": string,
    "subnet": string
}