1

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.

Chris
  • 629
  • 1
  • 10
  • 28
  • 1
    read [this](http://stackoverflow.com/questions/4632524/how-to-find-the-uuid-of-serial-port-bluetooth-device), [this](http://stackoverflow.com/questions/13964342/android-how-do-bluetooth-uuids-work), [this](http://stackoverflow.com/questions/19630810/android-get-bluetooth-uuid-for-this-device) and many others before posting a question to avoid dublications – hrskrs Feb 25 '15 at 15:32

2 Answers2

0

Here is a nice way that tells you how to get UUID for your app.

UUID

Community
  • 1
  • 1
denvercoder9
  • 2,979
  • 3
  • 28
  • 41
0

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 .

mach
  • 8,315
  • 3
  • 33
  • 51
  • This is the crux of the confusion to me... how is it possible that this is required if my coworker was able to write a working Bluetooth server WITHOUT specifying a UUID -- there is nothing to "share". In fact, I have downloaded "Bluetooth Terminal" on my Nexus and I am able to connect to his Arduino. What UUID is it using?? – Chris Feb 25 '15 at 16:42