You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When you initialize a NimBLEUUID with a 16-bit id, like in:
NimBLECharacteristic("1234",...
NimBLEUUID("1234")
Only the string without 0x prefix is accepted and working.
But when you try to get the string representation of the ID from a characteristic or a service UUID, it's build with sprintf("0x%04"... which is not consistent with the input described above.
And I can"t find any simple way to get a numeric version of this ID, for example to call to16String, which could return 0x1234 (the uint16_t number).
The consequence is that I'm not able, as the same time and from the same set of values (characteristics ID for example), to
select services and chars and subscribe to notifications with these IDs
match the received notifications from the set of values, because the keys should be without "0x" prefix (ex: "1234"), and the received notifications expose the characteristic ID with this prfiex within the generated string ("0x1234").
Any suggestion on how to be able to feed and get the same format for these IDs, preferably strings, in the same format ?
The text was updated successfully, but these errors were encountered:
You shouldn't need to use the string value for anything except printing to the console, you can simply use the NimBLEUUID class for anything that needs the UUID.
static NimBLEUUID myGlobalUUID("1234"); // even better to use myGlobalUUID((uint16_t)0x1234)
class CharacteristicCallbacks : public NimBLECharacteristicCallbacks {
void onRead(NimBLECharacteristic* pCharacteristic, NimBLEConnInfo& connInfo) override {
if (pCharacteristic->getUUID() == myGlobalUUID) {
Serial.println("Characteristic with myGlobalUUID was read");
}
}
};
/***** other code *****/
pService->createCharacteristic(myGlobalUUID);
Doing it this way is much more efficient.
If you really want the 16 bit value you could do this: uint16_t uuidVal = *(uint16_t*)someUUID.getValue(); or alternatively if you really want this you could do: uint16_t uuidVal = ((ble_uuid16_t*)(myGlobalUUID.getBase()))->value;, but I don't see much point in this.
When you initialize a NimBLEUUID with a 16-bit id, like in:
Only the string without 0x prefix is accepted and working.
But when you try to get the string representation of the ID from a characteristic or a service UUID, it's build with sprintf("0x%04"... which is not consistent with the input described above.
And I can"t find any simple way to get a numeric version of this ID, for example to call to16String, which could return 0x1234 (the uint16_t number).
The consequence is that I'm not able, as the same time and from the same set of values (characteristics ID for example), to
Any suggestion on how to be able to feed and get the same format for these IDs, preferably strings, in the same format ?
The text was updated successfully, but these errors were encountered: