问题
I am trying to get the signal strength of the current wifi connection using getRssi()
private void checkWifi(){
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo Info = cm.getActiveNetworkInfo();
if (Info == null || !Info.isConnectedOrConnecting()) {
Log.i("WIFI CONNECTION", "No connection");
} else {
int netType = Info.getType();
int netSubtype = Info.getSubtype();
if (netType == ConnectivityManager.TYPE_WIFI) {
wifiManager = (WifiManager)getApplicationContext().getSystemService(Context.WIFI_SERVICE);
int linkSpeed = wifiManager.getConnectionInfo().getLinkSpeed();
int rssi = wifiManager.getConnectionInfo().getRssi();
Log.i("WIFI CONNECTION", "Wifi connection speed: "+linkSpeed + " rssi: "+rssi);
//Need to get wifi strength
}
}
}
thing is i get numbers like -35 or -47 ect.. and i don't understand their values.. I have looked at the android documentation and all it states:
public int getRssi ()
Since: API Level 1 Returns the received signal strength indicator of the current 802.11 network.
This is not normalized, but should be!
Returns the RSSI, in the range ??? to ???
can someone explain how to 'normalize' or understand these results?
回答1:
According to IEEE 802.11 documentation: Lesser negative values denotes higher signal strength.
The range is between -100 to 0 dBm, closer to 0 is higher strength and vice-versa.
回答2:
I found this in WifiManager.java :
/** Anything worse than or equal to this will show 0 bars. */
private static final int MIN_RSSI = -100;
/** Anything better than or equal to this will show the max bars. */
private static final int MAX_RSSI = -55;
Relevant rssi range on android is betwwen -100 and -55.
There is this static method WifiManager.calculateSignalLevel(rssi,numLevel) that will compute the signal level for you :
int wifiLevel = WifiManager.calculateSignalLevel(rssi,5);
is returning a number between 0 and 4 (i.e. numLevel-1) : the number of bars you see in toolbar.
回答3:
From wikipedia:
Vendors provide their own accuracy, granularity, and range for the actual power (measured as mW or dBm) and their range of RSSI values (from 0 to RSSI_Max).
As an example, Cisco Systems cards have a RSSI_Max value of 100 and will report 101 different power levels, where the RSSI value is 0 to 100. Another popular Wi-Fi chipset is made by Atheros. An Atheros based card will return an RSSI value of 0 to 127 (0x7f) with 128 (0x80) indicating an invalid value.
So this is strongly depends of equipment.
回答4:
starting from ben75's answer, we can use this method to normalize rssi:
public static int normalizeRssi(int rssi){
// Anything worse than or equal to this will show 0 bars
final int MIN_RSSI = -100;
// Anything better than or equal to this will show the max bars.
final int MAX_RSSI = -55;
int range = MAX_RSSI - MIN_RSSI;
return 100 - ((MAX_RSSI - rssi) * 100 / range);
}
来源:https://stackoverflow.com/questions/13275306/whats-the-meaning-of-rssi-in-android-wifimanager