使用相同的SSID连接到最强的接入点(信号最强的接入点) [英] Connect to strongest access point (access point with the strongest signal) with the same SSID
问题描述
我正在编写一个程序,以始终连接到最强的访问点。我的意思是信号最强的接入点。首先,我扫描所有可用的WiFi网络,然后将它们限制为仅看到具有相同SSID的WiFi网络。
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.
因此,我可以看到一个网络的所有AP。
当我连接到该网络时,它没有连接到最强的信号,但是我希望它切换到最强的AP信号。
By
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
我理解最好的信号。
if(WifiManager.compareSignalLevel(bestSignal.level, connectedAP.level) <0){
}
问题是如果功能连接到最强的AP(信号最强的AP),我该怎么办?
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;
}
}
推荐答案
您还应该在conf中添加BSSID。即使不同的网络具有相同的SSID,它们也将具有不同的BSSID。
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+ "\"";
这篇关于使用相同的SSID连接到最强的接入点(信号最强的接入点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!