fix: builtin aliases, cmd version default, relay compat, NTP UTC, player guards
BuiltInMelodies (F-018):
- 24 builtin_* UID aliases added for backward compat with old device PIDs
- Two new PROGMEM arrays: builtin_catehetical, builtin_mournfull_toll_alternative
- isBuiltInMelody() helper for lightweight PID existence check
- FileManager download-skip now uses isBuiltInMelody() instead of findMelodyByPID()
Command envelope version default (F-020):
- MQTT, UART, WebSocket transports: missing "v" field defaults to 1 (was 2)
- Fixes legacy adapter rejecting commands from app and Node-RED
RelayHandler v1/v2 compat (F-021):
- set_durations and set_outputs accept both nested {"bells":{...}} (v2)
and flat {...} (v1) payload shapes
NTP UTC fix (F-019):
- configTime(0,0,ntpServer) fetches raw UTC; stored gmtOffset+dstOffset
applied manually to epoch before writing RTC
- Eliminates double-offset bug from SDK internal timezone handling
Player guards (F-022):
- speed==0 defaults to 300ms instead of producing silent/broken playback
- calculateProjectedRunTime() guards against singleLoopDuration==0
Telemetry (F-023):
- bellMaxLoad default raised 200→500 to eliminate false overload warnings
Version bump: 2.0.1 → 2.0.3
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -160,29 +160,42 @@ void Timekeeper::syncTimeWithNTP() {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_INFO(TAG, "⏰ Starting non-blocking NTP sync...");
|
||||
LOG_INFO(TAG, "⏰ Starting NTP sync (UTC-only, offsets applied manually)...");
|
||||
|
||||
// Get config from ConfigManager
|
||||
// Get stored offsets from config — these are the only source of truth
|
||||
auto& timeConfig = _configManager->getTimeConfig();
|
||||
long totalOffsetSec = timeConfig.gmtOffsetSec + timeConfig.daylightOffsetSec;
|
||||
|
||||
// Configure NTP with settings from config
|
||||
configTime(timeConfig.gmtOffsetSec, timeConfig.daylightOffsetSec, timeConfig.ntpServer.c_str());
|
||||
LOG_INFO(TAG, "⏰ Using stored offsets: GMT=%ld s, DST=%d s, total=%ld s",
|
||||
timeConfig.gmtOffsetSec, timeConfig.daylightOffsetSec, totalOffsetSec);
|
||||
|
||||
// 🔥 NON-BLOCKING: Try to get time with reasonable timeout for network response
|
||||
struct tm timeInfo;
|
||||
if (getLocalTime(&timeInfo, 5000)) { // 5 second timeout for NTP response
|
||||
// Success! Update RTC with synchronized time
|
||||
rtc.adjust(DateTime(timeInfo.tm_year + 1900, timeInfo.tm_mon + 1, timeInfo.tm_mday,
|
||||
timeInfo.tm_hour, timeInfo.tm_min, timeInfo.tm_sec));
|
||||
// Always fetch raw UTC from NTP (offsets=0 so the SDK returns UTC, not local time)
|
||||
configTime(0, 0, timeConfig.ntpServer.c_str());
|
||||
|
||||
LOG_INFO(TAG, "✅ NTP sync successful: %04d-%02d-%02d %02d:%02d:%02d",
|
||||
timeInfo.tm_year + 1900, timeInfo.tm_mon + 1, timeInfo.tm_mday,
|
||||
timeInfo.tm_hour, timeInfo.tm_min, timeInfo.tm_sec);
|
||||
struct tm utcTimeInfo;
|
||||
if (getLocalTime(&utcTimeInfo, 5000)) { // 5 second timeout for NTP response
|
||||
// utcTimeInfo is now true UTC — apply our stored offsets manually
|
||||
time_t utcEpoch = mktime(&utcTimeInfo);
|
||||
time_t localEpoch = utcEpoch + totalOffsetSec;
|
||||
|
||||
struct tm localTimeInfo;
|
||||
gmtime_r(&localEpoch, &localTimeInfo);
|
||||
|
||||
// Write local time into RTC
|
||||
rtc.adjust(DateTime(localTimeInfo.tm_year + 1900, localTimeInfo.tm_mon + 1, localTimeInfo.tm_mday,
|
||||
localTimeInfo.tm_hour, localTimeInfo.tm_min, localTimeInfo.tm_sec));
|
||||
|
||||
LOG_INFO(TAG, "✅ NTP sync successful: UTC %04d-%02d-%02d %02d:%02d:%02d → Local %04d-%02d-%02d %02d:%02d:%02d (offset %+ld s)",
|
||||
utcTimeInfo.tm_year + 1900, utcTimeInfo.tm_mon + 1, utcTimeInfo.tm_mday,
|
||||
utcTimeInfo.tm_hour, utcTimeInfo.tm_min, utcTimeInfo.tm_sec,
|
||||
localTimeInfo.tm_year + 1900, localTimeInfo.tm_mon + 1, localTimeInfo.tm_mday,
|
||||
localTimeInfo.tm_hour, localTimeInfo.tm_min, localTimeInfo.tm_sec,
|
||||
totalOffsetSec);
|
||||
|
||||
// Reload today's events since the time might have changed significantly
|
||||
loadTodaysEvents();
|
||||
} else {
|
||||
// No internet or NTP server unreachable - this is NORMAL for local networks
|
||||
// No internet or NTP server unreachable — this is NORMAL for local networks
|
||||
LOG_INFO(TAG, "⚠️ NTP sync skipped (no internet) - using RTC time. This is normal for local networks.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user