From 80e3cee006eb372d97cf7b98b69450bfbff90db9 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Sun, 14 Aug 2022 15:27:21 -0500 Subject: [PATCH] NimBLE enhanced logging (do not merge) (#1629) * Change log level to debug * Don't reinit active bluetooth services * Chmod +x before zip and adding to release --- .github/workflows/main_matrix.yml | 5 +++++ src/platform/esp32/ESP32Bluetooth.cpp | 15 ++++++++++++--- src/platform/esp32/ESP32Bluetooth.h | 1 + src/platform/esp32/main-esp32.cpp | 2 +- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main_matrix.yml b/.github/workflows/main_matrix.yml index ea1d5376b..698d3921a 100644 --- a/.github/workflows/main_matrix.yml +++ b/.github/workflows/main_matrix.yml @@ -425,6 +425,11 @@ jobs: with: name: firmware-${{ steps.version.outputs.version }} path: ./output + + - name: permissions + - run: | + chmod +x ./output/device-install.sh + chmod +x ./output/device-update.sh - name: Zip firmware run: zip -j -r ./firmware-${{ steps.version.outputs.version }}.zip ./output diff --git a/src/platform/esp32/ESP32Bluetooth.cpp b/src/platform/esp32/ESP32Bluetooth.cpp index d88caac08..0a6a21cef 100644 --- a/src/platform/esp32/ESP32Bluetooth.cpp +++ b/src/platform/esp32/ESP32Bluetooth.cpp @@ -56,7 +56,8 @@ class ESP32BluetoothToRadioCallback : public NimBLECharacteristicCallbacks } }; -class ESP32BluetoothFromRadioCallback : public NimBLECharacteristicCallbacks { +class ESP32BluetoothFromRadioCallback : public NimBLECharacteristicCallbacks +{ virtual void onRead(NimBLECharacteristic *pCharacteristic) { DEBUG_MSG("From Radio onread\n"); uint8_t fromRadioBytes[FromRadio_size]; @@ -91,7 +92,8 @@ class ESP32BluetoothServerCallback : public NimBLEServerCallbacks return passkey; } - virtual void onAuthenticationComplete(ble_gap_conn_desc *desc) { + virtual void onAuthenticationComplete(ble_gap_conn_desc *desc) + { DEBUG_MSG("BLE authentication complete\n"); if (passkeyShowing) { @@ -100,7 +102,8 @@ class ESP32BluetoothServerCallback : public NimBLEServerCallbacks } } - virtual void onDisconnect(NimBLEServer* pServer, ble_gap_conn_desc *desc) { + virtual void onDisconnect(NimBLEServer* pServer, ble_gap_conn_desc *desc) + { DEBUG_MSG("BLE disconnect\n"); } }; @@ -118,6 +121,12 @@ void ESP32Bluetooth::shutdown() pAdvertising->stop(); } +bool ESP32Bluetooth::isActive() +{ + NimBLEAdvertising *pAdvertising = NimBLEDevice::getAdvertising(); + return bleServer && (bleServer->getConnectedCount() > 0 || pAdvertising->isAdvertising()); +} + void ESP32Bluetooth::setup() { DEBUG_MSG("Initialise the ESP32 bluetooth module\n"); diff --git a/src/platform/esp32/ESP32Bluetooth.h b/src/platform/esp32/ESP32Bluetooth.h index 30e7c2774..76d9e47ab 100644 --- a/src/platform/esp32/ESP32Bluetooth.h +++ b/src/platform/esp32/ESP32Bluetooth.h @@ -8,6 +8,7 @@ class ESP32Bluetooth void setup(); void shutdown(); void clearBonds(); + bool isActive(); private: void setupService(); diff --git a/src/platform/esp32/main-esp32.cpp b/src/platform/esp32/main-esp32.cpp index 07b0eb9ee..fce405a01 100644 --- a/src/platform/esp32/main-esp32.cpp +++ b/src/platform/esp32/main-esp32.cpp @@ -46,7 +46,7 @@ void setBluetoothEnable(bool on) { if (!esp32Bluetooth) { esp32Bluetooth = new ESP32Bluetooth(); } - if (on) { + if (on && !esp32Bluetooth->isActive()) { esp32Bluetooth->setup(); } else { esp32Bluetooth->shutdown();