Generated UUIDs not working

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
LePetitRenard
 
Posts: 15
Joined: Tue Oct 25, 2022 10:24 am

Generated UUIDs not working

Post by LePetitRenard »

I'm trying to use BLE GATT on an nRF52840 Sense. Randomly generated UUIDs are not working for Service or Characteristic IDs. Different errors arise depending on the UUID tried:

Code: Select all

BLEService BLEservice = BLEService(5aee1a8a-08de-11ed-861d-0242ac120002);
returns : invalid digit "8" in octal constant

Code: Select all

BLEService BLEservice = BLEService(2fa3d779-25d1-4886-8736-ed40751c9fe5);
returns : "unable to find numeric literal operator 'operator" "fa3d779' "

These UUIDs work for my BLE Services/Characteristics on my other boards (ESP32, Arduino Nano). This is my first time working with Bluefruit and not sure what the issue is. I noticed all the example sketches from the Bluefruit nRF52 library use Bluetooth Assigned UUIDs ie '0x1800', '0x2A20 format.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Generated UUIDs not working

Post by adafruit_support_mike »

The compiler doesn't know how to read the hyphenated strings shown above. It thinks you're trying to subtract a series of badly-encoded smaller numbers.

You need to convert the UUID to a single hex value written in 0x... notation.

User avatar
LePetitRenard
 
Posts: 15
Joined: Tue Oct 25, 2022 10:24 am

Re: Generated UUIDs not working

Post by LePetitRenard »

I had noticed this hex issue and attempted to convert the UUID, but none of the conversions were working. It turns out converting UUIDs to a hex value is not straight forward. Online converters (as of 10/2022) do not work.

For future reference this is how to convert a UUID to hex:

We start with the UUID: 2fa3d779-25d1-4886-8736-ed40751c9fe5

1) Remove any hyphens in the UUID
-> 2fa3d77925d148868736ed40751c9fe5

2) Split the UUID into 2-digit sequences
-> 2f, a3, d7, 79, 25, d1, 48, 86, 87, 36, ed, 40, 75, 1c, 9f, e5

3) Reverse the order, and add '0x' in front of each segment
-> 0xe5, 0x9f, 0x1c, 0x75, 0x40, 0xed, 0x36, 0x87, 0x86, 0x48, 0xd1, 0x25, 0x79, 0x37, 0xa3, 0x2f

As for Bluefruit's prefered notation, here is the final result in code:

Code: Select all

#define My_Service_UUID (const uint8_t[]) { 0xe5, 0x9f, 0x1c, 0x75, 0x40, 0xed, 0x36, 0x87, 0x86, 0x48, 0xd1, 0x25, 0x79, 0x37, 0xa3, 0x2f }

I don't understand why this works, but apparently this is the way it is done. For confirmation, you can refer to the Bluefruit sketch 'arduino_science_journal'. Hopefully this will be helpful to someone in the future

Locked
Please be positive and constructive with your questions and comments.

Return to “Wireless: WiFi and Bluetooth”