]> git.tnoah.ca Git - lora-radio.git/commitdiff
Guard against BT power cycle object duplication bug
authorjacob.eva <x00010@disroot.org>
Thu, 30 Jan 2025 16:54:34 +0000 (16:54 +0000)
committerjacob.eva <x00010@disroot.org>
Thu, 30 Jan 2025 16:54:34 +0000 (16:54 +0000)
Bluetooth.h

index bbb0c829d3c4957fd8131df53c33cbff25e5ce73..d14284f30b46a7d09137f60e449420d3845c9681 100644 (file)
@@ -38,6 +38,7 @@
   BLEUart SerialBT(BLE_RX_BUF);
   BLEDis  bledis;
   BLEBas  blebas;
+  bool SerialBT_init = false;
 #endif
 
 #define BT_PAIRING_TIMEOUT 35000
@@ -511,12 +512,14 @@ char bt_devname[11];
       // start device information service
       bledis.begin();
 
-      SerialBT.bufferTXD(true); // enable buffering
+      // Guard to ensure SerialBT service is not duplicated through BT being power cycled
+      if (!SerialBT_init) {
+          SerialBT.bufferTXD(true); // enable buffering
 
-      SerialBT.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM); // enable encryption for BLE serial
-      SerialBT.begin();
-
-      blebas.begin();
+          SerialBT.setPermission(SECMODE_ENC_WITH_MITM, SECMODE_ENC_WITH_MITM); // enable encryption for BLE serial
+          SerialBT.begin();
+          SerialBT_init = true;
+      }
 
       Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
       Bluefruit.Advertising.addTxPower();