From e8aa2eadf309fbc0c0e1418c6bee482e505fa09b Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 19 Nov 2018 23:13:50 +0100 Subject: ble-read-characteristic: working READ mode, starting on NOTIFY. --- apps/SoilMoisture.cpp | 10 ++++------ apps/SoilMoisture.h | 4 ++-- apps/apps.h | 4 ++-- apps/ble-bts.cpp | 3 ++- apps/ble-read-characteristic.cpp | 8 +++++++- apps/mqtt_support.h | 2 +- 6 files changed, 18 insertions(+), 13 deletions(-) (limited to 'apps') diff --git a/apps/SoilMoisture.cpp b/apps/SoilMoisture.cpp index 79f168f..d7c03bb 100644 --- a/apps/SoilMoisture.cpp +++ b/apps/SoilMoisture.cpp @@ -4,23 +4,21 @@ namespace trygvis { namespace sensor { -#define BLUETOOTH_UUID_INITIALIZER \ - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb }; +using namespace trygvis::bluetooth; +using std::to_string; +using std::bitset; Uuid trygvis_io_base_uuid = {0x32, 0xd0, 0x00, 0x00, 0x03, 0x5d, 0x59, 0xc5, 0x70, 0xd3, 0xbc, 0x8e, 0x4a, 0x1f, 0xd8, 0x3f}; Uuid bluetooth_base_uuid = - {0x00, 0x00, 0x18, 0x0f, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}; + {0x00, 0x00, 0, 0, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}; const Uuid soil_moisture_service = makeUuid(trygvis_io_base_uuid, 0x00, 0x10); const Uuid soil_moisture_characteristic = makeUuid(trygvis_io_base_uuid, 0x00, 0x11); const Uuid temperature_characteristic = makeUuid(bluetooth_base_uuid, 0x2a, 0x1e); const Uuid light_characteristic = makeUuid(trygvis_io_base_uuid, 0x00, 0x12); -using namespace trygvis::bluetooth; -using std::to_string; - static void createGetSensorCount(ByteBuffer &buffer) { buffer diff --git a/apps/SoilMoisture.h b/apps/SoilMoisture.h index 3bfd0d8..4e6ae17 100644 --- a/apps/SoilMoisture.h +++ b/apps/SoilMoisture.h @@ -2,14 +2,14 @@ #include #include -#include +#include namespace trygvis { namespace sensor { using namespace trygvis::bluetooth; template -using o = std::experimental::optional; +using o = std::optional; enum class sm_cmd_code : uint8_t { SM_CMD_GET_SENSOR_COUNT = 1, diff --git a/apps/apps.h b/apps/apps.h index 21a25a3..d750543 100644 --- a/apps/apps.h +++ b/apps/apps.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include @@ -15,7 +15,7 @@ namespace trygvis { namespace apps { template -using o = std::experimental::optional; +using o = std::optional; namespace po = boost::program_options; using namespace log4cplus; diff --git a/apps/ble-bts.cpp b/apps/ble-bts.cpp index 3f79f2c..7b888d4 100644 --- a/apps/ble-bts.cpp +++ b/apps/ble-bts.cpp @@ -91,7 +91,8 @@ public: cout << "Reading temp value" << endl; - auto buf = gatt->readValue(tmc); + StaticByteBuffer<100> response; + auto buf = gatt->readValue(tmc, response); cout << "bytes " << buf.getSize() << endl; diff --git a/apps/ble-read-characteristic.cpp b/apps/ble-read-characteristic.cpp index 19bbfa3..8a0a7b6 100644 --- a/apps/ble-read-characteristic.cpp +++ b/apps/ble-read-characteristic.cpp @@ -67,7 +67,7 @@ public: } int with_device(const shared_ptr &device, const Uuid &service_uuid, - const Uuid &characteristic_uuid) { + const Uuid &characteristic_uuid) { cout << "Connecting to device: " << device->getMac().str() << endl; auto gatt = device->connectGatt(); @@ -98,6 +98,12 @@ public: auto response = gatt->readValue(characteristic, buf); 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); + } else { + cout << "Unsupported op mode." << endl; } return EXIT_SUCCESS; diff --git a/apps/mqtt_support.h b/apps/mqtt_support.h index ab319fd..0ba6b18 100644 --- a/apps/mqtt_support.h +++ b/apps/mqtt_support.h @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include "mosquitto.h" #include "apps.h" -- cgit v1.2.3