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. one voltage held for the whole run: ~2 mAh at 5 V, twice the UC96's own step.
""" """
global _cb_volts global _cb_volts
with urllib.request.urlopen(url, timeout=10) as r:
body = r.read().decode()
want = (f'device="{device}"', f'meter="{meter}"') want = (f'device="{device}"', f'meter="{meter}"')
out = {} # The box drops the meter for half a minute now and then (it killed a cell
for line in body.splitlines(): # 25 min in on 14. 11. 2026). A gap only thins the fitted series, so wait it
if line.startswith("cb_meter_") and all(w in line for w in want): # out; a feed that stays stale for minutes is a dead one.
out[line.split("{", 1)[0]] = float(line.rsplit(" ", 1)[1]) for attempt in range(25):
if "cb_meter_energy_wh" not in out or "cb_meter_voltage_volts" not in out: with urllib.request.urlopen(url, timeout=10) as r:
raise SystemExit(f"cbprom nema meter {meter} z budky {device}") body = r.read().decode()
age = time.time() - out.get("cb_meter_last_seen_timestamp_seconds", 0.0) out = {}
if age > 30: 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") raise SystemExit(f"posledni ramec pred {age:.0f} s -- serie je zamrzla, ne stabilni")
if _cb_volts is None: if _cb_volts is None:
_cb_volts = out["cb_meter_voltage_volts"] _cb_volts = out["cb_meter_voltage_volts"]