Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the meaning of Rssi in android WifiManager

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?

like image 526
erik Avatar asked Nov 07 '12 17:11

erik


2 Answers

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.

EDIT API 30+

The static method is now deprecated and you should use the instance method

wifiManager.calculateSignalLevel(rssi)

Major difference is that the number of levels is now given by wifiManager.getMaxSignalLevel()

like image 61
ben75 Avatar answered Sep 18 '22 13:09

ben75


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.

like image 39
PravinCG Avatar answered Sep 19 '22 13:09

PravinCG