I need to measure bluetooth signal between two or more mobile phones and detect nearest phone in range. After a lot of researching I came to idea to do periodically discovering for new bluetooth devices and measure rssi via EXTRA_RSSI that returned by ACTION_FOUND. All devices must be always in discovery mode and also must periodically scan for other devices.
Is this approach good or there are some better solution? What problems I can expect with this approach?
This solution Android 2.1: How do I poll the RSSI value of an existing Bluetooth connection? doesn't work for me because need phones to be rooted.
RSSI is a bad indicator for distance under real world conditions.
It could work under ideal conditions (free space propagation) but in reality you always have obstacles like walls, trees, etc. that affect the propagation.
See this article for more detailed information on propagation models.
RSSI doesn't indicate which phone is nearest, only which phone has the strongest signal.
Related
I want my android device to pick a BT device in range with a best RSSI and connect to it. Is there a way to implement such thing?
Ex: I have 5 ESP32-based devices around my house and need my phone to reconnect to the closest device (with a strongest RSSI). Is there a way to make app automatically pick the best RSSI from the available list of devices, terminate previous connection and reconnect to the device with best RSSI?
Your help is greatly appreciated. Thanks.
Yes this is definitely doable. All your app needs to do is the following:-
Scan for devices for a specific interval (e.g. 5 seconds).
Filter the scanned devices based on their name (i.e. you want to make sure that you only have the ESP32 devices and not other random Bluetooth devices).
Find the device with the best RSSI.
Connect to the device with the best RSSI.
If you want the process to be continuous, then go back to step 1.
However, keep in mind that RSSI does not always equate to distance/range. The device with the best RSSI might actually be further than other devices. The links below go over this plus some other useful data that you might need for your application:-
The ultimate guide to Android Bluetooth Low Energy
Using BLE for indoor positioning
Bluetooth LE RSSI for proximity detection
I have a BLE device (self made) that I pair with my app (iOS+Android).
I want to notify the user when the bluetooth signal is weak or better - when the device is about to disconnect.
Searching the web resulted with RSSI being the only value that is related to signal, yet I was unable to find a RSSI threshold that hints possible disconnection.
Is there a way to know?
Thanks a lot,
Giora.
The ability to connect to a BLE device with weak RSSI varies a lot depending on the phone you're using to connect to your device.
With some smartphones, especially those running on Android 8+, you might be able to stay connected to a BLE device advertising with a weak RSSI, whereas with some other smartphone, you're might have issue staying connected to a device with a strong RSSI.
It also depends on the quality of the BLE chip on your peripheral.
To answer your question, I would say you need to run some calibration tests, establishing the average RSSI at which your center or peripheral throws a disconnection, and start from there.
You'll need to calculate this average across several types of phones, including Android and iOS's, or, even better, set a threshold per OS.
I'm right now focusing on Android, but I believe the answers to these questions apply to any operating system, they just will use different functions to get the data.
Once I've established a BLE connection, I can BluetoothGatt.readRemoteRssi() to "Read the RSSI for a connected remote device."
First question: am I understanding this function correctly, it is returning to me the strength of the signal (transmitted from the remote BLE device) that my Android device is receiving, right? I think it's the function name that's throwing me off, shouldn't the name just be readRssi()? readRemoteRssi() makes me think there's a companion function readLocalRssi() somewhere.
Second question: assuming I am understanding the function correctly, is there anything built into Bluetooth that lets me ask "what is the remote BLE device seeing for RSSI?" In other words, of the signal that the Android device is transmitting, how much of that is reaching the remote BLE device?
ADDED LATER
Based on the answer I got, apparently I'm not explaining myself very well. Let me try again.
The remote BLE device is transmitting with a certain power, and those radio waves head out in all directions, and some of those waves are received by my mobile device. My mobile device measures how strong those waves are, and that's reported as RSSI. RSSI stands for "Received Signal Strength Indicator" and since it's the local mobile device that's doing the receiving, it seems strange to name the function "remote". Of course RSSI measures something coming from a remote transmitter - otherwise it wouldn't be very useful.
Similarly, the mobile device is transmitting with a certain power, and those radio waves head out in all directions, and some of those radio waves are received by the remote BLE device. That remote BLE device measures the strength of those waves, and that would be his RSSI. My second question is asking whether there's anything in the Bluetooth standard (a predefined characteristic, for example, like "Battery Level") that lets me mobile device query the remote BLE device and ask "Hey dude, how much signal you getting?"
am I understanding this function correctly, it is returning to me the strength of the signal
(transmitted from the remote BLE device) that my Android device is receiving, right?
Actually rssi is calculated by ble chip based on the advertising packets that are received from the remote device. We don't directly get the rssi value from remote device.
I think it's the function name that's throwing me off, shouldn't the name just be readRssi()?
No. We are actually reading remote device's rssi.
readRemoteRssi() makes me think there's a companion function readLocalRssi() somewhere.
No there is no such method as rssi is determined at the other end to which the current device is connected to.
assuming I am understanding the function correctly, is there anything built into Bluetooth that lets me ask "what is the remote BLE device seeing for RSSI?" In other words, of the signal that the Android device is transmitting, how much of that is reaching the remote BLE device?
It is rssi. It is calculated based on how many advertising packets received against total packets.
Note: some of my answers are my guess based on my experience.
I wanted to get the RSSI value to measure how far a device is from a handset...the problem I am currently facing is whether the RSSI value keeps on changing even after the devices are paired and also if can the value be directly used as short?
The RSSI value will fluctuate significantly.
It is proportional with distance, but it is affected by interference, and also by the 2 connected devices' power table (they might reduce their tx power if they are close).
That being said, RSSI will still appreciate with devices getting closer.
I preferred logging the RSSI data I receive on my other(embedded) device and sending it back to Android, showing it there. My embedded device has clear access to the Bluetooth stack, and so can get more accurate and more intense readings of the RSSI.
Ofc, getting the RSSI of the other device from Android should also work, but probably not so good (you have too many layers on top of the actual Bluetooth stack - linux bluez, then Android...).
I have my own graphing application for Bluetooth RSSI monitoring in Android, here are 2 printscreens from my app:
You can also look at Link Quality...this is another useful parameter(it it susceptible to duplications of the signal).
Here is a scientific paper on the subject.
so I'm trying my hand at android developing this summer. I was trying to make a sort of alarm app when a pair of connected devices go out of range of each other.
From looking around on the internet / stack overflow, it seems that looking at the RSSI value will help me achieve this.
However, it seems that the RSSI value can only be read at the time of connection with the device, that is it doesn't update itself (or there is no method to do so).
Is the RSSI value the only way to achieve my goal?
Would it be possible to use RemoteDevice and RemoteDeviceHelper? Has anyone tried this?
Any other suggestions and hints would be much appreciated
You could establish a connection with the device and exchange heartbeat information with the device , you can use the reception of valid heartbeat information to detect device being in range and or going out of range..
Your algorithm can use this information in conjunction with the connection loss to detect device being out of range and set off the alarm.
RSSI in Android available via public APIs is only during the discovery process, the other non public means of reading the RSSI (like in RemoteDeviceHelper) should also be possible , but RSSI by itself is not a good indication of distance.