Detect which BT device is going out of range - android

Is there a way to check which device among the paired Bluetooth devices is out of range/disconnected? I am able to see that some device is going out of range but need to identify which device is going out of range.

As #marcman mentioned in the comments, comparing the list of paired devices before and after would help to see which device is going out of range.

Related

Connecting to bluetooth device with a best rssi

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

Bluetooth proximity scan while paired

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.

android app will receive the BluetoothDevice.BOND_NONE broadcast when phone is away from the paired device at a distance

I used "createBond" method to pair my phone and my device with BLE.it succeed.but I took my phone away from the device at a distance, about 10 meters.My app received the broadcast: BluetoothDevice.ACTION_BOND_STATE_CHANGED, and the device status is became BluetoothDevice.BOND_NONE. Is it normal or something wrong?
after my app receive the broadcast I will unpaired the device.because I think the device is unpaired manually by user from setting activity.
10 meters is a normal range for a BLE device. You got too far from it so you couldn't maintain a connection. This is normal. With some devices the distance will be even shorter (perhaps 5m).
BluetoothDevice.BOND_NONE broadcast when phone is away from the paired device at a distance is not normal I guess.
Yes, the disconnection from the paired device when you're out of the bluetooth range is normal, but, as I said earlier in the comment, pairing and connectivity are two different things. The BLE might not be connected but, it can be shown in the paired list of Android once its paired.
And another interesting thing what I want to share in this case is, the bluetooth devices which are already paired once with an Android, are somehow remembered in Android device even if you un-pair them. I had this tested for some of my personal projects.

Get Bluetooth active paired devices

I am getting the Bluetooth paired by method getBondedDevices(). The method returns all the devices which are already paired.
In the list of paired devices there may be devices where Bluetooth may be turned off or out of range(Not reachable).
My requirement is to get the Bluetooth devices which are active(turned on).
Does anyone please can help me with this ?
So you scan your area for Bluetooth-Devices [Take a look at this answer].
When you receive a new Bluetooth-Device, you check if this Device is in your Bonded-Device list. If it is a Bonded-Device, you can sace it in a seperate list, where you save the Devices, which are bonded and active.

Read RSSI bluetooth value from paired device on API15 (no GATT available)

I have created a bluetooth car that is controlled using a Galaxy Tab, from which I want to be able to frequentely (1-10 times per second) read the RSSI value to be able to always stay in range of the bluetooth, and if not the car is supposted to return to the last known place where the connection was within range.
My problem however, is that I am not able to read the RSSI value when paired to the bluetooth module in my car. Reading while discovering is not a problem, but does not help me in this case.
I have been looking around but can't find an answer how to make this possible using the API I am, which is 15, and therefore GATT is out of the question. Help would be greatly appreciated!
Cheers :)

Categories

Resources