docs: record the verified register map and inverter IDs
P06D is a latched 21450 (not power), P052/P05A static, P063 frozen; power is computed V*I. Lists what's sent, what isn't, the unmapped diagnostics, the INV1-INV5 IP assignments, and that timestamps must be real UTC. The simulator now sends the same payload shape. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+26
-35
@@ -2,9 +2,11 @@
|
||||
|
||||
python fake_poller.py --url http://localhost:8090 --key change-me --backfill-days 30
|
||||
|
||||
--backfill-days first loads that many days of history (one reading per
|
||||
5 minutes), then it posts live readings every --interval seconds. Inverter
|
||||
INV3 runs with a dead MPPT2 string so the warnings show up.
|
||||
Sends what the real poller sends today (AC side, temperature, status code,
|
||||
unmapped diagnostics; no DC or energy counters). --backfill-days first loads
|
||||
that many days of history (one reading per 5 minutes), then it posts live
|
||||
readings every --interval seconds. INV4 runs at half output (as if a string
|
||||
fuse had blown) so the warnings show up.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
@@ -15,7 +17,7 @@ from datetime import datetime, timedelta, timezone
|
||||
|
||||
from backend_client import BackendClient
|
||||
|
||||
INVERTERS = ["INV1", "INV2", "INV3", "INV4", "INV5"]
|
||||
INVERTERS = ["INV1", "INV2", "INV4"]
|
||||
PEAK_W = 18_000
|
||||
|
||||
|
||||
@@ -26,40 +28,32 @@ def sun_factor(t: datetime) -> float:
|
||||
return max(0.0, math.sin(math.pi * x)) if 0 < x < 1 else 0.0
|
||||
|
||||
|
||||
def reading(inv: str, t: datetime, state: dict) -> dict | None:
|
||||
def reading(inv: str, t: datetime) -> dict | None:
|
||||
f = sun_factor(t) * random.uniform(0.93, 1.0)
|
||||
if f <= 0.01:
|
||||
return None # inverter asleep at night, doesn't answer
|
||||
dead_mppt2 = inv == "INV3"
|
||||
p_dc1 = PEAK_W / 2 * f
|
||||
p_dc2 = 0 if dead_mppt2 else PEAK_W / 2 * f
|
||||
v1, v2 = 560 + 60 * f, 560 + 60 * f
|
||||
ac = int((p_dc1 + p_dc2) * 0.97)
|
||||
day = t.date()
|
||||
if state.get((inv, "day")) != day:
|
||||
state[(inv, "day")] = day
|
||||
state[(inv, "daily")] = 0
|
||||
state[(inv, "daily")] += ac * state["step"] / 3600
|
||||
state[(inv, "total")] = state.get((inv, "total"), 40_000_000) + ac * state["step"] / 3600
|
||||
i_ac = ac / 3 / 230
|
||||
feeding = f > 0.03
|
||||
w = int(PEAK_W * f * (0.5 if inv == "INV4" else 1.0)) if feeding else 0
|
||||
volts = [round(random.uniform(229, 236), 2) for _ in range(3)]
|
||||
amps = [round(w / 3 / v, 2) for v in volts]
|
||||
return {
|
||||
"inverter_id": inv,
|
||||
"timestamp": t.isoformat(timespec="seconds"),
|
||||
"ac_voltage_l1_v": round(random.uniform(228, 236), 1),
|
||||
"ac_voltage_l2_v": round(random.uniform(228, 236), 1),
|
||||
"ac_voltage_l3_v": round(random.uniform(228, 236), 1),
|
||||
"dc_voltage_mppt1_v": round(v1, 1),
|
||||
"dc_voltage_mppt2_v": round(v2 if not dead_mppt2 else 30.0, 1),
|
||||
"dc_current_mppt1_a": round(p_dc1 / v1, 1),
|
||||
"dc_current_mppt2_a": round(p_dc2 / v2, 1),
|
||||
"ac_current_l1_a": round(i_ac, 2),
|
||||
"ac_current_l2_a": round(i_ac, 2),
|
||||
"ac_current_l3_a": round(i_ac, 2),
|
||||
"ac_power_total_w": ac,
|
||||
"ac_voltage_l1_v": volts[0],
|
||||
"ac_voltage_l2_v": volts[1],
|
||||
"ac_voltage_l3_v": volts[2],
|
||||
"ac_current_l1_a": amps[0],
|
||||
"ac_current_l2_a": amps[1],
|
||||
"ac_current_l3_a": amps[2],
|
||||
"ac_power_total_w": w,
|
||||
"grid_frequency_hz": round(random.uniform(49.95, 50.05), 2),
|
||||
"temperature_c": int(30 + 25 * f),
|
||||
"daily_energy_wh": int(state[(inv, "daily")] // 10 * 10),
|
||||
"total_energy_wh": int(state[(inv, "total")]),
|
||||
"status_code": (7 if inv == "INV1" else 8) if feeding else 3,
|
||||
"status_text": "feeding" if feeding else "standby/not feeding",
|
||||
"p06d_raw_latched": 21450,
|
||||
"p052_static_v": 312.5,
|
||||
"p05a_static_a": 45.0,
|
||||
"p063_ind0_raw": 1872,
|
||||
}
|
||||
|
||||
|
||||
@@ -72,13 +66,11 @@ def main() -> None:
|
||||
args = ap.parse_args()
|
||||
client = BackendClient(args.url, args.key, spool_path="fake_unsent.jsonl")
|
||||
|
||||
state: dict = {}
|
||||
if args.backfill_days:
|
||||
state["step"] = 300
|
||||
t = datetime.now(timezone.utc) - timedelta(days=args.backfill_days)
|
||||
batch: list[dict] = []
|
||||
while t < datetime.now(timezone.utc):
|
||||
batch += [r for inv in INVERTERS if (r := reading(inv, t, state))]
|
||||
batch += [r for inv in INVERTERS if (r := reading(inv, t))]
|
||||
if len(batch) >= 1000:
|
||||
client.send(batch)
|
||||
batch = []
|
||||
@@ -86,10 +78,9 @@ def main() -> None:
|
||||
client.send(batch)
|
||||
print(f"Backfilled {args.backfill_days} days")
|
||||
|
||||
state["step"] = args.interval
|
||||
while True:
|
||||
now = datetime.now(timezone.utc)
|
||||
batch = [r for inv in INVERTERS if (r := reading(inv, now, state))]
|
||||
batch = [r for inv in INVERTERS if (r := reading(inv, now))]
|
||||
ok = client.send(batch)
|
||||
print(f"{now:%H:%M:%S} sent {len(batch)} readings, ok={ok}")
|
||||
time.sleep(args.interval)
|
||||
|
||||
Reference in New Issue
Block a user