From 16dedc72c24acc83a667ff16071ca75142d52a86 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 13 Apr 2025 02:23:01 +0200 Subject: [PATCH] BLE improvements --- BLESerial.cpp | 8 ++++++++ BLESerial.h | 2 ++ Bluetooth.h | 1 + 3 files changed, 11 insertions(+) diff --git a/BLESerial.cpp b/BLESerial.cpp index 3460a86..80bcaf2 100644 --- a/BLESerial.cpp +++ b/BLESerial.cpp @@ -110,7 +110,10 @@ void BLESerial::begin(const char *name) { BLEDevice::setSecurityCallbacks(this); SetupSerialService(); + this->startAdvertising(); +} +void BLESerial::startAdvertising() { ble_adv = BLEDevice::getAdvertising(); ble_adv->addServiceUUID(BLE_SERIAL_SERVICE_UUID); ble_adv->setMinPreferred(0x20); @@ -119,6 +122,11 @@ void BLESerial::begin(const char *name) { ble_adv->start(); } +void BLESerial::stopAdvertising() { + ble_adv = BLEDevice::getAdvertising(); + ble_adv->stop(); +} + void BLESerial::end() { BLEDevice::deinit(); } void BLESerial::onWrite(BLECharacteristic *characteristic) { diff --git a/BLESerial.h b/BLESerial.h index 7b6d1c6..1dcae99 100644 --- a/BLESerial.h +++ b/BLESerial.h @@ -78,6 +78,8 @@ public: void begin(const char *name); void end(); + void startAdvertising(); + void stopAdvertising(); void onWrite(BLECharacteristic *characteristic); int available(); int peek(); diff --git a/Bluetooth.h b/Bluetooth.h index a93a2df..3d29178 100644 --- a/Bluetooth.h +++ b/Bluetooth.h @@ -266,6 +266,7 @@ char bt_devname[11]; // Serial.println("Authentication fail"); ble_authenticated = false; bt_state = BT_STATE_ON; + bt_update_passkey(); bt_security_setup(); } bt_allow_pairing = false;