1

I am creating an app that has a background service which continuously gets the WiFi RSSI using the getRssi() method and decides what it should do depending on the value.

The service is running OK, however, when the screen is locked the service stops updating the value of RSSI, instead, it gets stuck with the last value read before locking the screen.

I tried holding a partial WakeLock but unfortunately it has no effect.

In the OnStartCommand of the service I added the wake lock as follows :

wifi =(WifiManager)getApplicationContext().getSystemService(WIFI_SERVICE);
    PowerManager pm = (PowerManager)getSystemService(POWER_SERVICE);
            PowerManager.WakeLock wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyLock");
            wakeLock.acquire();
info = wifi.getConnectionInfo();
            RSSI = info.getRssi();
            System.out.println(RSSI);

I added the Wake Lock permission to the manifest :

<uses-permission android:name="android.permission.WAKE_LOCK" />

Have anyone had a similar problem?

What is the reason behind this?

10
  • Have you found the solution? I have faced the same issue and still no problem! Please let me know if have any working solution.
    – DeFoG
    Commented Dec 25, 2017 at 18:29
  • Unfortunately I couldn't find any solution, I even tried scanning wifi and get the RSSI of the network I'm connected to , but with no luck. Commented Dec 25, 2017 at 22:09
  • 1
    For me I found a solution by making the access point read the RSSI of the client, not the other way around, and that was possible because my access point is an ESP8266 chip which you can get the RSSI of a client if the client sends a probe request, however, that means your android device should always be scanning, and that might have a bad impact on the battery. Commented Dec 25, 2017 at 22:13
  • 1
    To sum it up : I made the access point read the RSSI of the packet it receives from a client. Another thing I probably should mention is that the values of RSSI vary from one device to another, because it is not the actual received power but rather an "indication", so each manufacturer implement it their own way, without a standard or obligations, so you won't be having very useful data if you rely on RSSI. Commented Dec 27, 2017 at 1:01
  • 1
    Regarding MicroPython I'm not sure about that but I think it won't work for the same reason C libraries. ESP chips can get RSSI when they operate in AP mode, however, they can only get RSSI if they receive a specific frame, which is a probe request. In case you don't know, a probe request is a special frame that devices(in this case your android device)send when they scan for wifi networks, so basically if your android device scans wifi networks and you have an ESP in the range, the ESP can determine the RSSI of the probe request. Commented Dec 28, 2017 at 3:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.