From 0b96ec6b2c6ae94b1cbbd0d17ebf57bccec72699 Mon Sep 17 00:00:00 2001 From: iranl Date: Tue, 28 Jan 2025 15:36:37 +0100 Subject: [PATCH] Allow BLE transmit power up to 20 on newer ESP32 models --- README.md | 2 +- src/NukiOpenerWrapper.cpp | 23 +++++++++++++++++++++++ src/NukiWrapper.cpp | 23 +++++++++++++++++++++++ src/WebCfgServer.cpp | 8 ++++++++ 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d8da16..66798f5 100644 --- a/README.md +++ b/README.md @@ -285,7 +285,7 @@ In a browser navigate to the IP address assigned to the ESP32. - Lock: Nuki Bridge is running alongside Nuki Hub: Enable to allow Nuki Hub to co-exist with a Nuki Bridge by registering Nuki Hub as an (smartphone) app instead of a bridge. Changing this setting will require re-pairing. Enabling this setting is strongly discouraged as described in the "[Pairing with a Nuki Lock or Opener](#pairing-with-a-nuki-lock-or-opener)" section of this README, ***unless when used in [Hybrid mode](/HYBRID.md) (Official MQTT / Nuki Hub co-existance)*** - Opener: Nuki Bridge is running alongside Nuki Hub: Enable to allow Nuki Hub to co-exist with a Nuki Bridge by registering Nuki Hub as an (smartphone) app instead of a bridge. Changing this setting will require re-pairing. Enabling this setting is strongly discouraged as described in the "[Pairing with a Nuki Lock or Opener](#pairing-with-a-nuki-lock-or-opener)" section of this README - Restart if bluetooth beacons not received: Set to a positive integer to restart the Nuki Hub after the set amount of seconds has passed without receiving a bluetooth beacon from the Nuki device, set to -1 to disable, default 60. Because the bluetooth stack of the ESP32 can silently fail it is not recommended to disable this setting. -- BLE transmit power in dB: Set to a integer between -12 and 9 to set the Bluetooth transmit power, default 9. +- BLE transmit power in dB: Set to a integer between -12 and 9 (ESP32) or -12 and 20 (All newer ESP32 variants) to set the Bluetooth transmit power, default 9. - Update Nuki Hub and Lock/Opener time using NTP: Enable to update the ESP32 time and Nuki Lock and/or Nuki Opener time every 12 hours using a NTP time server. Updating the Nuki device time requires the Nuki security code / PIN to be set, see "[Nuki Lock PIN / Nuki Opener PIN](#nuki-lock-pin--nuki-opener-pin)" below. - NTP server: Set to the NTP server you want to use, defaults to "pool.ntp.org". If DHCP is used and NTP servers are provided using DHCP these will take precedence over the specified NTP server. diff --git a/src/NukiOpenerWrapper.cpp b/src/NukiOpenerWrapper.cpp index 28552f6..0538b5b 100644 --- a/src/NukiOpenerWrapper.cpp +++ b/src/NukiOpenerWrapper.cpp @@ -76,7 +76,30 @@ void NukiOpenerWrapper::readSettings() if(pwrLvl >= 9) { + #if defined(CONFIG_IDF_TARGET_ESP32) powerLevel = ESP_PWR_LVL_P9; + #else + if(pwrLvl >= 20) + { + powerLevel = ESP_PWR_LVL_P20; + } + else if(pwrLvl >= 18) + { + powerLevel = ESP_PWR_LVL_P18; + } + else if(pwrLvl >= 15) + { + powerLevel = ESP_PWR_LVL_P15; + } + else if(pwrLvl >= 12) + { + powerLevel = ESP_PWR_LVL_P12; + } + else + { + powerLevel = ESP_PWR_LVL_P9; + } + #endif } else if(pwrLvl >= 6) { diff --git a/src/NukiWrapper.cpp b/src/NukiWrapper.cpp index e6b8a6a..b056e86 100644 --- a/src/NukiWrapper.cpp +++ b/src/NukiWrapper.cpp @@ -82,7 +82,30 @@ void NukiWrapper::readSettings() if(pwrLvl >= 9) { + #if defined(CONFIG_IDF_TARGET_ESP32) powerLevel = ESP_PWR_LVL_P9; + #else + if(pwrLvl >= 20) + { + powerLevel = ESP_PWR_LVL_P20; + } + else if(pwrLvl >= 18) + { + powerLevel = ESP_PWR_LVL_P18; + } + else if(pwrLvl >= 15) + { + powerLevel = ESP_PWR_LVL_P15; + } + else if(pwrLvl >= 12) + { + powerLevel = ESP_PWR_LVL_P12; + } + else + { + powerLevel = ESP_PWR_LVL_P9; + } + #endif } else if(pwrLvl >= 6) { diff --git a/src/WebCfgServer.cpp b/src/WebCfgServer.cpp index 20331f5..d5a6e6f 100644 --- a/src/WebCfgServer.cpp +++ b/src/WebCfgServer.cpp @@ -3363,7 +3363,11 @@ bool WebCfgServer::processArgs(PsychicRequest *request, PsychicResponse* resp, S } else if(key == "TXPWR") { + #if defined(CONFIG_IDF_TARGET_ESP32) if(value.toInt() >= -12 && value.toInt() <= 9) + #else + if(value.toInt() >= -12 && value.toInt() <= 20) + #endif { if(_preferences->getInt(preference_ble_tx_power, 9) != value.toInt()) { @@ -5848,7 +5852,11 @@ esp_err_t WebCfgServer::buildNukiConfigHtml(PsychicRequest *request, PsychicResp printCheckBox(&response, "REGAPPOPN", "Opener: Nuki Bridge is running alongside Nuki Hub (needs re-pairing if changed)", _preferences->getBool(preference_register_opener_as_app), ""); } printInputField(&response, "RSBC", "Restart if bluetooth beacons not received (seconds; -1 to disable)", _preferences->getInt(preference_restart_ble_beacon_lost), 10, ""); + #if defined(CONFIG_IDF_TARGET_ESP32) printInputField(&response, "TXPWR", "BLE transmit power in dB (minimum -12, maximum 9)", _preferences->getInt(preference_ble_tx_power, 9), 10, ""); + #else + printInputField(&response, "TXPWR", "BLE transmit power in dB (minimum -12, maximum 20)", _preferences->getInt(preference_ble_tx_power, 9), 10, ""); + #endif printCheckBox(&response, "UPTIME", "Update Nuki Hub and Lock/Opener time using NTP", _preferences->getBool(preference_update_time, false), ""); printInputField(&response, "TIMESRV", "NTP server", _preferences->getString(preference_time_server, "pool.ntp.org").c_str(), 255, "");