fix: stop group updates to silent drivers from starving zone play

Every acked unicast holds a pending slot for its whole retry run, so zone
and profile edits with drivers switched off filled the link and the next
zone play timed out (503). Group updates now go to a driver that has
failed three messages in a row at most once every 30 s; one that comes
back still gets its groups when it announces or resyncs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jimmyandClaude Opus 5.5 committed 2026-11-03 10:38:51 +13:00
1 parent 57182188ba
commit e7f238aebc
1 file changed
+39 -1
+39 -1
View File
@@ -846,6 +846,43 @@ static bool hex_mac(const char *s, uint8_t mac[6])
return parse_mac(s, mac);
}
/* Drivers that stopped acking (switched off, out of range). Every unicast to one holds a pending slot
for its whole retry run, so a few zone edits would fill the link and starve the next zone play.
Group updates go to such a driver at most once per DEAD_RETRY_US; a driver that comes back gets its
groups when it announces (boot) or resyncs (missed state). */
#define DEAD_FAILS 3
#define DEAD_RETRY_US (30LL * 1000000)
static struct {
uint8_t mac[6];
int64_t tried_us;
} s_dead[16];
static bool skip_unresponsive(const uint8_t mac[6])
{
int fails;
rel_peer_status(mac, &fails);
if (fails < DEAD_FAILS) {
return false;
}
int slot = 0;
for (int i = 0; i < 16; i++) {
if (!memcmp(s_dead[i].mac, mac, 6)) {
slot = i;
break;
}
if (s_dead[i].tried_us < s_dead[slot].tried_us) {
slot = i; // oldest entry, if this driver has none
}
}
int64_t now = esp_timer_get_time();
if (!memcmp(s_dead[slot].mac, mac, 6) && now - s_dead[slot].tried_us < DEAD_RETRY_US) {
return true;
}
memcpy(s_dead[slot].mac, mac, 6);
s_dead[slot].tried_us = now;
return false;
}
// Re-send group membership to every registered ESP-NOW driver (zones or devices changed)
void engine_groups_changed(void)
{
@@ -857,7 +894,8 @@ void engine_groups_changed(void)
const cJSON *tr = cJSON_GetObjectItem(d, "transport");
uint8_t mac[6];
const char *hex = cJSON_IsString(addr) ? addr->valuestring : d->string;
if (cJSON_IsString(name) && cJSON_IsString(tr) && !strcmp(tr->valuestring, "espnow") && hex_mac(hex, mac)) {
if (cJSON_IsString(name) && cJSON_IsString(tr) && !strcmp(tr->valuestring, "espnow") && hex_mac(hex, mac) &&
!skip_unresponsive(mac)) {
send_groups(mac, name->valuestring, true);
}
}