Author Topic: Using customUUID in Android example  (Read 4293 times)

MattG

  • RFduino Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Using customUUID in Android example
« on: September 03, 2015, 10:40:50 AM »
I generated a customUUID and set this in my RFduino app. Then, I modified the example Android app's BluetoothHelper to return the same customUUID as the service UUID (UUID_SERVICE). I am able to see my device when scanning, but when I try to connect to it, I always get:

RFduino GATT service not found!

My understanding of Bluetooth GATT services/characteristics is weak, but I am unclear what is going on. If I set customUUID to:

  RFduinoBLE.customUUID = "00002220-0000-1000-8000-00805F9B34FB";

(the default RFduino), everything works fine. But if I change one character on the RFduino:

  RFduinoBLE.customUUID = "00002220-0000-1000-A000-00805F9B34FB";

and match it in BluetoothHelper:

    public static String shortUuidFormat = "0000%04X-0000-1000-A000-00805F9B34FB";

it fails with the same error. Does the RFduino library have part of the GATT UUIDs hard coded still??

MattG

  • RFduino Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Using customUUID in Android example
« Reply #1 on: September 08, 2015, 09:33:04 AM »
Anyone? Seems like a pretty big bug/problem.


bsiever

  • RFduino Full Member
  • ***
  • Posts: 89
  • Karma: +4/-0
    • View Profile
Re: Using customUUID in Android example
« Reply #2 on: September 08, 2015, 06:15:58 PM »

iOS caches some details of a device, which can cause some problems like this. 

You might try to connect with a scanner app, like LightBlue.  If you can, verify the service UUID is the new one.  If you are only able to see the old UUID you may want to reboot your device (to try to clear any cached data).


MattG

  • RFduino Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Using customUUID in Android example
« Reply #3 on: September 09, 2015, 12:02:27 PM »
I did not try a scanner app, but I did try rebooting the device. I also tried multiple different phones (some that had never used the RFduino device).

thienkyo

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Using customUUID in Android example
« Reply #4 on: December 07, 2015, 07:11:56 PM »
Hi MattG,

Recently i did what you did (using customUUID sketch), but it did't work. Here what i did

1. upload customUUID sketch with RFduinoBLE.customUUID = "c97433f0-be8f-4dc8-b6f0-5343e6100eb4";

2. Android app: MainActivity.java

.....
UUID[] uuid_test =   new UUID[]{ UUID.fromString("c97433f0-be8f-4dc8-b6f0-5343e6100eb4")} ;

.... then

bluetoothAdapter.startLeScan( uuid_test ,MainActivity.this);

As you can see, uuid from both rfduino and app are the same, and the phone cannot see it when scanning . Can you show me where i did wrong b/c you said "I am able to see my device when scanning"


MattG

  • RFduino Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Using customUUID in Android example
« Reply #5 on: December 09, 2015, 08:19:32 AM »
It seems your MainActivity.java is different than mine. Are you using the RFduino BluetoothHelper.java example class? This has a method called sixteenBitUuid that creates all of the service UUIDs like this:

    public final static UUID UUID_SERVICE = BluetoothHelper.sixteenBitUuid(0x2220);

I modified these lines in BluetoothHelper.java to use my custom UUID:

    public static String shortUuidFormat = "0000%04X-0000-1000-8000-00805F9B34FB";

    public static UUID sixteenBitUuid(long shortUuid) {
        assert shortUuid >= 0 && shortUuid <= 0xFFFF;
        return UUID.fromString(String.format(shortUuidFormat, shortUuid & 0xFFFF));
    }




tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Using customUUID in Android example
« Reply #6 on: December 09, 2015, 12:35:49 PM »
I am not privy to what the RFduino Team is doing in their libraries. But it seems to me that the BLE standard for using 16 bit UUIDs are they are for use with the base BLE default UUID string only...
00000000-0000-1000-8000 00805F9B34FB
... I think.

If you define a custom UUID (128 bit) you have to use 128bit for all your characteristics that are subordinate to it.

I don't know what you have to do in JAVA, iOS, or Android SDK to play with UUID. But using the Nordic Master Control Panel is the way to go to see what something is putting out. So for the RFduino custom UUID sketch using
c97433f0-be8f-4dc8-b6f0-5343e6100eb4
I see the following UUIDs...

Primary Service(what was the 2220 Service): c97433f0-be8f-4dc8-b6f0-5343e6100eb4

What was the 2221 Service: c97433f1-be8f-4dc8-b6f0-5343e6100eb4
What was the 2222 Service: c97433f2-be8f-4dc8-b6f0-5343e6100eb4
What was the 2223 Service: c97433f3-be8f-4dc8-b6f0-5343e6100eb4

As far as I can tell the RFduino custom UUID is to just change the default UUID of 'RFduino'. It doesn't provide for a way to make custom UUID representing additional new services or characterstics other than the basic three built-in ones that were the 2221,2222,2223.

« Last Edit: December 09, 2015, 01:07:53 PM by tolson »

thienkyo

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Using customUUID in Android example
« Reply #7 on: December 24, 2015, 12:36:47 AM »
 Thanks guys,

@MattG:  I didn't use BluetoothHelper.java bc i wanna make a custom UUID quickly, and not baseed on base BLE default UUID(00000000-0000-1000-8000 00805F9B34FB).  Can you show me how you modifie the java code. I guess you customize the UUID but sitll based on base BLE default UUID.

@tolson : thanks for reply. It really does help.

I will test it and let you know the results.

thienkyo

  • RFduino Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Using customUUID in Android example
« Reply #8 on: December 24, 2015, 12:56:55 AM »
@MattG: I saw ur modified code. no need to show me it again.

 

anything