Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to esp-nimble-cpp 2.0.1 + Allow runtime choice of BLE connect mode and Nuki BLE debug logging #564

Merged
merged 2 commits into from
Dec 18, 2024
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ In a browser navigate to the IP address assigned to the ESP32.

- Nuki Smartlock enabled: Enable if you want Nuki Hub to connect to a Nuki Lock (1.0-4.0)
- Nuki Opener enabled: Enable if you want Nuki Hub to connect to a Nuki Opener
- New Nuki Bluetooth connection mode (disable if there are connection issues): Enable to use the latest Nuki BLE connection mode (recommended). Disable if you have issues communicating with the lock/opener

#### Advanced Nuki Configuration

Expand Down
48 changes: 3 additions & 45 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extra_scripts =
post:pio_package_post.py
build_flags =
${env.build_flags}
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0
-DCONFIG_BT_NIMBLE_LOG_LEVEL=0

Expand Down Expand Up @@ -138,12 +138,6 @@ build_flags =
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0
-DCONFIG_BT_NIMBLE_LOG_LEVEL=0
-DDEBUG_NUKIHUB
-DDEBUG_SENSE_NUKI
-DDEBUG_NUKI_COMMAND
-DDEBUG_NUKI_CONNECT
-DDEBUG_NUKI_COMMUNICATION
;-DDEBUG_NUKI_HEX_DATA
-DDEBUG_NUKI_READABLE_DATA

[env:esp32-c3_dbg]
extends = env:esp32-c3
Expand All @@ -155,13 +149,7 @@ build_flags =
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0
-DCONFIG_BT_NIMBLE_LOG_LEVEL=0
-DDEBUG_NUKIHUB
-DDEBUG_SENSE_NUKI
-DDEBUG_NUKI_COMMAND
-DDEBUG_NUKI_CONNECT
-DDEBUG_NUKI_COMMUNICATION
;-DDEBUG_NUKI_HEX_DATA
-DDEBUG_NUKI_READABLE_DATA
-DDEBUG_NUKIHUB

[env:esp32-c6_dbg]
extends = env:esp32-c6
Expand All @@ -174,12 +162,6 @@ build_flags =
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0
-DCONFIG_BT_NIMBLE_LOG_LEVEL=0
-DDEBUG_NUKIHUB
-DDEBUG_SENSE_NUKI
-DDEBUG_NUKI_COMMAND
-DDEBUG_NUKI_CONNECT
-DDEBUG_NUKI_COMMUNICATION
;-DDEBUG_NUKI_HEX_DATA
-DDEBUG_NUKI_READABLE_DATA

[env:esp32-h2_dbg]
extends = env:esp32-h2
Expand All @@ -193,12 +175,6 @@ build_flags =
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0
-DCONFIG_BT_NIMBLE_LOG_LEVEL=0
-DDEBUG_NUKIHUB
-DDEBUG_SENSE_NUKI
-DDEBUG_NUKI_COMMAND
-DDEBUG_NUKI_CONNECT
-DDEBUG_NUKI_COMMUNICATION
;-DDEBUG_NUKI_HEX_DATA
-DDEBUG_NUKI_READABLE_DATA

[env:esp32-s3_dbg]
extends = env:esp32-s3
Expand All @@ -211,12 +187,6 @@ build_flags =
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0
-DCONFIG_BT_NIMBLE_LOG_LEVEL=0
-DDEBUG_NUKIHUB
-DDEBUG_SENSE_NUKI
-DDEBUG_NUKI_COMMAND
-DDEBUG_NUKI_CONNECT
-DDEBUG_NUKI_COMMUNICATION
;-DDEBUG_NUKI_HEX_DATA
-DDEBUG_NUKI_READABLE_DATA

[env:esp32-s3-oct_dbg]
extends = env:esp32-s3-oct
Expand All @@ -229,12 +199,6 @@ build_flags =
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0
-DCONFIG_BT_NIMBLE_LOG_LEVEL=0
-DDEBUG_NUKIHUB
-DDEBUG_SENSE_NUKI
-DDEBUG_NUKI_COMMAND
-DDEBUG_NUKI_CONNECT
-DDEBUG_NUKI_COMMUNICATION
;-DDEBUG_NUKI_HEX_DATA
-DDEBUG_NUKI_READABLE_DATA

[env:esp32-solo1_dbg]
extends = env:esp32-solo1
Expand All @@ -246,10 +210,4 @@ build_flags =
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG
-DCONFIG_NIMBLE_CPP_LOG_LEVEL=0
-DCONFIG_BT_NIMBLE_LOG_LEVEL=0
-DDEBUG_NUKIHUB
-DDEBUG_SENSE_NUKI
-DDEBUG_NUKI_COMMAND
-DDEBUG_NUKI_CONNECT
-DDEBUG_NUKI_COMMUNICATION
;-DDEBUG_NUKI_HEX_DATA
-DDEBUG_NUKI_READABLE_DATA
-DDEBUG_NUKIHUB
1 change: 1 addition & 0 deletions sdkconfig.defaults
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ CONFIG_HEAP_TASK_TRACKING=n
CONFIG_LOG_COLORS=n
CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=n
CONFIG_LOG_MAXIMUM_LEVEL=4
CONFIG_ARDUHAL_ESP_LOG=y
CONFIG_ETH_ENABLED=y
CONFIG_ETH_USE_SPI_ETHERNET=y
CONFIG_ETH_SPI_ETHERNET_W5500=y
Expand Down
6 changes: 3 additions & 3 deletions sdkconfig.release.defaults
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CONFIG_LOG_DEFAULT_LEVEL_NONE=y
CONFIG_LOG_DEFAULT_LEVEL=0
CONFIG_ESP_IPC_TASK_STACK_SIZE=1024
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
CONFIG_LOG_DEFAULT_LEVEL=4
CONFIG_ESP_IPC_TASK_STACK_SIZE=2048
CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y
CONFIG_BOOTLOADER_LOG_LEVEL=1
2 changes: 1 addition & 1 deletion src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#define NUKI_HUB_VERSION "9.05"
#define NUKI_HUB_VERSION_INT (uint32_t)905
#define NUKI_HUB_BUILD "unknownbuildnr"
#define NUKI_HUB_DATE "2024-12-16"
#define NUKI_HUB_DATE "2024-12-18"

#define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest"
#define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json"
Expand Down
8 changes: 7 additions & 1 deletion src/NukiOpenerWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,13 @@ NukiOpenerWrapper::~NukiOpenerWrapper()

void NukiOpenerWrapper::initialize()
{
_nukiOpener.initialize();
_nukiOpener.setDebugConnect(_preferences->getBool(preference_debug_connect, false));
_nukiOpener.setDebugCommunication(_preferences->getBool(preference_debug_communication, false));
_nukiOpener.setDebugReadableData(_preferences->getBool(preference_debug_readable_data, false));
_nukiOpener.setDebugHexData(_preferences->getBool(preference_debug_hex_data, false));
_nukiOpener.setDebugCommand(_preferences->getBool(preference_debug_command, false));

_nukiOpener.initialize(_preferences->getBool(preference_connect_mode, false));
_nukiOpener.registerBleScanner(_bleScanner);
_nukiOpener.setEventHandler(this);
_nukiOpener.setConnectTimeout(3);
Expand Down
8 changes: 7 additions & 1 deletion src/NukiWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ NukiWrapper::~NukiWrapper()

void NukiWrapper::initialize()
{
_nukiLock.initialize();
_nukiLock.setDebugConnect(_preferences->getBool(preference_debug_connect, false));
_nukiLock.setDebugCommunication(_preferences->getBool(preference_debug_communication, false));
_nukiLock.setDebugReadableData(_preferences->getBool(preference_debug_readable_data, false));
_nukiLock.setDebugHexData(_preferences->getBool(preference_debug_hex_data, false));
_nukiLock.setDebugCommand(_preferences->getBool(preference_debug_command, false));

_nukiLock.initialize(_preferences->getBool(preference_connect_mode, false));
_nukiLock.registerBleScanner(_bleScanner);
_nukiLock.setEventHandler(this);
_nukiLock.setConnectTimeout(3);
Expand Down
20 changes: 18 additions & 2 deletions src/PreferencesKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
#define preference_wifi_ssid (char*)"wifiSSID"
#define preference_wifi_pass (char*)"wifiPass"
#define preference_disable_network_not_connected (char*)"disNtwNoCon"
#define preference_debug_connect (char*)"dbgConnect"
#define preference_debug_communication (char*)"dbgCommu"
#define preference_debug_readable_data (char*)"dbgReadData"
#define preference_debug_hex_data (char*)"dbgHexData"
#define preference_debug_command (char*)"dbgCommand"
#define preference_connect_mode (char*)"nukiConnMode"

// CHANGE DOES NOT REQUIRE REBOOT TO TAKE EFFECT
#define preference_find_best_rssi (char*)"nwbestrssi"
Expand Down Expand Up @@ -203,6 +209,13 @@ inline void initPreferences(Preferences* preferences)
preferences->putInt(preference_query_interval_configuration, 3600);
preferences->putInt(preference_query_interval_battery, 1800);
preferences->putInt(preference_query_interval_keypad, 1800);

preferences->putBool(preference_debug_connect, false);
preferences->putBool(preference_debug_communication, false);
preferences->putBool(preference_debug_readable_data, false);
preferences->putBool(preference_debug_hex_data, false);
preferences->putBool(preference_debug_command, false);
preferences->putBool(preference_connect_mode, false);

#ifndef CONFIG_IDF_TARGET_ESP32H2
WiFi.begin();
Expand Down Expand Up @@ -362,7 +375,9 @@ class DebugPreferences
preference_network_custom_rst, preference_network_custom_cs, preference_network_custom_sck, preference_network_custom_miso, preference_network_custom_mosi,
preference_network_custom_pwr, preference_network_custom_mdio, preference_ntw_reconfigure, preference_lock_max_auth_entry_count, preference_opener_max_auth_entry_count,
preference_auth_control_enabled, preference_auth_topic_per_entry, preference_auth_info_enabled, preference_auth_max_entries, preference_wifi_ssid, preference_wifi_pass,
preference_keypad_check_code_enabled, preference_disable_network_not_connected, preference_mqtt_hass_enabled, preference_hass_device_discovery
preference_keypad_check_code_enabled, preference_disable_network_not_connected, preference_mqtt_hass_enabled, preference_hass_device_discovery,
preference_debug_connect, preference_debug_communication, preference_debug_readable_data, preference_debug_hex_data, preference_debug_command, preference_connect_mode

};
std::vector<char*> _redact =
{
Expand All @@ -378,7 +393,8 @@ class DebugPreferences
preference_publish_authdata, preference_publish_debug_info, preference_official_hybrid_enabled, preference_mqtt_hass_enabled,
preference_official_hybrid_actions, preference_official_hybrid_retry, preference_conf_info_enabled, preference_disable_non_json, preference_update_from_mqtt,
preference_auth_control_enabled, preference_auth_topic_per_entry, preference_auth_info_enabled, preference_webserial_enabled, preference_hass_device_discovery,
preference_ntw_reconfigure, preference_keypad_check_code_enabled, preference_disable_network_not_connected, preference_find_best_rssi
preference_ntw_reconfigure, preference_keypad_check_code_enabled, preference_disable_network_not_connected, preference_find_best_rssi,
preference_debug_connect, preference_debug_communication, preference_debug_readable_data, preference_debug_hex_data, preference_debug_command, preference_connect_mode
};
std::vector<char*> _bytePrefs =
{
Expand Down
68 changes: 68 additions & 0 deletions src/WebCfgServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,56 @@ bool WebCfgServer::processArgs(PsychicRequest *request, String& message)
//configChanged = true;
}
}
else if(key == "DBGCONN")
{
if(_preferences->getBool(preference_debug_connect, false) != (value == "1"))
{
_preferences->putBool(preference_debug_connect, (value == "1"));
Log->print(F("Setting changed: "));
Log->println(key);
configChanged = true;
}
}
else if(key == "DBGCOMMU")
{
if(_preferences->getBool(preference_debug_communication, false) != (value == "1"))
{
_preferences->putBool(preference_debug_communication, (value == "1"));
Log->print(F("Setting changed: "));
Log->println(key);
configChanged = true;
}
}
else if(key == "DBGREAD")
{
if(_preferences->getBool(preference_debug_readable_data, false) != (value == "1"))
{
_preferences->putBool(preference_debug_readable_data, (value == "1"));
Log->print(F("Setting changed: "));
Log->println(key);
configChanged = true;
}
}
else if(key == "DBGHEX")
{
if(_preferences->getBool(preference_debug_hex_data, false) != (value == "1"))
{
_preferences->putBool(preference_debug_hex_data, (value == "1"));
Log->print(F("Setting changed: "));
Log->println(key);
configChanged = true;
}
}
else if(key == "DBGCOMM")
{
if(_preferences->getBool(preference_debug_command, false) != (value == "1"))
{
_preferences->putBool(preference_debug_command, (value == "1"));
Log->print(F("Setting changed: "));
Log->println(key);
configChanged = true;
}
}
else if(key == "ACLLVLCHANGED")
{
aclLvlChanged = true;
Expand Down Expand Up @@ -2728,6 +2778,16 @@ bool WebCfgServer::processArgs(PsychicRequest *request, String& message)
configChanged = true;
}
}
else if(key == "CONNMODE")
{
if(_preferences->getBool(preference_connect_mode, false) != (value == "1"))
{
_preferences->putBool(preference_connect_mode, (value == "1"));
Log->print(F("Setting changed: "));
Log->println(key);
configChanged = true;
}
}
else if(key == "CREDUSER")
{
if(value == "#")
Expand Down Expand Up @@ -3613,6 +3673,13 @@ esp_err_t WebCfgServer::buildAdvancedConfigHtml(PsychicRequest *request)
}
printInputField(&response, "OTAUPD", "Custom URL to update Nuki Hub updater", "", 255, "");
printInputField(&response, "OTAMAIN", "Custom URL to update Nuki Hub", "", 255, "");

printCheckBox(&response, "DBGCONN", "Enable Nuki connect debug logging", _preferences->getBool(preference_debug_connect, false), "");
printCheckBox(&response, "DBGCOMMU", "Enable Nuki communication debug logging", _preferences->getBool(preference_debug_communication, false), "");
printCheckBox(&response, "DBGREAD", "Enable Nuki readable data debug logging", _preferences->getBool(preference_debug_readable_data, false), "");
printCheckBox(&response, "DBGHEX", "Enable Nuki hex data debug logging", _preferences->getBool(preference_debug_hex_data, false), "");
printCheckBox(&response, "DBGCOMM", "Enable Nuki command debug logging", _preferences->getBool(preference_debug_command, false), "");

response.print("</table>");

response.print("<br><input type=\"submit\" name=\"submit\" value=\"Save\">");
Expand Down Expand Up @@ -3930,6 +3997,7 @@ esp_err_t WebCfgServer::buildNukiConfigHtml(PsychicRequest *request)
response.print("<table>");
printCheckBox(&response, "LOCKENA", "Nuki Lock enabled", _preferences->getBool(preference_lock_enabled), "");
printCheckBox(&response, "OPENA", "Nuki Opener enabled", _preferences->getBool(preference_opener_enabled), "");
printCheckBox(&response, "CONNMODE", "New Nuki Bluetooth connection mode (disable if there are connection issues)", _preferences->getBool(preference_connect_mode, false), "");
response.print("</table><br>");
response.print("<h3>Advanced Nuki Configuration</h3>");
response.print("<table>");
Expand Down
2 changes: 1 addition & 1 deletion src/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dependencies:

esp-nimble-cpp:
git: https://github.com/h2zero/esp-nimble-cpp.git
version: 6c85cfa6c3d5ec9c46b87c761925b1bcb5c3827c
version: 0d13044703b16df38b7884f9261ef0d79976726e

espressif/libsodium: "^1.0.20~2"

Expand Down
33 changes: 24 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "esp_https_ota.h"
#include "esp_task_wdt.h"
#include "Config.h"
#include "esp32-hal-log.h"

#ifndef NUKI_HUB_UPDATER
#include "NukiWrapper.h"
Expand Down Expand Up @@ -115,17 +116,31 @@ int _log_vprintf(const char *fmt, va_list args)
void setReroute()
{
esp_log_set_vprintf(_log_vprintf);

#ifdef DEBUG_NUKIHUB
esp_log_level_set("*", ESP_LOG_DEBUG);
esp_log_level_set("nvs", ESP_LOG_INFO);
esp_log_level_set("wifi", ESP_LOG_INFO);
#else
esp_log_level_set("*", ESP_LOG_NONE);
esp_log_level_set("httpd", ESP_LOG_ERROR);
esp_log_level_set("httpd_sess", ESP_LOG_ERROR);
esp_log_level_set("httpd_parse", ESP_LOG_ERROR);
esp_log_level_set("httpd_txrx", ESP_LOG_ERROR);
esp_log_level_set("httpd_uri", ESP_LOG_ERROR);
esp_log_level_set("event", ESP_LOG_ERROR);
esp_log_level_set("psychic", ESP_LOG_ERROR);
esp_log_level_set("ARDUINO", ESP_LOG_DEBUG);
esp_log_level_set("nvs", ESP_LOG_ERROR);
esp_log_level_set("wifi", ESP_LOG_ERROR);

#endif

if(preferences->getBool(preference_mqtt_log_enabled))
{
esp_log_level_set("*", ESP_LOG_INFO);
esp_log_level_set("mqtt", ESP_LOG_NONE);
}
else
{
esp_log_level_set("*", ESP_LOG_DEBUG);
esp_log_level_set("nvs", ESP_LOG_INFO);
esp_log_level_set("wifi", ESP_LOG_INFO);
}

}
#endif

Expand Down Expand Up @@ -174,13 +189,13 @@ void networkTask(void *pvParameters)
network->update();
bool connected = network->isConnected();

#ifdef DEBUG_NUKIHUB
#ifndef NUKI_HUB_UPDATER
if(connected && reroute)
{
reroute = false;
setReroute();
}
#endif
#endif

#ifndef NUKI_HUB_UPDATER
wifiConnected = network->wifiConnected();
Expand Down
Loading