Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/helpers/esp32/SerialBLEInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions variants/xiao_s3_wio/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down