power_ab.py --budka: wait out a short gap in the box's meter feed instead of dropping the run

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
tthandClaude Opus 5.5 committed 2026-11-14 02:18:29 +01:00
1 parent f2dd7e8082
commit ec55b7e8c3
1 file changed
+19 -10
+19 -10
View File
@@ -59,17 +59,26 @@ def cbprom_sample(url, meter, device):
one voltage held for the whole run: ~2 mAh at 5 V, twice the UC96's own step.
"""
global _cb_volts
with urllib.request.urlopen(url, timeout=10) as r:
body = r.read().decode()
want = (f'device="{device}"', f'meter="{meter}"')
out = {}
for line in body.splitlines():
if line.startswith("cb_meter_") and all(w in line for w in want):
out[line.split("{", 1)[0]] = float(line.rsplit(" ", 1)[1])
if "cb_meter_energy_wh" not in out or "cb_meter_voltage_volts" not in out:
raise SystemExit(f"cbprom nema meter {meter} z budky {device}")
age = time.time() - out.get("cb_meter_last_seen_timestamp_seconds", 0.0)
if age > 30:
# The box drops the meter for half a minute now and then (it killed a cell
# 25 min in on 14. 11. 2026). A gap only thins the fitted series, so wait it
# out; a feed that stays stale for minutes is a dead one.
for attempt in range(25):
with urllib.request.urlopen(url, timeout=10) as r:
body = r.read().decode()
out = {}
for line in body.splitlines():
if line.startswith("cb_meter_") and all(w in line for w in want):
out[line.split("{", 1)[0]] = float(line.rsplit(" ", 1)[1])
if "cb_meter_energy_wh" not in out or "cb_meter_voltage_volts" not in out:
raise SystemExit(f"cbprom nema meter {meter} z budky {device}")
age = time.time() - out.get("cb_meter_last_seen_timestamp_seconds", 0.0)
if age <= 30:
break
if attempt == 0:
print(f" (budka: posledni ramec pred {age:.0f} s, cekam)", flush=True)
time.sleep(5)
else:
raise SystemExit(f"posledni ramec pred {age:.0f} s -- serie je zamrzla, ne stabilni")
if _cb_volts is None:
_cb_volts = out["cb_meter_voltage_volts"]