NTP improvements

This commit is contained in:
iranl
2025-01-15 21:17:41 +01:00
parent 1c4b5b0e33
commit e42e8eb5b3
5 changed files with 58 additions and 13 deletions

View File

@@ -72,6 +72,7 @@
#define preference_connect_mode (char*)"nukiConnMode"
#define preference_http_auth_type (char*)"httpdAuthType"
#define preference_update_time (char*)"updateTime"
#define preference_time_server (char*)"timeServer"
#define preference_mqtt_ssl_enabled (char*)"mqttSSLena"
#define preference_lock_gemini_pin (char*)"geminiPin"
#define preference_lock_gemini_enabled (char*)"geminiena"
@@ -116,6 +117,7 @@
#define preference_network_timeout (char*)"nettmout"
#define preference_restart_on_disconnect (char*)"restdisc"
#define preference_publish_debug_info (char*)"pubdbg"
#define preference_enable_debug_mode (char*)"enadbg"
#define preference_official_hybrid_actions (char*)"hybridAct"
#define preference_official_hybrid_retry (char*)"hybridRtry"
#define preference_keypad_check_code_enabled (char*)"kpChkEna"
@@ -178,6 +180,7 @@ inline void initPreferences(Preferences* preferences)
uint32_t advancedOpenerConfigAclPrefs[21] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
preferences->putBytes(preference_conf_opener_advanced_acl, (byte*)(&advancedOpenerConfigAclPrefs), sizeof(advancedOpenerConfigAclPrefs));
preferences->putString(preference_mqtt_lock_path, "nukihub");
preferences->putString(preference_time_server, "pool.ntp.org");
preferences->putBool(preference_check_updates, true);
preferences->putBool(preference_opener_continuous_mode, false);
@@ -232,6 +235,7 @@ inline void initPreferences(Preferences* preferences)
preferences->putBool(preference_connect_mode, true);
preferences->putBool(preference_http_auth_type, false);
preferences->putBool(preference_retain_gpio, false);
preferences->putBool(preference_enable_debug_mode, false);
#ifndef CONFIG_IDF_TARGET_ESP32H2
WiFi.begin();
@@ -469,7 +473,7 @@ private:
preference_started_before, preference_config_version, preference_device_id_lock, preference_device_id_opener, preference_nuki_id_lock, preference_nuki_id_opener,
preference_mqtt_broker, preference_mqtt_broker_port, preference_mqtt_user, preference_mqtt_password, preference_mqtt_log_enabled, preference_check_updates,
preference_webserver_enabled, preference_lock_enabled, preference_lock_pin_status, preference_mqtt_lock_path, preference_opener_enabled, preference_opener_pin_status,
preference_opener_continuous_mode, preference_lock_max_keypad_code_count, preference_opener_max_keypad_code_count, preference_update_time,
preference_opener_continuous_mode, preference_lock_max_keypad_code_count, preference_opener_max_keypad_code_count, preference_update_time, preference_time_server,
preference_lock_max_timecontrol_entry_count, preference_opener_max_timecontrol_entry_count, preference_enable_bootloop_reset, preference_mqtt_ca, preference_mqtt_crt,
preference_mqtt_key, preference_mqtt_hass_discovery, preference_mqtt_hass_cu_url, preference_buffer_size, preference_ip_dhcp_enabled, preference_ip_address,
preference_ip_subnet, preference_ip_gateway, preference_ip_dns_server, preference_network_hardware, preference_http_auth_type, preference_lock_gemini_pin,
@@ -478,7 +482,7 @@ private:
preference_query_interval_configuration, preference_query_interval_battery, preference_query_interval_keypad, preference_keypad_control_enabled,
preference_keypad_info_enabled, preference_keypad_publish_code, preference_timecontrol_control_enabled, preference_timecontrol_info_enabled, preference_conf_info_enabled,
preference_register_as_app, preference_register_opener_as_app, preference_command_nr_of_retries, preference_command_retry_delay, preference_cred_user,
preference_cred_password, preference_disable_non_json, preference_publish_authdata, preference_publish_debug_info, preference_mqtt_ssl_enabled,
preference_cred_password, preference_disable_non_json, preference_publish_authdata, preference_publish_debug_info, preference_mqtt_ssl_enabled, preference_enable_debug_mode,
preference_official_hybrid_enabled, preference_query_interval_hybrid_lockstate, preference_official_hybrid_actions, preference_official_hybrid_retry,
preference_task_size_network, preference_task_size_nuki, preference_authlog_max_entries, preference_keypad_max_entries, preference_timecontrol_max_entries,
preference_update_from_mqtt, preference_show_secrets, preference_ble_tx_power, preference_webserial_enabled, preference_find_best_rssi, preference_lock_gemini_enabled,
@@ -507,7 +511,7 @@ private:
preference_ntw_reconfigure, preference_keypad_check_code_enabled, preference_disable_network_not_connected, preference_find_best_rssi, preference_http_auth_type,
preference_debug_connect, preference_debug_communication, preference_debug_readable_data, preference_debug_hex_data, preference_debug_command, preference_connect_mode,
preference_lock_force_id, preference_lock_force_doorsensor, preference_lock_force_keypad, preference_opener_force_id, preference_opener_force_keypad, preference_mqtt_ssl_enabled,
preference_hybrid_reboot_on_disconnect, preference_lock_gemini_enabled
preference_hybrid_reboot_on_disconnect, preference_lock_gemini_enabled, preference_enable_debug_mode
};
std::vector<char*> _bytePrefs =
{

View File

@@ -233,12 +233,12 @@ void WebCfgServer::initialize()
}
else if (value == "debugon")
{
_preferences->putBool(preference_publish_debug_info, true);
_preferences->putBool(preference_enable_debug_mode, true);
return buildConfirmHtml(request, resp, "Debug On", 3, true);
}
else if (value == "debugoff")
{
_preferences->putBool(preference_publish_debug_info, false);
_preferences->putBool(preference_enable_debug_mode, false);
return buildConfirmHtml(request, resp, "Debug Off", 3, true);
}
else if (value == "export")
@@ -1882,6 +1882,16 @@ bool WebCfgServer::processArgs(PsychicRequest *request, PsychicResponse* resp, S
configChanged = true;
}
}
else if(key == "TIMESRV")
{
if(_preferences->getString(preference_time_server, "pool.ntp.org") != value)
{
_preferences->putString(preference_time_server, value);
Log->print(("Setting changed: "));
Log->println(key);
configChanged = true;
}
}
else if(key == "NWHW")
{
if(_preferences->getInt(preference_network_hardware, 0) != value.toInt())
@@ -2547,6 +2557,16 @@ bool WebCfgServer::processArgs(PsychicRequest *request, PsychicResponse* resp, S
configChanged = true;
}
}
else if(key == "DBGHEAP")
{
if(_preferences->getBool(preference_publish_debug_info, false) != (value == "1"))
{
_preferences->putBool(preference_publish_debug_info, (value == "1"));
Log->print(("Setting changed: "));
Log->println(key);
configChanged = true;
}
}
else if(key == "DBGREAD")
{
if(_preferences->getBool(preference_debug_readable_data, false) != (value == "1"))
@@ -3961,7 +3981,7 @@ esp_err_t WebCfgServer::buildHtml(PsychicRequest *request, PsychicResponse* resp
{
buildNavigationMenuEntry(&response, "Custom Ethernet Configuration", "/get?page=custntw");
}
if (_preferences->getBool(preference_publish_debug_info, false))
if (_preferences->getBool(preference_enable_debug_mode, false))
{
buildNavigationMenuEntry(&response, "Advanced Configuration", "/get?page=advanced");
}
@@ -4431,6 +4451,7 @@ esp_err_t WebCfgServer::buildAdvancedConfigHtml(PsychicRequest *request, Psychic
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), "");
printCheckBox(&response, "DBGHEAP", "Pubish free heap over MQTT", _preferences->getBool(preference_publish_debug_info, false), "");
response.print("</table>");
response.print("<br><input type=\"submit\" name=\"submit\" value=\"Save\">");
@@ -4781,6 +4802,8 @@ esp_err_t WebCfgServer::buildNukiConfigHtml(PsychicRequest *request, PsychicResp
printInputField(&response, "RSBC", "Restart if bluetooth beacons not received (seconds; -1 to disable)", _preferences->getInt(preference_restart_ble_beacon_lost), 10, "");
printInputField(&response, "TXPWR", "BLE transmit power in dB (minimum -12, maximum 9)", _preferences->getInt(preference_ble_tx_power, 9), 10, "");
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, "");
response.print("</table>");
response.print("<br><input type=\"submit\" name=\"submit\" value=\"Save\">");
response.print("</form>");
@@ -4967,7 +4990,9 @@ esp_err_t WebCfgServer::buildInfoHtml(PsychicRequest *request, PsychicResponse*
#else
response.print("Disabled");
#endif
response.print("\nPublish debug information enabled: ");
response.print("\nAdvanced menu enabled: ");
response.print(_preferences->getBool(preference_enable_debug_mode, false) ? "Yes" : "No");
response.print("\nPublish free heap over MQTT: ");
response.print(_preferences->getBool(preference_publish_debug_info, false) ? "Yes" : "No");
response.print("\nNuki connect debug logging enabled: ");
response.print(_preferences->getBool(preference_debug_connect, false) ? "Yes" : "No");

View File

@@ -29,8 +29,7 @@
#include "RestartReason.h"
#include "EspMillis.h"
#include "NimBLEDevice.h"
#include <time.h>
#include "esp_sntp.h"
#include "esp_netif_sntp.h"
/*
#ifdef DEBUG_NUKIHUB
@@ -827,9 +826,22 @@ void setup()
if(preferences->getBool(preference_update_time, false))
{
sntp_set_sync_interval(12 * 60 * 60 * 1000UL);
sntp_set_time_sync_notification_cb(cbSyncTime);
configTime(0, 0, "pool.ntp.org");
esp_sntp_config_t config = ESP_NETIF_SNTP_DEFAULT_CONFIG(preferences->getString(preference_time_server, "pool.ntp.org").c_str());
config.start = false;
config.server_from_dhcp = true;
config.renew_servers_after_new_IP = true;
config.index_of_first_server = 1;
if (network->networkDeviceType() == NetworkDeviceType::WiFi)
{
config.ip_event_to_renew = IP_EVENT_STA_GOT_IP;
}
else
{
config.ip_event_to_renew = IP_EVENT_ETH_GOT_IP;
}
config.sync_cb = cbSyncTime;
esp_netif_sntp_init(&config);
}
#endif