Connect to strongest access point (access point with the strongest signal) with the same SSID

◇◆丶佛笑我妖孽 提交于 2019-12-24 00:37:54

问题


I am writing a program to always connect to the strongest access point. I mean the access point with the strongest signal. First I scan all the available WiFi networks and then I restrict them to see just the ones with the same SSID.

So I can see all the APs of one network. When I connect to that network it doesn't connect to the strongest signal but I want it to switch to the strongest AP signal. By

WifiManager.compareSignalLevel(bestSignal.level, connectedAP.level) <0  

I understand the best signal.

if(WifiManager.compareSignalLevel(bestSignal.level, connectedAP.level) <0){

}

The question is what should I do in this if function to connect to the strongest AP(the AP with the strongest signal)?

Below is my code but there is no way to add the signal to it:

    WifiConfiguration conf = new WifiConfiguration();
                 conf.SSID = "\"" + bestSignal.SSID + "\"";
            // I want to connect to the access point with signal bestSignal.level
            //how is it possible?



                conf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
                wifiManager.addNetwork(conf);
                List<WifiConfiguration> list =wifiManager.getConfiguredNetworks();
                for( WifiConfiguration i : list ) {
                    if(i.SSID != null && 
                            i.SSID.equals("\"" + bestSignal.SSID + "\"")) {
                        wifiManager.disconnect();
                        wifiManager.enableNetwork(i.networkId, true);
                        wifiManager.reconnect();

                        break;
                    }
                }

回答1:


You should also add BSSID with the conf. Even though different networks have same SSIDs, they will have different BSSID. Adding that line will do.

WifiConfiguration conf = new WifiConfiguration();
             conf.SSID = "\"" + bestSignal.SSID + "\"";
             conf.BSSID= "\"" + bestSignal.BSSID+ "\"";


来源:https://stackoverflow.com/questions/41788364/connect-to-strongest-access-point-access-point-with-the-strongest-signal-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!