Android bluetooth RFCOMM questions - android

I am trying to get an android phone to look like a bluetooth GPS unit so that a PC or any other device that supports bluetooth GPS can use it. I figured out the whole NMEA thing and have the device spitting out correct NMEA sentences. My problem lies in the bluetooth area though.
I have a bluetooth thread setup for listening for a connection. In windows I can see the service "Bluetooth GPS" that I created. The problem is I can't figure out how to get windows to open up the connection so I can start sending the NMEA sentences. When I enable the service in windows it says "Bluetooth Peripheral Device" and there are no drivers available.
What am I missing that would allow windows to understand that I want to communicate over RFCOMM and the device is a GPS device?

You need atleast Android 2.0 because unfortunately older versions of Android's Bluetooth API does not support RFCOMM yet neither does it support other methods of communicating its GPS data to an other Bluetooth device such as a windows PC.
Depending on the phone you are currently using you may be able to update it to Android 2.0.
I just tried it with my phone and it only supports Bluetooth headset and A2DP stereo audio.
You would have to create an app for android that passes your GPS data over Bluetooth RFCOMM just like the Bluetooth wireless tether app. You have to have the app running and then pair the device to your PC in order to use its services.

Related

Extract Mobile (android and IOS) Sensor data via Bluetooth without pairing

I know that connection between two Bluetooth devices can be made without pairing and maybe exchange files. My question is how can I extract accelerometer data from a smartphone without pairing? I already have a device that can locate the smartphone using Bluetooth signals only without connection or pairing. So, I don't have control or access over the smartphone, I only sense its location with a sensor.
You might want to use Bluetooth BLE (low energy), which doesn’t need pairing, but I’m not sure if you can access accelerometer data without using classic Bluetooth and pairing.

Disconnecting and closing BLE connection stops classic Blutetooth PBAP profile

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

Emulate a Bluetooth Device

My treadmill has a bluetooth chipset that it allows it to communicate with an app on my phone called iFit. In the communications, the phone receives information such as my distance traveled and speed, and the phone can set the treadmill's incline.
Instead of using iFit, I'd like to make my own script running on something like raspberry pi.
Is it possible to emulate the iFit bluetooth communications?
You can capture the bluetooth communication using bluetooth snoop logs. I think you will still need to write something to initiate the initial bluetooth connection. Once that is done you can possibly replay the traffic that captured in the bluetooth snoop logs. You can use Android Things on a raspberry pi if you are comfortable with working on the Android platform.

How to build this android app (Bluetooth technology)

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.

Activate Bluetooth SPP in Android?

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.

Categories

Resources