From 05070d6964b0010c48b0df18d59e22b0937d2d99 Mon Sep 17 00:00:00 2001 From: Arthur Lutz Date: Mon, 13 Jul 2026 16:55:16 +0200 Subject: [PATCH] feat(SerialBLEInterface): add BLE_NO_PIN option to diable Bluetooth PIN --- src/helpers/esp32/SerialBLEInterface.cpp | 16 +++++++++++++++- variants/xiao_s3_wio/platformio.ini | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/helpers/esp32/SerialBLEInterface.cpp b/src/helpers/esp32/SerialBLEInterface.cpp index dcfa0e1e34..bf4b2cba27 100644 --- a/src/helpers/esp32/SerialBLEInterface.cpp +++ b/src/helpers/esp32/SerialBLEInterface.cpp @@ -29,8 +29,14 @@ void SerialBLEInterface::begin(const char* prefix, char* name, uint32_t pin_code BLEDevice::setMTU(MAX_FRAME_SIZE); BLESecurity sec; +#ifdef BLE_NO_PIN + // Attempt to NO_PIN + sec.setCapability(ESP_IO_CAP_NONE); + sec.setAuthenticationMode(ESP_LE_AUTH_BOND); +#else sec.setStaticPIN(pin_code); sec.setAuthenticationMode(ESP_LE_AUTH_REQ_SC_MITM_BOND); +#endif //BLEDevice::setPower(ESP_PWR_LVL_N8); @@ -43,11 +49,19 @@ void SerialBLEInterface::begin(const char* prefix, char* name, uint32_t pin_code // Create a BLE Characteristic pTxCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID_TX, BLECharacteristic::PROPERTY_READ | BLECharacteristic::PROPERTY_NOTIFY); +#ifdef BLE_NO_PIN + pTxCharacteristic->setAccessPermissions(ESP_GATT_PERM_READ); +#else pTxCharacteristic->setAccessPermissions(ESP_GATT_PERM_READ_ENC_MITM); +#endif pTxCharacteristic->addDescriptor(new BLE2902()); BLECharacteristic * pRxCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID_RX, BLECharacteristic::PROPERTY_WRITE); +#ifdef BLE_NO_PIN + pRxCharacteristic->setAccessPermissions(ESP_GATT_PERM_WRITE); +#else pRxCharacteristic->setAccessPermissions(ESP_GATT_PERM_WRITE_ENC_MITM); +#endif pRxCharacteristic->setCallbacks(this); pServer->getAdvertising()->addServiceUUID(SERVICE_UUID); @@ -129,7 +143,7 @@ void SerialBLEInterface::onWrite(BLECharacteristic* pCharacteristic, esp_ble_gat // ---------- public methods -void SerialBLEInterface::enable() { +void SerialBLEInterface::enable() { if (_isEnabled) return; _isEnabled = true; diff --git a/variants/xiao_s3_wio/platformio.ini b/variants/xiao_s3_wio/platformio.ini index db8c5a9486..7dd04c82c3 100644 --- a/variants/xiao_s3_wio/platformio.ini +++ b/variants/xiao_s3_wio/platformio.ini @@ -157,6 +157,7 @@ build_flags = -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -D BLE_PIN_CODE=123456 +; -D BLE_NO_PIN=1 -D DISPLAY_CLASS=SSD1306Display -D OFFLINE_QUEUE_SIZE=256 ; -D BLE_DEBUG_LOGGING=1