I am trying to properly read the RSSI of a BLE device I am connected to in order to send it to an upstream server.
I found that the RSSI returned by BluetoothGatt.readRemoteRssi()
has a lot of "jumps". I started doing a running average (over the last 10 seconds) to get a more smooth value. This did not help as the value had a lot of spikes.
I found that doing mBluetoothAdapter.startLeScan(null);
makes the values smoother. I know that the official documentation discourages from scanning while being connected to a device, but in practice - on an LG and Samsung devices it does work.
Further on - if I pass null
as the callback, this method should do nothing (see https://github.com/aosp-mirror/platform_frameworks_base/blob/master/core/java/android/bluetooth/BluetoothAdapter.java#L2833). Which leads me to believe that Samsung and LG do modify the Android Bluetooth stack a lot.
Can anyone explain what am I seeing? Can anyone offer a better solution for reading "real" RSSI values?
edit:
I found that onCharasteristicWritten()
is called several (?) times with the same value, even tough the HW did send it only once. We are filtering those values manually right now. Also onRssiRead()
is called several times.
This may be the reason why Android documentation suggests not scanning while connected to a BT device.