diff options
Diffstat (limited to 'sensor/patchedBLE/examples/BLE_notify')
-rw-r--r-- | sensor/patchedBLE/examples/BLE_notify/BLE_notify.ino | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/sensor/patchedBLE/examples/BLE_notify/BLE_notify.ino b/sensor/patchedBLE/examples/BLE_notify/BLE_notify.ino index 5e915be..42b9e72 100644 --- a/sensor/patchedBLE/examples/BLE_notify/BLE_notify.ino +++ b/sensor/patchedBLE/examples/BLE_notify/BLE_notify.ino @@ -2,6 +2,7 @@ Video: https://www.youtube.com/watch?v=oCMOYS71NIU Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleNotify.cpp Ported to Arduino ESP32 by Evandro Copercini + updated by chegewara Create a BLE server that, once we receive a connection, will send periodic notifications. The service advertises itself as: 4fafc201-1fb5-459e-8fcc-c5c9c331914b @@ -27,7 +28,7 @@ BLEServer* pServer = NULL; BLECharacteristic* pCharacteristic = NULL; bool deviceConnected = false; bool oldDeviceConnected = false; -uint8_t value = 0; +uint32_t value = 0; // See the following for generating UUIDs: // https://www.uuidgenerator.net/ @@ -52,7 +53,7 @@ void setup() { Serial.begin(115200); // Create the BLE Device - BLEDevice::init("MyESP32"); + BLEDevice::init("ESP32"); // Create the BLE Server pServer = BLEDevice::createServer(); @@ -78,17 +79,21 @@ void setup() { pService->start(); // Start advertising - pServer->getAdvertising()->start(); + BLEAdvertising *pAdvertising = BLEDevice::getAdvertising(); + pAdvertising->addServiceUUID(SERVICE_UUID); + pAdvertising->setScanResponse(false); + pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter + BLEDevice::startAdvertising(); Serial.println("Waiting a client connection to notify..."); } void loop() { // notify changed value if (deviceConnected) { - pCharacteristic->setValue(&value, 1); + pCharacteristic->setValue((uint8_t*)&value, 4); pCharacteristic->notify(); value++; - delay(10); // bluetooth stack will go into congestion, if too many packets are sent + delay(3); // bluetooth stack will go into congestion, if too many packets are sent, in 6 hours test i was able to go as low as 3ms } // disconnecting if (!deviceConnected && oldDeviceConnected) { |