issue connecting callback with SetEventhandler for eventType BLERead
Hello,
I am working on a data logger. Data are saved on a SD card then at the end of the session data are uploaded to the phone. I have an issue with the connection of a callback on a read characteristic. I have already attached BLESubscribed, BLEUnsubscribed, BLEWritten but I do not managed to have a working callback on BLERead enventType.
My callback print a message on the Serial that I do not received and the PunchThrough android application returns ERROR 7 when I ask to read this characteristic.
Piece of my code, I have copied only parts related to this characteristic.
I believe it's an issue but i may have a wrong use of the callback event.... I do not know.
Thanks in advance
#define DATA_SIZE 68
//Custom GATT Characteristic to upload data file to phone
BLECharacteristic uploadChar("fd0e2894-e3f2-11eb-ba80-0242ac130004",BLERead, DATA_SIZE);
//callback
void uploadCharRead(BLEDevice central, BLECharacteristic characteristic);
// buffer to uplod
byte upload_buffer[DATA_SIZE];
void setup() {
//INIT BLE
initBLE();
}
void initBLE(){
pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected
// begin initialization
if (!BLE.begin()) {
Serial.println("starting BLE failed!");
while (1);
}
//BLE.debug(Serial);
// BLE.setAdvertisingInterval(40); // 25ms = 40 * 0.625 ms
// assign event handlers for connected, disconnected to peripheral
BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler);
BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);
//Add service and characteritics
BLE.setLocalName("KiteBoardSensing");
BLE.setAdvertisedService(kiteService); // add the service UUID
kiteService.addCharacteristic(dataChar);
kiteService.addCharacteristic(battChar);
kiteService.addCharacteristic(tareChar);
kiteService.addCharacteristic(recordChar);
kiteService.addCharacteristic(uploadChar);
BLE.addService(kiteService);
// assign callback
uploadChar.setEventHandler(BLERead, uploadCharRead);
//Start advertising
BLE.advertise();
Serial.println("Bluetooth device active, waiting for connections...");
}
void uploadCharRead(BLEDevice central, BLECharacteristic characteristic){
Serial.print("Upload characteristic event, read: ");
//open file for uploading
uploadChar.writeValue(upload_buffer,DATA_SIZE);
}
Hey! Were you able to resolve this? I'm attempting a similar callback setup instead using BLERead | BLEIndicate. I need the callback to fire off upon the central reading my data but it's not working either.