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
Related
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 have been doing a ton of research on this project I want to do, probably read every SO post (bluejacking, RFCOMM, beacons, etc...) and my head is spinning.
I want to create a system at home, using Arduino (with bluetooth le) that will scan bluetooth and detect when my phone or any of my family members phones are in proximity. Whether this is a MAC scanner or simply getting the friendly name. I would also like to get the RSSI. I dont need to do accurate distance measurement but I would like to know approximately how close they are. Does anybody have any suggestions for this approach? I know I can create an app on the phone and have it become a beacon and this may be an option but I am concerned with Android, it would have to be Marshmallow 5.0 at a minimum. I would like support to be a little lower than that, like JB or KK. So, it seems like there should be a simple scan, just looking for the MAC or name. That is all I really need.
That said, the main question I have is, can you scan for and see bluetooth devices in range if they are already paired to something? Like a Bluetooth headset? I understand bluetooth is point to point but does it allow multiple connections or at least broadcast the mac or name when paired?
This question, along with any general suggestions will help me out tremendously!
Thanks!
Bluetooth Discovery from the Listener involves Listening for Bluetooth Inquiry packets(RX) and inquiry response (TX).if done continuously this will deplete the battery. Hence most devices (including Mobile Phones and Headsets) has a policy of when to be discover-able and connectable. Headsets in particular are discoverable only when they are instructed and connectable until one device is connected to it ( There are probably exceptions where the headset has the capability to be connected to multiple phones at the same time). Most Mobile Phones are discoverable only when they are in settings screen ( Android,IOS and Windows Phones), but unlike the headset case they are connectable.
so one option with the MobilePhone is to see if it is possible to connect to them after pairing once ( for example by trying a service search on the remote device and see if it returns the service attributes, this internally makes a connection and indirectly ensures the presence of the device).
if you are specific about a mobile phone which is already paired then you might need to establish a higherlayer connection ( such as SPP) with Authentication and encryption. This would force a two way check between devices to see whether they are already paired. other less secure option is to rely on the Phone (Android and IOS phones doesn't generally Allow a higher layer connection without encryption/pairing) and try to establish an SPP connection to the phone.
Another option is to use Bluetooth-LowEnergy. But Note that security in BT was superior to BLE till BTv4.1 and same on BTv4.2.
I am building a project (using Arduino) that should detect a person going inside a building (e.g her house, office, etc) and inform a server about it. This should be done seamlessly and handless.
I though of using Bluetooth to do so, because I know that some devices (like a car speaker) can automatically connect to my phone.
Generally, I wish that once the device is in range (using small range BT devices of <1 meter range) my application will be aware of it and can inform the server about it, even if the the phone is "locked" (screen is black). It is possible that the BT device will actively search for the phone and will try to connect to it (assuming the phone and the device) are already paired.
Is it possible to accomplish what I am trying to do with BT, and if so, how? If not, is there any other way to accomplish it?
Yes that is possible but normal bluetooth would consume too much energy as you would constantly have to search for devices. Your use case is typically implemented with Bluetooth Low Energy (BLE) - for example the famous Apple iBeacon.
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.
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.