From 09711d12d0f40308b727488f7f508d96ee3d5f0a Mon Sep 17 00:00:00 2001 From: Robert Marshall Date: Sat, 13 Nov 2021 10:04:51 +0000 Subject: [PATCH] Retransmit changes to keep clients in sync --- src/BluetoothLEDCallback.cpp | 7 +++++-- src/BluetoothService.cpp | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/BluetoothLEDCallback.cpp b/src/BluetoothLEDCallback.cpp index 7cfc8e7..41f8ede 100644 --- a/src/BluetoothLEDCallback.cpp +++ b/src/BluetoothLEDCallback.cpp @@ -3,10 +3,13 @@ class BluetoothLEDCallback : public BLECharacteristicCallbacks { JsonLightControl *_lightControl; + std::string _json; void onWrite(BLECharacteristic *characteristic) { - std::string value = characteristic->getValue(); - _lightControl->action(value); + _json = characteristic->getValue(); + _lightControl->action(_json); + characteristic->setValue(_json); + characteristic->indicate(); } public: diff --git a/src/BluetoothService.cpp b/src/BluetoothService.cpp index 5c5f11d..fa452ac 100644 --- a/src/BluetoothService.cpp +++ b/src/BluetoothService.cpp @@ -26,11 +26,12 @@ public: void init() { BLEDevice::init(_serviceName); + //BLEDevice::setMTU(517); _server = BLEDevice::createServer(); _service = _server->createService(SERVICE_UUID); _server->setCallbacks(new BLEAdvertisingRestartCallback()); - _characteristic = _service->createCharacteristic(CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE); + _characteristic = _service->createCharacteristic(CHARACTERISTIC_UUID, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_WRITE | BLECharacteristic::PROPERTY_INDICATE); _characteristic->setCallbacks(_callbacks); }