#include <BLEDevice.h> #include <BLEUtils.h> #include <BLEServer.h> #include <BLE2902.h> #define SERVICE_UUID "1811"//0x1811 ANS UUID #define UNREAD_ALERT_CHARACTERISTIC_UUID "2a45" //unread alert notification UUID #define NEW_ALERT_CHARACTERISTIC_UUID "2a46" #define CONTROL_POINT_CHARACTERISTIC_UUID "2a44" #define SUPPORTED_NEW_ALERT_CAT_CHAR "2a47" #define SUPPORTED_UNREAD_ALERT_CAT_CHAR "2a48" //4fafc201-1fb5-459e-8fcc-c5c9c331914b General BLE UUID //00001811-0000-1000-8000-00805f9b34fb General ANS UUID class MyServerCallbacks: public BLEServerCallbacks { void onConnect(BLEServer* pServer) { // deviceConnected = true; Serial.println("Connected"); }; void onDisconnect(BLEServer* pServer) { // deviceConnected = false; Serial.println("DIs-connected"); } }; void setup() { Serial.begin(115200); Serial.println("Starting BLE work!"); BLEDevice::init("ESP32_ANS_testing"); BLEServer *pServer = BLEDevice::createServer(); pServer->setCallbacks(new MyServerCallbacks()); BLEService *pService = pServer->createService(SERVICE_UUID); BLECharacteristic *pCharacteristic_1 = pService->createCharacteristic( UNREAD_ALERT_CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_INDICATE | BLECharacteristic::PROPERTY_NOTIFY ); BLECharacteristic *pCharacteristic_2 = pService->createCharacteristic( NEW_ALERT_CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_INDICATE | BLECharacteristic::PROPERTY_NOTIFY ); BLECharacteristic *pCharacteristic_3 = pService->createCharacteristic( CONTROL_POINT_CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_INDICATE | BLECharacteristic::PROPERTY_NOTIFY ); BLECharacteristic *pCharacteristic_4 = pService->createCharacteristic( SUPPORTED_NEW_ALERT_CAT_CHAR, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_INDICATE | BLECharacteristic::PROPERTY_NOTIFY ); BLECharacteristic *pCharacteristic_5 = pService->createCharacteristic( SUPPORTED_UNREAD_ALERT_CAT_CHAR, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_INDICATE | BLECharacteristic::PROPERTY_NOTIFY ); pCharacteristic_4->addDescriptor(new BLE2902()); pCharacteristic_5->addDescriptor(new BLE2902()); pCharacteristic_4->setValue("Hello World"); pService->start(); // BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility BLEAdvertising *pAdvertising = BLEDevice::getAdvertising(); pAdvertising->addServiceUUID(SERVICE_UUID); pAdvertising->setScanResponse(true); pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue pAdvertising->setMinPreferred(0x12); BLEDevice::startAdvertising(); Serial.println("Characteristic defined! Now you can read it in your phone!"); } void loop() { // put your main code here, to run repeatedly: delay(2000); }
Hi,
I wanted to read all the android notification using an embedded BLE device..
I have gone through BLE_ANS example which is in nRF51 SDK, All i want is to implement the same example on ESP32 board, so i started a BLE_Server with SERVICE_UUID = 0x1811(ANS), and with following characteristics(0x2a46 new alert UUID, 0x2a44 control point UUID, 0x2a45 unread alert UUID, 0x2a47 new alert category characteristic UUID, 0x2a48 unread alert category characteristic, also the parameters of all these characteristics are READ, WRITE, NOTIFY, INDICATE ) and i have also set the characteristic descriptor of 0x2a47 and 0x2a48 as 0x2902. After setting all this information i started advertising, and i also checked on nRF_connect android app on i was able to see all the services, characteristics, descriptors i have included.
Now my question is, after setting up all the above UUIDS, how can i start reading data from BLE, i mean how can i get data if a notification pops up on my phone?
PS: I have attached the ESP32 code which i have till now, thanks for the reply in advance