What's the meaning of Rssi in android WifiManager

 ̄綄美尐妖づ 提交于 2019-12-04 19:41:17

问题


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

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