I am implementing Bluetooth Low Energy's HID over GATT (HOGP) profile on Android Lollipop. My target is to use the phone as a keyboard/mouse, which can just plug and play with the default BLE (HID) drivers in Windows 8.1 laptop. The Android phone is supposed to act as BLE peripheral and the laptop should be in BLE central role.
Currently, I am able to establish a very short connection with the laptop. But just right after I enter the passkeys, and bonded successfully with the laptop, the BLE connection will be lost. Have anyone faced this kind of problems before? Or have any solutions on it?
Also, I failed to add generic access service to the gatt server in Android. I am curious if GAP service is included in Android BLE communication by nature? The reason I want to include this service is for defining the "device name", "appearance", and the "peripheral connection parameter update" characteristics. How I can do so?
Did you get your system fixed, I am seeing something kind of similar, where after bonding, my device will go to paired list, then about 20 sec later, the bluetooth on /off button will automatically switch to off position, wait 10 sec, then back
to on position, and my device is gone..
Related
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
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.
Here's our situation. We have a machine vending machine run in peripheral mode and mobile runs in central mode. When the mobile is close to the vending machine, it triggers the connection and start to communicate. But as far as I know, the peripheral mode can only connect to one device at a time just considering bluetooh 4.0, so if there's someone who wants to make a trick stands around our vending machine and connects to it all the time, no one else can connect the vending machine. Am I right?
My question is
How to avoid this situation. Is it possible for the vending machine to refuse the connection or to trigger the disconnection when it founds that the connection is invalid (triggered by other app)?
I have heard something like multipoint bluetooth. So how much can the multi be, can it be like 100 so that it may solve the problem.
I found a similar situation in paypal beacon. https://devblog.paypal.com/how-does-paypal-beacon-work/ it says the beacon is running in peripheral mode. I am wondering how do they avoid these invalid connections.
Since, the central device(mobile device) initiating connection, it will act as Master and the other end device(vending machine) will act as slave.
According to Bluetooth 4.1 specification, a slave can have multiple masters.
So, more than one mobile device can connect to the single LE device.
I am a little confused on how to build this android app. Here's how it should work. I have a list of paired bluetooth devices. Lets say paired devices are:
1. A bluetooth head set.
2. A mobile phone.
And my app should automatically connect only to my headset when ever it comes in range.
Thats the basic functionality. I have been doing some research on bluetooth technology and its implementation. I came across the bluetooth chat application, when I started using the application I realized that both phones should have the app on it in order to connect and exchange messages. I tried connecting to my headset but it doesnt connect. And also when I removed the bluetooth chat app from one of my device and tried to connect it from a device which had bluetooth chat app, the devices couldnt connect.
If you have already worked on bluetooth this might look very simple. But how can I connect to a bluetooth device from my app when ever its in range even if the other device doesnt have my app.
Thanks.
This will be a 2 sections answer:
-To connect to a Bluetooth Headset, check my answer on here
-To Always connect to that device, you can save device address to memory then create a service with BroadCastReciever that listens for Bluetooth Connectivity. and check which device gets connected and compare it address to the one save in memory once its finds it connected call ibth.connect(device). ibth is inside the above link.
I am trying to use Bluetooth SPP to communicate over it. In some Android phones, SPP profile is not activated. I faced the problem in the application that SPP was not activated and so the connection could not be established over bluetooth and when I started another app that is 3g hotspot which I think activates SPP and I was able to connect over bluetooth in my app.
So, how can we actually activate SPP profile of bluetooth in Android devices? And does all the android devices has SPP profile?
In developer.android.com BluetoothSocket:
The most common type of Bluetooth
socket is RFCOMM, which is the type
supported by the Android APIs. RFCOMM
is a connection-oriented, streaming
transport over Bluetooth. It is also
known as the Serial Port Profile
(SPP).
This might answer your question ..
https://source.android.com/devices/bluetooth/services
SPP (or ability to use Java API's to establish RFCOMM channels) is available from Android (2.0/2.1) release (Eclair) onwards
On the Android phone you will probably need to run an application that initiates the service over SPP.
**
public BluetoothServerSocket
listenUsingRfcommWithServiceRecord
(String name, UUID uuid)
** API can be used to create a service with specified UUID to listen,
Doing this should make this service visible to other devices which can then connect to it.
I just called Samsung help regarding bluetooth SPP on an S8+ phone. They tell me wait for Android Oreo as it isn't available till then. My previous Sony Xperia used Ntrip Client to talk to an external Geneq GPS to receive corrected coordinates and worked really well. Seems we went backwards somewhere?
Ntrip client on the phone collects an internet data stream of GPS corrections every five seconds and sends these to the GPS. The GPS uses the corrections and sends back adjusted coordinates to the phone to use in any application.
I would appreciate someone brighter than me pointing out a quick fix I just load and run to bring back this functionality.