Skip to content

Typecast issue when converting example code from .ino to .cpp (CurieBLE) #408

@ajhool

Description

@ajhool

Hi, I am having trouble understanding the BLECharacteristic templates, and implementing the .ino example code in .cpp. Specifically, adding a typed BLECharacteristic (eg. BLEUnsignedLongCharacteristic) to a service. I have also reviewed the .cpp code that the Arduino IDE generates, and find that XCode IDE still won't compile it. Using master head of CurieBLE library Code and compiler error below (which follows patterns in the LED and LEDCallback examples provided):

BLEPeripheral blePeripheral;
BLEService service = BLEService("8888888-5555-1234-5678-D104768A1214");
BLEUnsignedCharCharacteristic failedChar = BLEUnsignedCharCharacteristic("8888888-5555-1235-5678-D104768A1214", BLERead | BLEWrite);
BLECharacteristic workingChar = BLECharacteristic(""8888888-5555-1236-5678-D104768A1214"", BLERead | BLEWrite , 1);

int main(int argc, const char * argv[]) {
    service.addServiceToPeripheral(blePeripheral);

    service.addCharacteristic(workingChar);

    //throws error in XCode: 
    //non-const !value reference to type "BLECharacteristic" cannot bind to value of unrelated type "BLEUnsignedLongCharacteristic"
    service.addCharacteristic(failedChar);

}

As an aside, perhaps examples could be given in .cpp and .ino?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions