From 63408f3a7d607e850875f223b63f1827f90b473d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 1 Mar 2023 10:58:02 +0100 Subject: [PATCH] Add NTP time request from gateway (#17984) --- CHANGELOG.md | 1 + RELEASENOTES.md | 2 ++ tasmota/tasmota_support/support_wifi.ino | 29 ++++++++++++------------ 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e294dba68..9e0eeaeeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. - Matter subscriptions (#18017, #18018) - Matter multi-fabric (#18019) - Support for multiple MCP23017 as switch/button/relay +- NTP time request from gateway (#17984) ### Breaking Changed diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 7313af172..d25d6ba87 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -112,6 +112,8 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm ## Changelog v12.4.0.1 ### Added +- Support for multiple MCP23017 as switch/button/relay +- NTP time request from gateway [#17984](https://github.com/arendst/Tasmota/issues/17984) ### Breaking Changed diff --git a/tasmota/tasmota_support/support_wifi.ino b/tasmota/tasmota_support/support_wifi.ino index fe5b8fb0e..084d55bb5 100644 --- a/tasmota/tasmota_support/support_wifi.ino +++ b/tasmota/tasmota_support/support_wifi.ino @@ -461,35 +461,35 @@ void WifiSetState(uint8_t state) /*****************************************************************************************************\ * IP detection revised for full IPv4 / IPv6 support - * + * * In general, each interface (Wifi/Eth) can have 1x IPv4 and * 2x IPv6 (Global routable address and Link-Local starting witn fe80:...) - * + * * We always use an IPv4 address if one is assigned, and revert to * IPv6 only on networks that are v6 only. * Ethernet calls can be safely used even if the USE_ETHERNET is not enabled - * + * * New APIs: * - general form is: * `bool XXXGetIPYYY(IPAddress*)` returns `true` if the address exists and copies the address * if the pointer is non-null. * `bool XXXHasIPYYY()` same as above but only returns `true` or `false` * `String XXXGetIPYYYStr()` returns the IP as a `String` or empty `String` if none - * + * * `XXX` can be `Wifi` or `Eth` * `YYY` can be `` for any address, `v6` for IPv6 global address or `v6LinkLocal` for Link-local - * + * * - Legacy `Wifi.localIP()` and `ETH.localIP()` always return IPv4 and nothing on IPv6 only networks * * - v4/v6: * `WifiGetIP`, `WifiGetIPStr`, `WifiHasIP`: get preferred v4/v6 address for Wifi * `EthernetGetIP`, `EthernetGetIPStr`, `EthernetHasIP`: get preferred v4/v6 for Ethernet - * + * * - Main IP to be used dual stack v4/v6 * `hasIP`, `IPGetListeningAddress`, `IPGetListeningAddressStr`: any IP to listen to for Web Server * IPv4 is always preferred, and Eth is preferred over Wifi. * `IPForUrl`: converts v4/v6 to use in URL, enclosing v6 in [] - * + * * - v6 only: * `WifiGetIPv6`, `WifiGetIPv6Str`, `WifiHasIPv6` * `WifiGetIPv6LinkLocal`, `WifiGetIPv6LinkLocalStr` @@ -499,7 +499,7 @@ void WifiSetState(uint8_t state) * - v4 only: * `WifiGetIPv4`, `WifiGetIPv4Str`, `WifiHasIPv4` * `EthernetGetIPv4`, `EthernetGetIPv4Str`, `EthernetHasIPv4` - * + * * - DNS reporting actual values used (not the Settings): * `DNSGetIP(n)`, `DNSGetIPStr(n)` with n=`0`/`1` (same dns for Wifi and Eth) \*****************************************************************************************************/ @@ -648,7 +648,7 @@ String DNSGetIPStr(uint32_t idx) return DNSGetIP(&ip, idx) ? ip.toString() : String(F("0.0.0.0")); } -// +// #include "lwip/dns.h" void WifiDumpAddressesIPv6(void) { @@ -1254,13 +1254,14 @@ uint64_t WifiGetNtp(void) { IPAddress time_server_ip; - char fallback_ntp_server[16]; - snprintf_P(fallback_ntp_server, sizeof(fallback_ntp_server), PSTR("%d.pool.ntp.org"), random(0,3)); + char fallback_ntp_server[2][32]; + ext_snprintf_P(fallback_ntp_server[0], sizeof(fallback_ntp_server[0]), PSTR("%_I"), Settings->ipv4_address[1]); // #17984 + ext_snprintf_P(fallback_ntp_server[1], sizeof(fallback_ntp_server[1]), PSTR("%d.pool.ntp.org"), random(0,3)); char* ntp_server; - for (uint32_t i = 0; i <= MAX_NTP_SERVERS; i++) { - if (ntp_server_id > MAX_NTP_SERVERS) { ntp_server_id = 0; } - ntp_server = (ntp_server_id < MAX_NTP_SERVERS) ? SettingsText(SET_NTPSERVER1 + ntp_server_id) : fallback_ntp_server; + for (uint32_t i = 0; i < MAX_NTP_SERVERS +2; i++) { + if (ntp_server_id >= MAX_NTP_SERVERS +2) { ntp_server_id = 0; } + ntp_server = (ntp_server_id < MAX_NTP_SERVERS) ? SettingsText(SET_NTPSERVER1 + ntp_server_id) : fallback_ntp_server[ntp_server_id - MAX_NTP_SERVERS]; if (strlen(ntp_server)) { break; }