From 180f61f499d657f3e69eb8c0e2c08964c8525893 Mon Sep 17 00:00:00 2001 From: iranl Date: Fri, 20 Dec 2024 21:09:23 +0100 Subject: [PATCH] Retain Input GPIO --- src/Config.h | 2 +- src/NukiNetwork.cpp | 5 +++-- src/NukiNetwork.h | 1 + src/PreferencesKeys.h | 7 +++++-- src/WebCfgServer.cpp | 27 ++++++++++++++++++++------- 5 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/Config.h b/src/Config.h index 131e84b..aa3e0ed 100644 --- a/src/Config.h +++ b/src/Config.h @@ -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-19" +#define NUKI_HUB_DATE "2024-12-20" #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" diff --git a/src/NukiNetwork.cpp b/src/NukiNetwork.cpp index 07dc3ba..2a1cc06 100644 --- a/src/NukiNetwork.cpp +++ b/src/NukiNetwork.cpp @@ -324,7 +324,7 @@ void NukiNetwork::initialize() buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_role}); publishString(_lockPath.c_str(), gpioPath, "input", false); buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pinEntry.pin)).c_str(), mqtt_topic_gpio_state}); - publishString(_lockPath.c_str(), gpioPath, std::to_string(digitalRead(pinEntry.pin)).c_str(), false); + publishString(_lockPath.c_str(), gpioPath, std::to_string(digitalRead(pinEntry.pin)).c_str(), _retainGpio); } break; case PinRole::GeneralOutput: @@ -353,6 +353,7 @@ void NukiNetwork::readSettings() _restartOnDisconnect = _preferences->getBool(preference_restart_on_disconnect, false); _checkUpdates = _preferences->getBool(preference_check_updates, false); _rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval, 0) * 1000; + _retainGpio = _preferences->getBool(preference_retain_gpio, false); if(_rssiPublishInterval == 0) { @@ -573,7 +574,7 @@ bool NukiNetwork::update() uint8_t pinState = digitalRead(pin) == HIGH ? 1 : 0; char gpioPath[250]; buildMqttPath(gpioPath, {mqtt_topic_gpio_prefix, (mqtt_topic_gpio_pin + std::to_string(pin)).c_str(), mqtt_topic_gpio_state}); - publishInt(_lockPath.c_str(), gpioPath, pinState, false); + publishInt(_lockPath.c_str(), gpioPath, pinState, _retainGpio); Log->print(F("GPIO ")); Log->print(pin); diff --git a/src/NukiNetwork.h b/src/NukiNetwork.h index 83b18d3..e0a5f07 100644 --- a/src/NukiNetwork.h +++ b/src/NukiNetwork.h @@ -151,6 +151,7 @@ private: bool _firstConnect = true; bool _publishDebugInfo = false; bool _logIp = true; + bool _retainGpio = false; std::vector _subscribedTopics; std::map _initTopics; int64_t _lastConnectedTs = 0; diff --git a/src/PreferencesKeys.h b/src/PreferencesKeys.h index a1486d9..f2e295d 100644 --- a/src/PreferencesKeys.h +++ b/src/PreferencesKeys.h @@ -112,6 +112,7 @@ #define preference_official_hybrid_actions (char*)"hybridAct" #define preference_official_hybrid_retry (char*)"hybridRtry" #define preference_keypad_check_code_enabled (char*)"kpChkEna" +#define preference_retain_gpio (char*)"retGpio" //NOT USER CHANGABLE #define preference_updater_version (char*)"updVer" @@ -216,6 +217,8 @@ inline void initPreferences(Preferences* preferences) preferences->putBool(preference_debug_hex_data, false); preferences->putBool(preference_debug_command, false); preferences->putBool(preference_connect_mode, true); + + preferences->putBool(preference_retain_gpio, false); #ifndef CONFIG_IDF_TARGET_ESP32H2 WiFi.begin(); @@ -375,7 +378,7 @@ private: 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_retain_gpio, preference_debug_connect, preference_debug_communication, preference_debug_readable_data, preference_debug_hex_data, preference_debug_command, preference_connect_mode }; @@ -390,7 +393,7 @@ private: preference_timecontrol_topic_per_entry, preference_keypad_topic_per_entry, preference_enable_bootloop_reset, preference_webserver_enabled, preference_restart_on_disconnect, preference_keypad_control_enabled, preference_keypad_info_enabled, preference_keypad_publish_code, preference_show_secrets, preference_timecontrol_control_enabled, preference_timecontrol_info_enabled, preference_register_as_app, preference_register_opener_as_app, preference_ip_dhcp_enabled, - preference_publish_authdata, preference_publish_debug_info, preference_official_hybrid_enabled, preference_mqtt_hass_enabled, + preference_publish_authdata, preference_publish_debug_info, preference_official_hybrid_enabled, preference_mqtt_hass_enabled, preference_retain_gpio, 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, diff --git a/src/WebCfgServer.cpp b/src/WebCfgServer.cpp index 33b0f6f..6370f78 100644 --- a/src/WebCfgServer.cpp +++ b/src/WebCfgServer.cpp @@ -3313,17 +3313,28 @@ void WebCfgServer::processGpioArgs(PsychicRequest *request) { int params = request->params(); std::vector pinConfiguration; - + for(int index = 0; index < params; index++) { const PsychicWebParameter* p = request->getParam(index); - PinRole role = (PinRole)p->value().toInt(); - if(role != PinRole::Disabled) + + if(p->name() == "RETGPIO") { - PinEntry entry; - entry.pin = p->name().toInt(); - entry.role = role; - pinConfiguration.push_back(entry); + if(_preferences->getBool(preference_retain_gpio, false) != (p->value() == "1")) + { + _preferences->putBool(preference_retain_gpio, (p->value() == "1")); + } + } + else + { + PinRole role = (PinRole)p->value().toInt(); + if(role != PinRole::Disabled) + { + PinEntry entry; + entry.pin = p->name().toInt(); + entry.role = role; + pinConfiguration.push_back(entry); + } } } @@ -4037,6 +4048,8 @@ esp_err_t WebCfgServer::buildGpioConfigHtml(PsychicRequest *request) response.print("
"); response.print("

GPIO Configuration

"); response.print(""); + printCheckBox(&response, "RETGPIO", "Retain Input GPIO MQTT state", _preferences->getBool(preference_retain_gpio, false), ""); + std::vector> options; String gpiopreselects = "var gpio = []; ";