Hello,
I'm working in an application that (among other things) will connect to an specific device that is acting as an open Wifi Access Point and send some configuration commands to it.
I'm currently creating the configuration for the network:
WifiConfiguration config = new WifiConfiguration();
config.BSSID = bssid;
config.priority= 40;
config.status = WifiConfiguration.Status.ENABLED;
config.SSID = "\""+ssid+"\"";
config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
config.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
config.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
config.allowedAuthAlgorithms.clear();
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
config.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP40);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.WEP104);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
and then using WifiManager to add the network configuration to the config list:
WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
int id = wm.addNetwork(config);
Now, I take this id and enable the network, disabling all the others:
wm.enableNetwork(id,true);
And reconnect:
wm.reconnect();
Now, this generally works, but the results are very inconsistent. Sometimes it will take 2 seconds for it to go from connected to disconnected to connected to the new AP. However, it would sometimes take 30 or more seconds, and I've seen cases where it takes up to 2 minutes. Sometimes, it just hangs there and connects to the mobile network since it was unable to connect to wifi. Both my phone and the AP I'm connecting to are resting side-by-side on the desk, so I wouldn't think the signal level is a problem.
Is there something I am missing? Or, is there a better way to do this than using the WifiManager API?
Thanks in advance.
Jorge Rivera (jriverag, in IRC)