diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2018-11-22 19:30:14 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2018-11-22 22:34:59 +0100 |
commit | d88eee8fcf23e20ae76b3dd346b36af693849ccd (patch) | |
tree | 31407c1ef67b8e6a7f96189fc29906d70500346e /apps | |
parent | e8aa2eadf309fbc0c0e1418c6bee482e505fa09b (diff) | |
download | ble-toys-d88eee8fcf23e20ae76b3dd346b36af693849ccd.tar.gz ble-toys-d88eee8fcf23e20ae76b3dd346b36af693849ccd.tar.bz2 ble-toys-d88eee8fcf23e20ae76b3dd346b36af693849ccd.tar.xz ble-toys-d88eee8fcf23e20ae76b3dd346b36af693849ccd.zip |
o Working enabling of notifications.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/SoilMoisture.cpp | 4 | ||||
-rw-r--r-- | apps/ble-read-characteristic.cpp | 15 |
2 files changed, 15 insertions, 4 deletions
diff --git a/apps/SoilMoisture.cpp b/apps/SoilMoisture.cpp index d7c03bb..3129564 100644 --- a/apps/SoilMoisture.cpp +++ b/apps/SoilMoisture.cpp @@ -95,7 +95,7 @@ SoilMoisture::SoilMoisture(const shared_ptr<BluetoothGatt> &gatt, temperatureCharacteristic(temperatureCharacteristic), lightCharacteristic(lightCharacteristic) {} void SoilMoisture::writeAndRead(const BluetoothGattCharacteristicPtr &c, ByteBuffer &buffer) { - buffer.setCursor(0); + buffer.setPosition(0); uint8_t expectedCode = buffer.peek8(0); @@ -137,7 +137,7 @@ string SoilMoisture::getName(uint8_t sensor) { writeAndRead(soilMoistureCharacteristic, buffer); size_t bytesLeft = buffer.getBytesLeft(); uint8_t bytes[bytesLeft]; - buffer.copy(bytes, bytesLeft); + buffer.copyTo(bytes, bytesLeft); if (bytesLeft == 0 || bytesLeft < (bytes[0] + 1)) { throw runtime_error("Bad response from device. buffer size: " + to_string(bytesLeft) + ", buffer[0]=" + 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; } |