ESP32 BLE response on notification

I'm currently messing around with two ESP32 and trying to connect them via BLE. So far i can send a notification from the server to the client and do a write from the client that the server can see.

I'm trying to get a response on a nofity, and my thoughts was to do a write within the notifyCallback. However the ESP stalls when it reaches the line where it needs to send the data back. "pRemoteCharacteristic->writeValue(...);" This line works perfectly in the loop function, and in my test i can send data to the server in the loop function, but whenever it reaches the line within the callBack void it stalls. I never get to see the serial print of "this print never sends.." and all other communication stops (sending new updates in the loop function and also receiving data from the server via notify's).

Am I doing something wrong? Is there another way of sending a response back to the server? Want to send the same data it received in the notify back - to ensure the right data got transferred. Any other suggestions how to achieve this?

I'm using the standard "BLE_Client" and "BLE_Server" exampels for the ESP32 BLE in the Arduino IDE environment. Snip of the stalling code below.

Hope you can help me - thanks in advance.

Martin

static void notifyCallback(BLERemoteCharacteristic* pBLERemoteCharacteristic,
uint8_t* pData,
size_t length,
bool isNotify) {
  Serial.print("recieved data: ");
  Serial.println((char*)pData);

  newValue = (char*)pData;
  delay(400);
  Serial.println("new value is " + newValue + " with the length: " + newValue.length());
  String newValue2 = "another sting"; //also tried to send newValue - but same result
  pRemoteCharacteristic->writeValue(newValue2.c_str(), newValue2.length());
  Serial.println("This print never sends..");

I

suggestion #1, I would remove the blocking delay() from callBack function

suggestion #2, I would have a global variable String that's receiving the data in the callback, and later in the main loop(), invoke the write function to send the same data ( like how you wanted ) back to a server,

Of course I would have some variable as flag ensuring the data is sent (written) just once

my point here do some
pRemoteCharacteristic->writeValue() stuffs within the main loop

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.