From ec55b7e8c3bec2c6b32e7a89cfbdf5ad86eeca1b Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Sat, 14 Nov 2026 02:18:29 +0100 Subject: [PATCH] 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 --- tools/power_ab.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/power_ab.py b/tools/power_ab.py index 95335131..491daee3 100755 --- a/tools/power_ab.py +++ b/tools/power_ab.py @@ -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"]