You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Board: ESP32 dev board
Core Installation version: 1.0.4
IDE name: Platform.io
Flash Frequency: 40Mhz
PSRAM enabled: no
Upload Speed: 460800
Computer OS: Windows 7
Description:
@chegewara
I am working on a BLE UART connection between Android and ESP32.
After connection established, it takes some time before the Android app is enabling notification on the UartTX characteristic. On the ESP32 I found no way to get informed if and when the BLE client enabled notifications. If the ESP32 notifies data immediately after a connection is established, the data is lost, because the Android app is not notified about it.
What I would need is a callback (or flag to test) that tells me that the Android app has enabled notifications on the characteristic. On nRF52 Arduino is a callback for the CCCD requests from the client.
Maybe I am blind, but I went through the BLE library up and down, but I cannot find anything that would give me this information.
Sketch: BLE Uart example
#include<BLEDevice.h>
#include<BLEServer.h>
#include<BLEUtils.h>
#include<BLE2902.h>
BLEServer *pServer = NULL;
BLECharacteristic *pTxCharacteristic;
bool deviceConnected = false;
bool oldDeviceConnected = false;
uint8_t txValue = 0;
// See the following for generating UUIDs:// https://www.uuidgenerator.net/
#defineSERVICE_UUID"6E400001-B5A3-F393-E0A9-E50E24DCCA9E"// UART service UUID
#defineCHARACTERISTIC_UUID_RX"6E400002-B5A3-F393-E0A9-E50E24DCCA9E"
#defineCHARACTERISTIC_UUID_TX"6E400003-B5A3-F393-E0A9-E50E24DCCA9E"classMyServerCallbacks : publicBLEServerCallbacks
{
voidonConnect(BLEServer *pServer)
{
deviceConnected = true;
};
voidonDisconnect(BLEServer *pServer)
{
deviceConnected = false;
}
};
classMyCallbacks : publicBLECharacteristicCallbacks
{
voidonWrite(BLECharacteristic *pCharacteristic)
{
std::string rxValue = pCharacteristic->getValue();
if (rxValue.length() > 0)
{
Serial.println("*********");
Serial.print("Received Value: ");
for (int i = 0; i < rxValue.length(); i++)
Serial.print(rxValue[i]);
Serial.println();
Serial.println("*********");
}
}
};
voidsetup()
{
Serial.begin(115200);
// Create the BLE DeviceBLEDevice::init("UART Service");
// Create the BLE Server
pServer = BLEDevice::createServer();
pServer->setCallbacks(newMyServerCallbacks());
// Create the BLE Service
BLEService *pService = pServer->createService(SERVICE_UUID);
// Create a BLE Characteristic
pTxCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_TX,
BLECharacteristic::PROPERTY_NOTIFY);
pTxCharacteristic->addDescriptor(newBLE2902());
BLECharacteristic *pRxCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_RX,
BLECharacteristic::PROPERTY_WRITE);
pRxCharacteristic->setCallbacks(newMyCallbacks());
// Start the service
pService->start();
// Start advertising
pServer->getAdvertising()->start();
Serial.println("Waiting a client connection to notify...");
}
voidloop()
{
if (deviceConnected)
{
// ============================================// First write might fail because client has not yet enabled notifications// ============================================
pTxCharacteristic->setValue(&txValue, 1);
pTxCharacteristic->notify();
txValue++;
delay(10); // bluetooth stack will go into congestion, if too many packets are sent
}
// disconnectingif (!deviceConnected && oldDeviceConnected)
{
delay(500); // give the bluetooth stack the chance to get things ready
pServer->startAdvertising(); // restart advertising
Serial.println("start advertising");
oldDeviceConnected = deviceConnected;
}
// connectingif (deviceConnected && !oldDeviceConnected)
{
// do stuff here on connecting
oldDeviceConnected = deviceConnected;
}
}```
### Debug Messages:
No crash, just missing a callback
The text was updated successfully, but these errors were encountered:
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
Hardware:
Board: ESP32 dev board
Core Installation version: 1.0.4
IDE name: Platform.io
Flash Frequency: 40Mhz
PSRAM enabled: no
Upload Speed: 460800
Computer OS: Windows 7
Description:
@chegewara
I am working on a BLE UART connection between Android and ESP32.
After connection established, it takes some time before the Android app is enabling notification on the UartTX characteristic. On the ESP32 I found no way to get informed if and when the BLE client enabled notifications. If the ESP32 notifies data immediately after a connection is established, the data is lost, because the Android app is not notified about it.
What I would need is a callback (or flag to test) that tells me that the Android app has enabled notifications on the characteristic. On nRF52 Arduino is a callback for the CCCD requests from the client.
Maybe I am blind, but I went through the BLE library up and down, but I cannot find anything that would give me this information.
Sketch: BLE Uart example
No crash, just missing a callback
The text was updated successfully, but these errors were encountered: