I know I’m making a basic error here, but I cannot see it.
Walking through an example…
If I use the bleButton as my example.
I can see that within ButtonService.h we construct our service:
ButtonService(BLE &_ble, bool buttonPressedInitial) :
ble(_ble), buttonState(BUTTON_STATE_CHARACTERISTIC_UUID, &buttonPressedInitial, GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY)
{
GattCharacteristic *charTable[] = {&buttonState};
GattService buttonService(ButtonService::BUTTON_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
ble.gattServer().addService(buttonService);
}
Then my understanding is that our characteristic is defined by buttonState which is handled by our template ReadOnlyGattCharacteristic<bool> buttonState;
Then from this template we can construct our characteristic, which is made up of:
a UUID, which is BUTTON_STATE_CHARACTERISTIC_UUID
an initial value which is &buttonPressedInitial
and some additional properties: GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY
I can see that the template also allows me to add in two additional parameters which have default values assigned:
GattAttribute *descriptors[] = NULL,
unsigned numDescriptors = 0
But this is where I am stuck.
Going to GattAttribute.h I am given an example:
@code
* // declare a value of 2 bytes within a 10 bytes buffer
* const uint8_t attribute_value[10] = { 10, 50 };
* GattAttribute attr = GattAttribute(
* 0x2A19, // attribute type
* attribute_value,
* 2, // length of the current value
* sizeof(attribute_value), // length of the buffer containing the value
* true // variable length
* );
* @endcode
But when I add this to my characteristic as follows:
uint8_t attribute_value[10] = { 10, 50 }; // define my attribute value
ButtonService(BLE &_ble, bool buttonPressedInitial) :
ble(_ble),
buttonState(BUTTON_STATE_CHARACTERISTIC_UUID,
&buttonPressedInitial,
GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY,
GattAttribute( 0x2A19, attribute_value, 2, sizeof(attribute_value), true),
1 )
{
GattCharacteristic *charTable[] = {&buttonState};
GattService buttonService(ButtonService::BUTTON_SERVICE_UUID, charTable, sizeof(charTable) / sizeof(GattCharacteristic *));
ble.gattServer().addService(buttonService);
}
I get an error:
No matching constructor for initialization of ‘ReadOnlyGattCharacteristicstd::uint8_t’ (aka ‘ReadOnlyGattCharacteristic’)
mbed-os/features/FEATURE_BLE/ble/GattCharacteristic.h:1832:5:
note: candidate constructor not viable: no known conversion from ‘GattAttribute’ to ‘GattAttribute **’ for 4th argument
mbed-os/features/FEATURE_BLE/ble/GattCharacteristic.h:1812:7:
note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 5 were provided