feat(backend): capture voltage, current and sample context in meter samples
The charger sends Voltage/Current.Import in every MeterValues frame but we only stored energy/power/SoC. samples now also record voltage_v, current_a and the OCPP context (Sample.Periodic vs Transaction.Begin/End snapshots, which are legitimately all-zero). Existing dbs migrate via ALTER TABLE on open.
This commit is contained in:
+7
-3
@@ -192,10 +192,11 @@ class ChargePoint(OcppChargePoint):
|
||||
tx = kwargs.get("transaction_id")
|
||||
if tx is not None:
|
||||
for entry in meter_value or []:
|
||||
reading = {}
|
||||
reading, context = {}, None
|
||||
for sv in entry.get("sampled_value") or []:
|
||||
# measurand defaults to the energy register when omitted
|
||||
measurand = sv.get("measurand", "Energy.Active.Import.Register")
|
||||
context = sv.get("context", context) # Sample.Periodic / Transaction.Begin / .End
|
||||
try:
|
||||
value = float(sv.get("value"))
|
||||
except (TypeError, ValueError):
|
||||
@@ -207,10 +208,13 @@ class ChargePoint(OcppChargePoint):
|
||||
reading["power_w"] = value * 1000 if sv.get("unit") == "kW" else value
|
||||
elif measurand == "SoC":
|
||||
reading["soc"] = value
|
||||
elif measurand == "Voltage":
|
||||
reading["voltage_v"] = value * 1000 if sv.get("unit") == "kV" else value
|
||||
elif measurand == "Current.Import":
|
||||
reading["current_a"] = value
|
||||
if reading:
|
||||
store.add_sample(tx, entry.get("timestamp", now()),
|
||||
reading.get("energy_wh"), reading.get("power_w"),
|
||||
reading.get("soc"))
|
||||
context=context, **reading)
|
||||
log.info("MeterValues: connector=%s values=%r", connector_id, meter_value)
|
||||
return call_result.MeterValues()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user