Having trouble with custom UUID in Android BLE - android

I have a problem with using my own generated UUID(not using 16 bit UUID reserved by Bluetooth SIG) to communicate in Android BLE.
Target device is two - one is as a peripheral(Samsung galaxy note 4/android 5.1.1) and another one is as a central(Samsung galaxy S5/android 5.0.1). I put my own service's UUID and characteristic's UUID on the peripheral side. On the central side, it could not find characteristic but service.
It seems like it caused by not using one of these Characteristic UUIDs but using custom generated UUID.
Below is my own generated UUIDs.
private static final UUID CUSTOM_SERVICE_UUID = UUID.fromString("abcd1111-0000-1000-8000-00805f9b34fb");
private static final UUID CUSTOM_CHARACTERISTIC_UUID = UUID.fromString("abcd1112-0000-1000-8000-00805f9b34fb");
Service, found well, but characteristic, no.
Do you have any idea?

you are using the official base UUID: xxxxxxxx-0000-1000-8000-00805f9b34fb, from which all upper 32-bit are reserved (some already assigned.)
Instead, you should use your own 128-bit UUID. You can use an online tool to generate one. Then just assign your own internal n-bit short uuid to each one of your characteristic.
For example: using base => 18902a9a-1f4a-44fe-936f-14c8eea418xx
Service => 18902a9a-1f4a-44fe-936f-14c8eea41800
Characteristic => 18902a9a-1f4a-44fe-936f-14c8eea41801

Related

nRF52840 - Android Kotlin application : Problem with 16-bit UUIDs

I'm developing a frame exchange sequence between an nRF52840 and an Android smartphone using the BLE protocol.
The service exposed by nRF52840 has the following 16-bit UUID : EB7A
In my Android application, if I only want to retrieve BLE devices that have this service, I need to initialize the filter like this :
private var scanFilters: List<ScanFilter> = arrayListOf(
ScanFilter.Builder().setServiceUuid(ParcelUuid(UUID.fromString("0000eb7a-0000-1000-8000-00805f9b34fb"))
)
However, if I want to write about a feature of this service, I have to use the following UUID:
0000eb7a-0000-0000-0000-000000000000
I don't understand why I can't use the same UUID for filtering as for read/write operations, can you help me?
I don't know whether you have figured it out. If yes, would be interesting to know what you have discovered. I am quite new to android and nRF dev myself, but I have 2 theories for your question:
If you are using a vendor-specific UUID for the filter, I guess you are not able to modify it, which is why you have to use a different UUID.
Have you tried deriving the UUID as a String for example and then using it in a filter (not sure if this would work thou)
public static String SOME_SERVICE = "0000eb7a-0000-1000-8000-00805f9b34fb"
ScanFilter = newScanFilter.Builder().setServiceUuid(UUID.fromString(SOME_SERVICE);

Web Bluetooth with a Custom GATT Service?

First, the source code for the BLE Peripheral Simulator is a tremendous resource for anyone investigating Web Bluetooth.
There is a an approved list of GATT Services.
When I modified the Android source code to use a custom defined GATT service (easy to do by simply specifying your own UUID in the Android code) pairing from the web page to the Android app running the GATT sever fails.
The Web Bluetooth documentation does state, "If device’s advertised Service UUIDs have a non-empty intersection with the set of Service UUIDs, add device to result and abort these sub-steps [for pairing]."
Does this mean only services in the approved GATT list are supported? If so, what is the rational? It seems that such a restriction would limit innovation.
I am working with web-bluetooth also and i was able to talk with custom services, yet to read data from them you have to have device docs explaining how to talk to that services. I think this approved list is like generally used list which doesn't require unique logic to get data. However there is difference since some characteristics are blacklisted for web-bluetooth yet available to fetch data from using ios/android stuff.
If I had done some more research on Stack Overflow I would have realized the UUID spec requires lowercase a-f.
Type of Character generated by UUID
The following values work for a custom defined service and characteristic:
private static final UUID SERVICE_UUID = UUID.fromString("29143321-ef6c-4761-947c-c858f9a2e8f1");
private static final UUID CHARACTERISTIC_UUID = UUID.fromString("92f3131b-ffa8-4dd1-a12b-641d65a78857");

What should my UUID be?

I'm relatively new to Android and am creating a Bluetooth App on a Nexus 9 that will connect to a Bluetooth device application my coworker has written on an Arduino processor. I'm following this doc, which is very helpful:
http://developer.android.com/guide/topics/connectivity/bluetooth.html
However, to connect as a client I have to use this code, which uses this MY_UUID symbol.
// MY_UUID is the app's UUID string, also used by the server code
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
In the text the doc says: "The UUID passed here must match the UUID used by the server device when it opened its BluetoothServerSocket (with listenUsingRfcommWithServiceRecord(String, UUID)). Using the same UUID is simply a matter of hard-coding the UUID string into your application and then referencing it from both the server and client code."
This is confusing to me... does it mean it must match a UUID specified in the Arduino firmware?? My coworker who wrote the firmware doesn't know what that would be. When I sniff his firmware advertising, it has ID "RNBT-DFBC", but when I use that as a UUID I get an exception :
java.lang.IllegalArgumentException: RNBT-DFBC is not a valid Bluetooth address
And none of the sample Bluetooth projects I've looked at seem to explain the basis of this UUID value, they're just "magic numbers."
So... what on earth do I use as the parameter for my createRfcommSocketToServiceRecord() function? I feel like I am misunderstanding this, because a Bluetooth client cant possibly generally have such "intimate" knowledge of a server it wants to connect to. So sorry if it's a dumb question, but any help is appreciated.
Here is a nice way that tells you how to get UUID for your app.
You should use a pre-shared UUID that both your device and the Arduino device knows. For example:
public static final java.util.UUID MY_UUID
= java.util.UUID.fromString("DEADBEEF-0000-0000-0000-000000000000");
The String is in a format according to RFC 4122. You can find more information about the specifics for Android in the Android UUID documentation .

CoreBluetooth: the UUID of a peripheral is an inherent attribute of a device?

I use CoreBluetooth to connect my iPhone with a device equipped with Bluetooth 4.0.
I print its (as a peripheral) UUID :
<CBPeripheral: 0x1742fca80, identifier = B148AD69-1FC7-498C-016F-33BA3BE041A3, name = HMSoft, state = disconnected>
I wonder whether this identifier is an inherent attribute of a device.
Since I use the following code in android to get its UUID which is different from what I get using CoreBluetooth in iPhone:
BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
for (ParcelUuid uuid : device.getUuids()) {
Log.d("UUID", uuid.getUuid().toString());
}
( I connect with the same device but the print UUID is different).
Identifier in CBPeripheral is a randomly generated Unique identifier. This gets varied over time. In case of a CBPeripheral, we need to know about two kinds of UUIDs. One is ServiceUUID and other is CharacteristicUUID. Each peripheral broadcast data over each service. A single service can have more than one characteristics. For eg. a device information service can have device name, device version etc as its characteristics.
See the following image for a better understanding CBPeripheral. The Apple docs speaks well on this.
My first answer, so I hope I won't make a fool of myself ;-)
BluetoothDevice.getUuids():
Returns the supported features (UUIDs) of the remote device. I.e. UUIDs of services advertised by the device, not UUID of the device itself.
I'm currently looking myself for an Android way to get the UUID of a discovered BLE device...

Android Find the UUID of a specific bluetooth device

I'm starting to work on Bluetooth in Android recently.
I want to build an application that can read the data recorded by a sensor through bluetooth.
I have some sample code, but looks like I need another UUID of a different device.It looks like this:
private static final UUID MY_UUID = UUID
.fromString("00001101-0000-1000-8000-00805F9B34FB");
Later on in the code, it uses this UUID to make a connection:
tmp = device.createRfcommSocketToServiceRecord(MY_UUID);
I have done some research online, like [here][1]. I think I need a different UUID number for the new device I'm working on. How do I get the UUID number?
On the device, there are two lines of number saying:
SN: 1201L0023
BT: 10:00:E8:C5:16:85
Thanks in advance!
Jake
UUIDs are not tied to particular devices. They identify software services. Some UUIDs for defined profiles are set by BT. The UUIDs used with RFCOMM sockets like your example are arbitrary. You just need both sides to use the same one. In general, devices connect and then use service discovery protocol to find out what services (UUIDs) are supported on the remote device.

Categories

Resources