Titanium module for exposing Androids's WifiManager. The module can list the configured networks, can browse all access points. The module can connect to new AP. It supports WEP, WPA (PSK and Enterprise). The button method of WPS will supported.
Thanks to Jean-RenΓ© Auger and Appwapp for sponsoring.
You need ACCESS_WIFI_STATE permission. Some functions need CHANGE_WIFI_STATE and CHANGE_WIFI_MULTICAST_STATE.
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.pemissions.OVERRIDE_WIFI_CONFIG" />
The location permission is critical, you need a runtime permission!
var WM = require("ti.wifimanager");
var Wifi = require("ti.wifimanager");
Wifi.startWifiScan({
complete : function(scanned) {
console.log("runtime="+ scanned.runtime);
if (scanned.scanResults) {
scanned.scanResults.forEach(function(scanResult) {
if (scanResult) {
console.log("bssid=" + scanResult.getBSSID() + " rssi=" + scanResult.getRSSI() + " ssid=" + scanResult.getSSID());
}
}
});
Typical result:
[
{"timestamp":388418592430,"ssid":"Elysium","bssid":"38:10:d5:cf:bd:0e","wps":true,"rssi":"-51","security":"PSK","freq":"5240"}
{"timestamp":388418592418,"ssid":"Elysium","bssid":"38:10:d5:cf:bd:0d","wps":true,"rssi":"-47","security":"PSK","freq":"2437"}
{"timestamp":388418592444,"ssid":"o2-WLAN93","bssid":"1c:74:0d:27:92:f1","wps":true,"rssi":"-57","security":"PSK","freq":"2442"}
{"timestamp":388418592455,"ssid":"o2-WLAN93","bssid":"1c:74:0d:27:92:f2","wps":true,"rssi":"-63","security":"PSK","freq":"5180"}
{"timestamp":388418592477,"ssid":"o2-WLAN77","bssid":"88:03:55:10:b2:07","wps":true,"rssi":"-67","security":"PSK","freq":"2467"}
{"timestamp":388418592398,"ssid":"WILHELM.TEL-YWY52M7T","bssid":"34:31:c4:e4:2a:0e","wps":true,"rssi":"-43","security":"PSK","freq":"2422"}
{"timestamp":388418592466,"ssid":"WLAN-309178","bssid":"94:4a:0c:74:57:c3","wps":true,"rssi":"-69","security":"PSK","freq":"2412"}
{"timestamp":388418592510,"ssid":"WILHELM.TEL-J52R996K","bssid":"08:96:d7:02:2f:e4","wps":true,"rssi":"-89","security":"PSK","freq":"2462"}
{"timestamp":388418592499,"ssid":"HP-Print-6C-Photosmart 6520","bssid":"64:51:06:da:66:6c","wps":false,"rssi":"-88","security":"PSK","freq":"2437"}
{"timestamp":388418592489,"ssid":"WILHELM.TEL-267875C4","bssid":"5c:49:79:66:6a:0c","wps":true,"rssi":"-80","security":"PSK","freq":"2412"}
]
- getBSSID()
- getSSID()
- getFrequency()
- getSecurity()
- getTimes()
- gethasWPS()
- getRSSI()
- toString()
- setPassword()
var Wifi = require("ti.wifimanager");
Wifi.getConfiguredNetworks().forEach(function(saved) {
console.log(saved);
});
Typical result:
[
{"priority":1,"SSID":"Ringelnetz","status":2,"id":11,"hidden":false,"BSSID":null}
{"priority":1,"SSID":"IKEA WiFi","status":2,"id":72,"hidden":false,"BSSID":null}
{"priority":1,"SSID":"Airport_Free_WiFi","status":2,"id":53,"hidden":false,"BSSID":null}
{"priority":1,"SSID":"ROCKSTART","status":2,"id":37,"hidden":false,"BSSID":null}
{"priority":1,"SSID":"asian beauty salon","status":2,"id":36,"hidden":false,"BSSID":null}
{"priority":1,"SSID":"Tinkerforge","status":2,"id":71,"hidden":true,"BSSID":null}
{"priority":1,"SSID":"FreeWifi","status":2,"id":23,"hidden":false,"BSSID":null}
{"priority":1,"SSID":"TOURO","status":2,"id":54,"hidden":false,"BSSID":null}
{"priority":1,"SSID":"akanoo_guest","status":2,"id":42,"hidden":false,"BSSID":null}
{"priority":1,"SSID":"francesco","status":2,"id":55,"hidden":false,"BSSID":null}
{"priority":1,"SSID":"GUEST@ROCKSTART","status":2,"id":52,"hidden":false,"BSSID":null}
var Wifi = require("ti.wifimanager");
var networkId = Wifi.addNetwork({
bssid : "f8:4f:57:37:f4:2f",
security : "PSK", // optional, in most case automatic
password : "sagichdirnicht",
persist : true // is default
});
Alternativly you can use a scanResult to add a network:
var networkId = Wifi.addNetwork(scanResult.setPasswort("seehrGehe1m,kommtkeinerdrauf"));
In case of enterprise WPA you need additional a name
:
var Wifi = require("ti.wifimanager");
var AP = Wifi.addNetwork({
BSSID : "f8:4f:57:37:f4:2f",
name : "DigitalTransformationOfficer"
password : "sagichdirnicht"
});
var Wifi = require("ti.wifimanager");
Wifi.enableNetwork({
netId : netId,
change : function() {
// Hurra!
});
});
Wifi.addEventListener("change",function(event){
if (event.online == true) {
// Hurra!
}
});
You can use for callback the property in method or the event listener.
var Wifi = require("ti.wifimanager");
Wifi.startWPS({
setup : Wifi.WPS_PBC,
onconnected : function() {
},
onerror : function() {
},
})
var Wifi = require("ti.wifimanager");
Wifi.startWPS({
setup : Wifi.WPS_PIN,
onstarted : function(pin) {
alert(pin);
},
onconnected : function() {
},
onerror : function() {
},
})
- WM.ACTION_PICK_WIFI_NETWORK
Activity Action: Pick a Wi-Fi network to connect to.
- WM.ACTION_REQUEST_SCAN_ALWAYS_AVAILABLE
_Activity Action: Show a system activity that allows the user to enable scans to be available even with Wi- turned off. _
- WM.CONFIG_STATUS_CURRENT
This is the network we are currently connected to
- WM.CONFIG_STATUS_DISABLED
_supplicant will not attempt to use this network
- WM.CONFIG_STATUS_ENABLED
_supplicant will consider this network available for association
- WM.WIFI_STATE_ENABLED
- WM.WIFI_STATE_DISABLED
- WM.WIFI_STATE_ENABLING
- WM.WIFI_STATE_DISABLING
- removeNetwork(networkId)
- removeAllNetworks()
Result:
- SSID
- BSSID
- IP-Address
- LinkSpeed
- MacAddress
- RSSI
- securityMode (OPEN, WEP, PSK, EAP)
Return the results of the latest access point scan
Result:
- BSSID
- SSID
- securityMode
- level
- frequency
- channelWidth
- timestamp
- status (WM.WifiConfiguration.STATUS_CURRENT,WM.WifiConfiguration.STATUS_ENABLED,WM.WifiConfiguration.STATUS_DISABLED)
- isPasspointNetwork
- is80211mcResponder
- capabilities
- venueName
- operatorFriendlyName
- MW.saveConfiguration() // to persist new configuration
- MW.is5GHzBandSupported()
- MW.isDeviceToApRttSupported()
- MW.isLocationServiceEnabled();
- MW.isEnhancedPowerReportingSupported()
- MW.isP2pSupported()
- MW.isPreferredNetworkOffloadSupported()
- MW.isTdlsSupported()
- MW.isScanAlwaysAvailable()
var wifiConfiguration = MW.createWifiConfiguration({
BSSID : BSSID,
secret : "WEPKEY_or_WPAsharedSecfret"
});
var configuration = MW.createWifiConfiguration({
BSSID : BSSID,
secret : "WEPKEY_or_WPAsharedSecfret"
});
MW.isValidWEPKey();
MW.isValidBSSID();
The WifiManager holds internally a list of network configurations (with "passwords").
With this method WM.getConfiguredNetworks()
can you read all:
var networks = WM.getConfiguredNetworks();
for (var i =0; i< networks.length;i++) {
console.log(networks[i].toJSON());
}
Result:
- networkId
- SSID
- BSSID
- priority
- allowedProtocols
- allowedKeyManagement
- allowedAuthAlgorithms
- allowedPairwiseCiphers
- allowedGroupCiphers
You can extend this by adding a new WifiConfiguration creating a new one
var myConf = WM.createWifiConfiguration({
ssid : ssid
sharedKey : "geheim", // for wpa
wepKey : "2423A2E4" // for wep
});
and adding:
WM.addConfiguration(myConf);
Before you can add a new access point, you need SSID. For this you can get it by:
// Return the results of the latest access point scan
var networks = WM.getScanResults();
for (var i =0; i< networks.length;i++) {
console.log(networks[i]);
}
Result:
- BSSID
- SSID
- securityMode
- level
- frequency
- channelWidth
- timestamp
- isPasspointNetwork
- is80211mcResponder
- capabilities
- venueName
- operatorFriendlyName
WM.startWPS({
setup : WM.WPS_PBC,
onconnect : function() {
console.log("Hurra!");
},
onerror : function(){}
});
WM.startWPS({
setup : WM.WPS_PIN,
onadded : function(pin) {
alert("Please add this pin " + pin + " to your AccessPoint");
}
onconnect : function() {
console.log("Hurra!");
},
onerror : function(){}
});
During connecting you can cancel the process with:
WM.cancelWPS();