0

I am using the following code in wpa_supplicant for getting the signal strength of wifi in Android. I am able to get linkspeed but signal strength is always showing -110dB, although router is 1 meter away.

Code:

  if ((os_strcasecmp(cmd, "rssi") == 0) || (os_strcasecmp(cmd, "rssi-approx") == 0)) {
        struct iwreq wrq;
        struct iw_statistics stats;
        signed int rssi;
        wpa_printf(MSG_DEBUG, ">>>. DRIVER AWEXT RSSI ");
        wrq.u.data.pointer = (caddr_t) &stats;
        wrq.u.data.length = sizeof(stats);
        wrq.u.data.flags = 1; /* Clear updated flag */
        os_strncpy(wrq.ifr_name, drv->wext->ifname, IFNAMSIZ);

        if (ioctl(drv->wext->ioctl_sock, SIOCGIWSTATS, &wrq) < 0) {
            perror("ioctl[SIOCGIWSTATS]");
            ret = -1;
        } else {
            if (stats.qual.updated & IW_QUAL_DBM) {
                /* Values in dBm, stored in u8 with range 63 : -192 */
                rssi = ( wrq.u.qual.level > 63 ) ?
                    wrq.u.qual.level - 0x100 :
                    wrq.u.qual.level;
            } else {
                rssi = wrq.u.qual.level;
            }

            if (drv->ssid_len != 0 && drv->ssid_len < buf_len) {
                os_memcpy((void *) buf, (void *) (drv->ssid),
                        drv->ssid_len );
                ret = drv->ssid_len;
                ret += snprintf(&buf[ret], buf_len-ret,
                        " rssi %d\n", rssi);
                if (ret < (int)buf_len) {
                    return( ret );
                }
                ret = -1;
            }
        }
    }
4

1 に答える 1

0

次のコードは、wifi 強度の RSSI 値を提供します...

これがあなたを助けることを願っています.....

public class Wifi2 extends Activity{

    Context context; 

  @Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);


    context=this;
}   

  @Override
  public void onResume() {
      super.onResume();
      //Note: Not using RSSI_CHANGED_ACTION because it never calls me back.
      IntentFilter rssiFilter = new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
      this.registerReceiver(myRssiChangeReceiver, rssiFilter);

      WifiManager wifiMan=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
      wifiMan.startScan();
  }


      @Override
  public void onPause() {
      super.onPause();
      this.unregisterReceiver(myRssiChangeReceiver);

  }
  /**
   * Broadcast receiver to update 
   * s
   */
  private BroadcastReceiver myRssiChangeReceiver
          = new BroadcastReceiver(){
      @Override
      public void onReceive(Context arg0, Intent arg1) {
          WifiManager wifiMan=(WifiManager)context.getSystemService(Context.WIFI_SERVICE);
          wifiMan.startScan();
          int newRssi = wifiMan.getConnectionInfo().getRssi();
          Toast.makeText(context, ""+newRssi, Toast.LENGTH_SHORT).show();

  }};

}
于 2012-12-20T13:16:02.287 に答える