Unable to retrieve characteristic uuid in callback

Hello everyone.

I am using the ArduinoBLE library on my Nano 33 BLE.

I have a class, DayAlarmService which has three characteristics: enabled, startTime and duration. I have 7 instances of that class, one for each day of the week. I need to know on which one of them an event was triggered (like a read on a characteristic or a subscription, ...). To do this, I have another class, AlarmServiceManager, which instantiates all 7 DayAlarmServices and stores all UUIDs (from the services and the characteristics). Since we have access to the BLECharacteristic when we set an event handler, I should be able to retrieve the uuid of the characteristic and check out to which day it corresponds (since I know all the uuids). Of course, all characteristics and service have a different UUID, known by AlarmServiceManager.

The issue is that, for an unknown reason, when the callback is called, the uuid() function returns "random characters" and not the correct uuid.

#EDIT: remove some code that is now not accessible anymore

The weird part is that I have other services and characteristics that can correctly access their uuid(). I don't understand why it doesn't work as expected in this case.

I hope that I was clear. If you need anything else, please let me know!

Thanks

For anyone interested, or having the same issue, here is the solution:

The uuids were stored on the stack and, apparently, the BLECharacteristic do not copy the uuid given to them in their constructor.

The fix is simple enough: declare the uuid somewhere where the characteristics will be able to access them (so static, or on the heap).