I have my ArduinoBLE program mostly working but I am struggling to read the value of a BLEBoolCharacteristic in the eventHandler. My pointer knowledge is only suspect so that may be the issue. The definitions and the eventhandler are shown below.
//Definition of boolean characteristic
BLEBoolCharacteristic runmodeChar(BLE_UUID_RUNMODE,BLERead | BLEWrite | BLENotify);
// Add eventhandler.
runmodeChar.setEventHandler(BLEWritten, writeHandler);
//Definition of eventhandler
void writeHandler(BLEDevice central, BLECharacteristic characteristic){
//Event Handler passes a generic BLECharacteristic
// *** This is my problem. It always prints "runmode set to TRUE"
// *** even when I have set the boolean characteristic value =0
if (characteristic.value())
{
//If True -> in Run Mode
Serial.println("runmode set to TRUE");
} else
{
Serial.println("runmode set to FALSE");
}
}
So I was thinking, do I need to cast the BLECharacteristic to a BLEBoolCharacteristic inside the eventHandler hand then retrieve it's value?
newChar=(BLEBoolCharacteristic) characteristic
//Now use the value property to get a true or false.
if(newChar.value() ){
//Would I get a true now?
}else{
//would I get a false now?
}
Ultimately, in the eventHandler I want to read the value of my BLEBoolCharacteristic and make a decision accordingly, but for some reason I cannot. In other parts of the program when I have type BLEBoolCharacteristic I can read the value() directly and I don't have the same issue.
Thank You