Hi,
I'm trying to read the value from a Characteristic with getValue(), but it is not working.
I provide here a minimum working example of the problem, where I write the value to the characteristic, and then try to read it. connectTime is the time when the central connects:
void BLESetupClass::loop() {
// Check if someone subscribed to the salt characteristic
if (millis() - connectTime > 100 && millis() - connectTime < 1000) {
connectTime -= 1000;
uint8_t currentSalt[4] = {0x00, 0x00, 0x04, 0x08};
// Write the new salt to the characteristic so we have something to read
currentSalt[0] = 0x10;
saltCharacteristic.setValue(currentSalt, 4);
// Set to a different value so we can see if it changes
currentSalt[0] = 0x20;
ssize_t retVal = saltCharacteristic.getValue(currentSalt, 4);
// Set the value, we will see if 0x10 was read, it works, if 0x20 was read, it doesn't work
saltCharacteristic.setValue(currentSalt, 4);
Log.info("Salt Notified: %02X%02X%02X%02X", currentSalt[0], currentSalt[1], currentSalt[2], currentSalt[3]);
// Lets also check if it returned the expected 4 bytes
Log.info("Salt Retval: %d", retVal);
}
}
The output I'm getting is this:
0000004640 [app] INFO: Connected to 58:C1:D7:A7:50:C5
0000004640 [wiring.ble] TRACE: Connected
0000004641 [app] INFO: Salt Notified: 20000408
0000004641 [app] INFO: Salt Retval: 0
Where you can see that the return value is 0 (nothing was read) and the notified value is the 0x20 (on the first byte) that is the original value of the currentSalt
variable. Everything indicates that nothing was read and I have no clue why.
With nrfConnect, I can see that the value is indeed being written correctly, so it's strange that it can't be read.
Does anyone know what is going on?
Thanks!
Pedro