We are developing an application which needs the BLE Peripheral to be automatically paired with the smartphone when the smartphone is near the BLE Peripheral.
We are using RN4871 Microchip BLE Board,
First time when I pair the device from the settings, then power of the device and power on the device, it doesn't show in the Connected Device list, I mean Android doesn't automatically gets connected. Whereas this behavior is not seen in case of Bluetooth Headset.
What is the difference between a BLE Peripheral and Bluetooth Headset, how can i achieve this behavior
That a device is paired (or more correct, bonded) generally just means that the central and peripheral stores keys used for encryption etc. when they later connect.
FYI Peripherals can be programmed so that they advertise with a specific Bluetooth device address as target.
Back to your question. In Android, an "application" must initiate a connection to a device to make it connected (no matter if it's paired or not). That can either be a normal app you install or the built-in HID application in the Bluetooth stack. That said, the HID application will automatically connect to enabled bonded HID devices. So basically, if no application wants the peripheral connected, it won't stay connected.
Related
I'm working on a project that requires Bluetooth, however I need it to connect with Bluetooth from my app on one phone to my app on another phone.
Is there a way for Bluetooth to be used on two devices of the same type, or is is just different devices that can connect to each other? Could you please also provide me with a link to Android documentation, if possible?
When using BLE, an Android device can act as a peripheral device, a central device, or both. Peripheral mode lets devices send advertisement packets. Central mode lets devices scan for advertisements
See Device modes.
BluetoothLeAdvertiser enables to turn a supported phone into a peripheral.
See Bluetooth Low Energy Advertising for details.
I know that there are ways to share internet via:
Creating a hot spot on the mobile phone
Bluetooth tethering?
NFC tags
However all these processes require some manual effort on the user side.
I am wondering if there is a way to seamlessly do this for the user the moment we pair with their peripheral device over BLE. Is there a way I can programmatically share the Wi-Fi connection the moment we are successfully connected?
Use Case:
I have a new speaker that can connect over BLE
I successfully pair my phone with the speaker over BLE
My speaker after pairing also automatically joins the same wifi network as my phone after
I have a setup with two Android devices: an android phone and a custom hardware running Android 10. The latter acts as a BLE Server, which is discoverable always with the same static MAC address. Also when that custom HW is paired with the phone it has access to phone's contacts and calls history. That HW can also play media (sound) streamed from the phone.
I use RxAndroidBle 1.11.0 library for BLE communication. As soon as I exchange some data via BLE Characteristic I unsubscribe from the RX observable so the library effectively calls: bluetoothGatt.disconnect() then blutetoohGatt.close()
(all those inside the DisconnectOperation class).
My problem is the fact that based on my observations, calling blutetoohGatt.disconnect() disconnects the classic BT profile (PBAP) as well.
Is it an expected behaviour?
I have investigated the code of generic Android P framework and it looks that calling bluetoothGatt.disconnect() -> bluetoothGatt.close() completely disconnects the device described by the given MAC Address:
BluteoothGatt#disconnect()
BlutetoothGatt#close()
BlutetoothGatt#unregisterApp()
I would risk a statement that I have quite unusual BLE use-case scenario where the phone (Central/Client) and the peripheral (custom Android HW/Server) are connected simultaneously via Classic BT profile and via BLE.
I suspect that disconnecting/closing device using its BT MAC address disconnect both profiles, hence the contacts sharing stops working.
Is it possible to disconnect BLE connection only, but not affect the classic BT (SPP/PBAP) connections between the two devices?
After further investigation described on that Github issue
I realised that my custom hardware is equipped with dual-mode BT adapter so it supports classic BT (BR/EDR) and the BLE one.
As soon as I pair an Android phone with the custom hardware via System Settings, classic BT profiles are bonded, but also my GATT Server advertises relevant services using the same MAC address which is used by the BR/EDR. Disconnecting BLE client connection disconnect BD/EDR as well.
What helps in my case is to not start pairing via System Settings, but let the GATT server advertise and let my BLE client app to connect (and trigger pairing) first. As a result I have a BLE connection with server available under "AA:AA:AA:AA:xx", while the classic BT profiles are connected to "BB:BB:BB:BB:yy" interface on the custom hardware.
Now, disconnecting BLE profile does not disconnect the classic one.
I am looking for a solution which would allow my GATT Server to be advertised with BLE only, but no luck so far.
Here are some interesting links I have found:
connectGatt creates connection over BT Classic instead of BLE
how to force BLE "just works" pairing in Android
BLE Dual-Mode
I am trying to answer the following question?
When two Bluetooth devices are connected, does either of them reply to any Inquiry scan, or send an Inquiry?
I had a few experiments and my answer is no. I connected two BT devices and try to pick any BT device nearby by my other phone which it did not detect any of them.
It would be great if you could also support your answer by a referencable document.
I have looked at several docs like these:
http://essay.utwente.nl/59681/1/MA_scriptie_A_Franssens.pdf
https://link.springer.com/content/pdf/10.1007%2F978-0-387-75462-8_20.pdf
but could not find a straight answer.
Yes, Bluetooth device can scan/enquiry and send scan/enquery response when connected. However, most cells designed so that it can be discovered only when you have Bluetooth settings opened. This is not Bluetooth limitation but OS design.
If we are talking about headsets (or keyboard or any other HID device) then this is reasonable why manufacturer made it so it can pair/work with only single device. But this is just a manufacturer decition and made so by design. It is not Bluetooth limitations. If you need you can design such headset that can be paired and connected to few devices t the same time.
On high-level Bluetooth device can be in Discoverable and/or in Connectable modes. Discoverable mode makes device visible to other devices. Connectable mode allows to connect to the device.
Usually manufacturer design it so that is device is not paired (or when you press special button or open Bluetooth settings on cell) it stays in Discoverable mode. So other devices can discover (find) the headset/cell. Once you paired with your device the Discoverable mode switched off. So now you can connect to device (cause during pairing the MAC is stored and you do not need to rediscover the device).
Once you connected the device turns Connectable mode off so others can't find and connect to it.
But once again. This is how manufacturer designed device. It is not Bluetooth limitation.
Bluetooth Core Specification
I know that you can connect and interact with multiple bluetooth low energy devices without problems. I myself connected to at least three ble devices and could easily receive and send data.
Goal:
I'm trying to connect my Android phone to an already paired bluetooth device when its in proximity.
Issue : I am novice to BT technology. I am pairing up my Android phone with a BT device using classic bluetooth API (SPP) as BT device is intent to send large data to mobile app.
The requirement/issue is : Mobile device should automatically connect with already paired BT device when in range. Note that we are using classic BT API and not the GATT.
How does the car audio system automatically connects with driver's phone. I think its the car's BT system who initiate pairing request with phone when car is turn on?
There are a lot of loose ends here. To reconnect to an already paired SPP device depends upon the behavior of the device. If it is passive (always in the slave role) you will have to actively connect to it. I have a passive SPP medical device and to auto reconnect to the device I have to 'continuously' do a discovery in the background (by continuously I mean to a discovery for 5 seconds every 10 seconds or something like that). When I detect the device I create an SPP socket and invoke the connect() method. The alternative is to have a UI that has the user invoke the connect() method when using the device. Hopefully the device is nice and becomes discoverable when it is ready to connect. If it is not discoverable then you need to (yuulk) poll it with connect attempts.
If you have an active device, you can set up a listener socket so the peer can connect to you and you avoid all that background discovery work. At least that is what I have had to deal with.
Yeah by periodic discovery of already paid BT device we can detect and auto pair with them but ar the cost of battery. This is what I had done.