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:
2026-06-30 09:52:39 +03:00
co-authored by Claude Sonnet 4.6
parent df8426fce6
commit 7e8d91673f
11 changed files with 205 additions and 32 deletions
+89
View File
@@ -1,6 +1,9 @@
COMMANDS:
PV26A28BC01R01
{
"cmd":"system",
"contents":
@@ -37,3 +40,89 @@ COMMANDS:
"action":"get_full_settings"
}
}
{
"cmd":"system_info",
"contents":
{
"action":"get_full_settings"
}
}
{
"cmd": "clock_setup",
"contents": {
"action": "set_alerts",
"alertType": "OFF"
}
}
{
"cmd":"system_info",
"contents":
{
"action":"get_clock_time"
}
}
{
"cmd": "clock_setup",
"contents": {
"action": "set_rtc_time",
"timestamp": 1775329309,
"timezone_offset": 10800,
"dst_offset": 3600,
"timezone_name": "EEST"
}
}
{
"cmd": "playback",
"contents": {
"action": "stop",
"name": "one_bell_test",
"uid": "01DegzV9FA8tYbQpkIHR",
"url": "https://example.com/melody.bin",
"speed": 500,
"note_assignments": [4, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"segment_duration": 15000,
"pause_duration": 5000,
"total_duration": 60000,
"continuous_loop": true
}
}
{
"cmd": "playback",
"contents": {
"action": "play",
"name": "Great Friday Mournfull",
"uid": "mournfull_gf_1_4",
"url": "https://storage.googleapis.com/bs-vesper.firebasestorage.app/melodies/95fd22bb-56fb-4635-a1c3-51cad3a0ccb6/mournfull_gf_1_4.bsm",
"speed": 600,
"note_assignments": [1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"segment_duration": 15000,
"pause_duration": 5000,
"total_duration": 60000,
"continuous_loop": true
}
}
{
"cmd": "playback",
"contents": {
"action": "stop",
"uid": "one_bell_test",
"speed": 100,
"note_assignments": [1, 2, 3, 4, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
"segment_duration": 15000,
"pause_duration": 5000,
"total_duration": 60000,
"continuous_loop": true
}
}
+67 -4
View File
@@ -24,9 +24,9 @@
* - Bit 0-15: Which bells/notes to activate
* - Example: 0x0001 = Bell 0, 0x0003 = Bells 0+1, 0x8000 = Bell 15
*
* 📋 VERSION: 1.0
* 📅 DATE: 2025-12-28
* 👨‍💻 AUTHOR: Advanced Bell Systems
* 📋 VERSION: 1.1
* 📅 DATE: 2026-03-19
* 👨‍💻 AUTHOR: bonamin
* ═══════════════════════════════════════════════════════════════════════════════════
*/
@@ -330,6 +330,27 @@ const uint16_t PROGMEM doxology_1_4[] = {
};
// ═════════════════════════════════════════════════════════════════════════════════
// PROGMEM for builtin_* UIDs that have no identical current array
// ═════════════════════════════════════════════════════════════════════════════════
// builtin_catehetical: same as catechetical_1_5 but without trailing 0x0000
const uint16_t PROGMEM builtin_catehetical[] = {
0x0001, 0x0002, 0x0004, 0x0008, 0x0010
};
// builtin_mournfull_toll_alternative: unique doubled-beat pattern
const uint16_t PROGMEM builtin_mournfull_toll_alternative[] = {
0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0001,
0x0001, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0004,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0004, 0x0004,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0002, 0x0002, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0008, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0008, 0x0008, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000
};
// ═════════════════════════════════════════════════════════════════════════════════
// MELODY LIBRARY - Array of all built-in melodies
// ═════════════════════════════════════════════════════════════════════════════════
@@ -490,7 +511,35 @@ const MelodyInfo MELODY_LIBRARY[] = {
"doxology_1_4",
doxology_1_4,
sizeof(doxology_1_4) / sizeof(uint16_t)
}
},
// ── builtin_* UIDs — backward-compat aliases for devices using old PIDs ──────
{ "1 Bell Test", "builtin_1bell_test", one_bell_test, sizeof(one_bell_test) / sizeof(uint16_t) },
{ "Doxology Traditional", "builtin_doxology_traditional", doxology_1_4, sizeof(doxology_1_4) / sizeof(uint16_t) },
{ "Doxology Alternative", "builtin_doxology_alternative", doxology_alt_1_5, sizeof(doxology_alt_1_5) / sizeof(uint16_t) },
{ "Doxology Festive", "builtin_doxology_festive", doxology_fst_1_6, sizeof(doxology_fst_1_6) / sizeof(uint16_t) },
{ "Vesper Traditional", "builtin_vesper_traditional", vesper_1_3, sizeof(vesper_1_3) / sizeof(uint16_t) },
{ "Vesper Alternative", "builtin_vesper_alternative", vesper_fst_1_4, sizeof(vesper_fst_1_4) / sizeof(uint16_t) },
{ "Catehetical", "builtin_catehetical", builtin_catehetical, sizeof(builtin_catehetical) / sizeof(uint16_t) },
{ "Orthros Traditional", "builtin_orthros_traditional", orthros_1_8, sizeof(orthros_1_8) / sizeof(uint16_t) },
{ "Orthros Alternative", "builtin_orthros_alternative", orthros_fst_1_3, sizeof(orthros_fst_1_3) / sizeof(uint16_t) },
{ "Mournfull Toll", "builtin_mournfull_toll", mournfull_1_4, sizeof(mournfull_1_4) / sizeof(uint16_t) },
{ "Mournfull Toll Alternative", "builtin_mournfull_toll_alternative", builtin_mournfull_toll_alternative, sizeof(builtin_mournfull_toll_alternative) / sizeof(uint16_t) },
{ "Mournfull Toll Meg Par", "builtin_mournfull_toll_meg_par", mournfull_gf_1_4, sizeof(mournfull_gf_1_4) / sizeof(uint16_t) },
{ "Sematron", "builtin_sematron", semantron_1_4, sizeof(semantron_1_4) / sizeof(uint16_t) },
{ "Sematron Alternative", "builtin_sematron_alternative", talanto_1_4, sizeof(talanto_1_4) / sizeof(uint16_t) },
{ "Athonite 1 2 Voices", "builtin_athonite_1_2_voices", athonite_1_2, sizeof(athonite_1_2) / sizeof(uint16_t) },
{ "Athonite 3 Voices", "builtin_athonite_3_voices", athonite_3, sizeof(athonite_3) / sizeof(uint16_t) },
{ "Athonite 3 4 Voices", "builtin_athonite_3_4_voices", athonite_3_4, sizeof(athonite_3_4) / sizeof(uint16_t) },
{ "Athonite 4 8 Voices", "builtin_athonite_4_8_voices", athonite_4_8, sizeof(athonite_4_8) / sizeof(uint16_t) },
{ "Onebyone 2 3 Voices", "builtin_onebyone_2_3_voices", onebyone_2_3, sizeof(onebyone_2_3) / sizeof(uint16_t) },
{ "Onebyone 4 8 Voices", "builtin_onebyone_4_8_voices", onebyone_4_8, sizeof(onebyone_4_8) / sizeof(uint16_t) },
{ "Festive 1Voice", "builtin_festive_1voice", festive_1, sizeof(festive_1) / sizeof(uint16_t) },
{ "Festive 4Voices", "builtin_festive_4voices", festive_2_4, sizeof(festive_2_4) / sizeof(uint16_t) },
{ "Festive 5Voices", "builtin_festive_5voices", festive_5, sizeof(festive_5) / sizeof(uint16_t) },
{ "Festive 5Voice Alternative", "builtin_festive_5voice_alternative", festive_alt_5, sizeof(festive_alt_5) / sizeof(uint16_t) },
{ "Festive 6Voices", "builtin_festive_6voices", festive_6, sizeof(festive_6) / sizeof(uint16_t) },
{ "Festive 8Voices", "builtin_festive_8voices", festive_1_8, sizeof(festive_1_8) / sizeof(uint16_t) },
{ "Ormilia", "builtin_ormilia", ormilia_1_8, sizeof(ormilia_1_8) / sizeof(uint16_t) }
};
@@ -501,6 +550,20 @@ const uint16_t MELODY_COUNT = sizeof(MELODY_LIBRARY) / sizeof(MelodyInfo);
// HELPER FUNCTIONS
// ═════════════════════════════════════════════════════════════════════════════════
/**
* @brief Check if a PID corresponds to a built-in melody
* @param pid The melody PID to check
* @return true if the PID exists in the built-in melody library
*/
inline bool isBuiltInMelody(const String& pid) {
for (uint16_t i = 0; i < MELODY_COUNT; i++) {
if (pid == MELODY_LIBRARY[i].pid) {
return true;
}
}
return false;
}
/**
* @brief Find a built-in melody by PID
* @param pid The melody playback ID to find
@@ -23,10 +23,12 @@ CommandResult RelayHandler::execute(const CommandEnvelope& envelope) {
CommandResult RelayHandler::handleSetDurations(const CommandEnvelope& e) {
JsonVariant contents = const_cast<JsonDocument&>(e.contents).as<JsonVariant>();
if (contents["bells"].isNull()) {
// Accept v2 nested {"bells":{"b1":...}} or v1 flat {"b1":...}
JsonVariant bells = contents["bells"].is<JsonObject>() ? contents["bells"].as<JsonVariant>() : contents;
if (bells.isNull()) {
return CommandResult::err("relay.set_durations", "Missing or invalid 'bells' object");
}
_configManager.updateBellDurations(contents);
_configManager.updateBellDurations(bells);
if (!_configManager.saveBellDurations()) {
return CommandResult::err("relay.set_durations", "Durations updated but failed to save to SD");
}
@@ -36,10 +38,12 @@ CommandResult RelayHandler::handleSetDurations(const CommandEnvelope& e) {
CommandResult RelayHandler::handleSetOutputs(const CommandEnvelope& e) {
JsonVariant contents = const_cast<JsonDocument&>(e.contents).as<JsonVariant>();
if (contents["bells"].isNull()) {
// Accept v2 nested {"bells":{"b1":...}} or v1 flat {"b1":...}
JsonVariant bells = contents["bells"].is<JsonObject>() ? contents["bells"].as<JsonVariant>() : contents;
if (bells.isNull()) {
return CommandResult::err("relay.set_outputs", "Missing or invalid 'bells' object");
}
_configManager.updateBellOutputs(contents);
_configManager.updateBellOutputs(bells);
if (!_configManager.saveBellOutputs()) {
return CommandResult::err("relay.set_outputs", "Outputs updated but failed to save to SD");
}
@@ -59,7 +59,7 @@ void MQTTTransport::onMessage(const String& topic, const String& payload) {
envelope.transport = CommandEnvelope::Transport::MQTT;
envelope.clientId = 0;
envelope.command = doc["cmd"].as<String>();
envelope.version = doc["v"] | 2;
envelope.version = doc["v"] | 1;
if (doc.containsKey("contents")) {
envelope.contents.set(doc["contents"]);
@@ -78,7 +78,7 @@ void UARTTransport::onMessage(JsonDocument& doc) {
envelope.transport = CommandEnvelope::Transport::UART;
envelope.clientId = 0;
envelope.command = cmd;
envelope.version = doc["v"] | 2;
envelope.version = doc["v"] | 1;
if (doc.containsKey("contents")) {
envelope.contents.set(doc["contents"]);
@@ -69,7 +69,7 @@ void WebSocketTransport::onMessage(uint32_t clientId, const JsonDocument& doc) {
envelope.transport = CommandEnvelope::Transport::WEBSOCKET;
envelope.clientId = clientId;
envelope.command = cmd;
envelope.version = doc["v"] | 2;
envelope.version = doc["v"] | 1;
if (doc.containsKey("contents")) {
envelope.contents.set(doc["contents"]);
+3 -3
View File
@@ -29,9 +29,9 @@ bool FileManager::addMelody(JsonVariant doc) {
const char* url = doc["download_url"];
const char* melodyUid = doc["melodys_uid"];
// Check built-in library by PID — skip download if found
if (BuiltInMelodies::findMelodyByPID(melodyUid) != nullptr) {
LOG_INFO(TAG, "Melody '%s' is a built-in, skipping download", melodyUid);
// Check built-in library — skip download if found
if (BuiltInMelodies::isBuiltInMelody(melodyUid)) {
LOG_INFO(TAG, "Melody '%s' is a built-in melody, skipping download", melodyUid);
return true;
}
+3 -1
View File
@@ -278,7 +278,8 @@ void Player::setMelodyAttributes(JsonVariant doc) {
url = doc["url"].as<const char*>();
}
if (doc.containsKey("speed")) {
speed = doc["speed"].as<uint16_t>();
uint16_t s = doc["speed"].as<uint16_t>();
speed = (s == 0) ? 300 : s; // Default to 300ms if speed is 0
}
if (doc.containsKey("note_assignments")) {
JsonArray noteArray = doc["note_assignments"];
@@ -571,6 +572,7 @@ uint64_t Player::calculateProjectedRunTime() const {
// Calculate single loop duration: steps * speed (in milliseconds)
uint32_t singleLoopDuration = _melodySteps.size() * speed;
if (singleLoopDuration == 0) return 0;
if (infinite_play || total_duration == 0) {
return 0; // Infinite playback has no end time
+1 -1
View File
@@ -8,7 +8,7 @@ void Telemetry::begin() {
for (uint8_t i = 0; i < 16; i++) {
strikeCounters[i] = 0;
bellLoad[i] = 0;
bellMaxLoad[i] = 200; // Default max load
bellMaxLoad[i] = 500; // Default max load
}
coolingActive = false;
+27 -14
View File
@@ -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.");
}
}
+3 -1
View File
@@ -12,8 +12,10 @@
// v154 (legacy integer) - Last integer-versioned release
// v2.0.0 - First SemVer release
// v2.0.1 - Adds Safemode-OTA during boot.
// v2.0.2 - Fixes Legacy adapter not accepting non designated command versions
// v2.0.3 - Fixes various command and response builder problems
// ═══════════════════════════════════════════════════════════════════════
#define FW_VERSION "2.0.1"
#define FW_VERSION "2.0.3"
// ═══════════════════════════════════════════════════════════════════════
// SemVer — lightweight 3-part version struct