From 7d0411cd15c366120ed4fe4e5b76c21d067304f9 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 10 Aug 2022 12:44:52 -0500 Subject: [PATCH] Esp32 NimBLE experiments (#1613) * Delete callbacks on bleServer on destruct * Trying things --- protobufs | 2 +- src/mesh/generated/mesh.pb.h | 4 ++-- src/platform/esp32/ESP32Bluetooth.cpp | 15 ++++++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/protobufs b/protobufs index addd11766..c473ed7a6 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit addd11766c2e76d4f84e715aa7f0d4e061b925a8 +Subproject commit c473ed7a6aa83c4be80382aa9abf8f8258be40a3 diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index b1688054d..d6b188816 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -257,10 +257,10 @@ typedef struct _Location { uint32_t expire; /* If true, only allow the original sender to update the location. */ bool locked; - /* Name of the location - max 40 chars */ + /* Name of the location - max 30 chars */ char name[30]; /* * - Description of the location - max 160 chars */ + Description of the location - max 100 chars */ char description[100]; } Location; diff --git a/src/platform/esp32/ESP32Bluetooth.cpp b/src/platform/esp32/ESP32Bluetooth.cpp index 563679339..ded88c325 100644 --- a/src/platform/esp32/ESP32Bluetooth.cpp +++ b/src/platform/esp32/ESP32Bluetooth.cpp @@ -109,9 +109,11 @@ class ESP32BluetoothServerCallback : public NimBLEServerCallbacks { screen->stopBluetoothPinScreen(); } } + virtual void onDisconnect(NimBLEServer* pServer, ble_gap_conn_desc *desc) { + DEBUG_MSG("BLE disconnect\n"); + } }; - static ESP32BluetoothToRadioCallback *toRadioCallbacks; static ESP32BluetoothFromRadioCallback *fromRadioCallbacks; @@ -120,6 +122,9 @@ void ESP32Bluetooth::shutdown() // Shutdown bluetooth for minimum power draw DEBUG_MSG("Disable bluetooth\n"); //Bluefruit.Advertising.stop(); + NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising(); + pAdvertising->reset(); + pAdvertising->stop(); } void ESP32Bluetooth::setup() @@ -175,7 +180,7 @@ void ESP32Bluetooth::setup() bleServer = NimBLEDevice::createServer(); ESP32BluetoothServerCallback *serverCallbacks = new ESP32BluetoothServerCallback(); - bleServer->setCallbacks(serverCallbacks); + bleServer->setCallbacks(serverCallbacks, true); NimBLEService *bleService = bleServer->createService(MESH_SERVICE_UUID); //NimBLECharacteristic *pNonSecureCharacteristic = bleService->createCharacteristic("1234", NIMBLE_PROPERTY::READ ); @@ -208,9 +213,9 @@ void ESP32Bluetooth::setup() //ToRadioCharacteristic->setCallbacks() NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising(); + pAdvertising->reset(); pAdvertising->addServiceUUID(MESH_SERVICE_UUID); - pAdvertising->start(); - + pAdvertising->start(0); } @@ -228,7 +233,7 @@ void ESP32Bluetooth::clearBonds() //Bluefruit.Periph.clearBonds(); //Bluefruit.Central.clearBonds(); - + NimBLEDevice::deleteAllBonds(); } void clearNVS() {