diff options
Diffstat (limited to 'apps/ble-read-characteristic.cpp')
-rw-r--r-- | apps/ble-read-characteristic.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/apps/ble-read-characteristic.cpp b/apps/ble-read-characteristic.cpp index 8a0a7b6..a11b0cf 100644 --- a/apps/ble-read-characteristic.cpp +++ b/apps/ble-read-characteristic.cpp @@ -1,5 +1,6 @@ #include <stdexcept> #include <iostream> +#include <thread> #include <vector> #include <boost/uuid/uuid_io.hpp> #include "ble/Bluetooth.h" @@ -100,8 +101,18 @@ public: cout << "Got data, size=" << response.getSize() << endl; } else if (op_mode == op::NOTIFY) { auto cccd = characteristic.get()->getDescriptor(trygvis::bluetooth::uuids::CLIENT_CHARACTERISTIC_CONFIG); -// cccd->setValue(BluetoothGattDescriptor::ENABLE_NOTIFICATION_VALUE); - gatt->setCharacteristicNotification(cccd, true); + + if (!cccd) { + cout << "The characteristic does not have a CCCD" << endl; + } else { + cerr << "Enabling notifications" << endl; + cccd->setValue(ByteBuffer::wrapInitialized(BluetoothGattDescriptor::ENABLE_NOTIFICATION_VALUE)); + gatt->setCharacteristicNotification(cccd, true); + gatt->write(cccd); + + cout << "sleeping" << endl; + std::this_thread::sleep_for(10s); + } } else { cout << "Unsupported op mode." << endl; } |