MQTT: laufende Nummer (total) ins Crossing-Event aufnehmen
Jedes crossing-Event enthaelt jetzt "total" = Gesamtzaehler-Stand zum Zeitpunkt der Ueberquerung (= laufende Nummer des Fahrzeugs). README-Payload-Beispiel ergaenzt. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -214,7 +214,7 @@ Datenbank wie **NocoDB** ablegen.
|
||||
(retained): Beim Verbinden sendet die App `online` (Birth-Message), bei einem
|
||||
Verbindungsabbruch publiziert der Broker automatisch `offline` (Last Will /
|
||||
LWT). So lässt sich jederzeit erkennen, ob der Counter läuft.
|
||||
- Das Payload ist JSON, z. B.:
|
||||
- Das Payload ist JSON (`total` = laufende Nummer dieses Fahrzeugs = Gesamtzähler-Stand), z. B.:
|
||||
```json
|
||||
{
|
||||
"event": "crossing",
|
||||
@@ -222,6 +222,7 @@ Datenbank wie **NocoDB** ablegen.
|
||||
"source": "webcam",
|
||||
"type": "car",
|
||||
"track_id": 42,
|
||||
"total": 183,
|
||||
"ts": "2026-06-01T12:34:56+02:00"
|
||||
}
|
||||
```
|
||||
|
||||
8
app.py
8
app.py
@@ -142,8 +142,9 @@ else:
|
||||
print(f"[mqtt] init failed: {exc}", flush=True)
|
||||
|
||||
|
||||
def publish_crossing(vehicle_type, track_id, source):
|
||||
"""Crossing-Event auf {MQTT_TOPIC}/crossing (QoS 1, nicht retained)."""
|
||||
def publish_crossing(vehicle_type, track_id, source, total):
|
||||
"""Crossing-Event auf {MQTT_TOPIC}/crossing (QoS 1, nicht retained).
|
||||
total = laufende Nummer dieses Fahrzeugs (= Gesamtzaehler nach dem Zaehlen)."""
|
||||
if _mqtt is None:
|
||||
return
|
||||
payload = {
|
||||
@@ -152,6 +153,7 @@ def publish_crossing(vehicle_type, track_id, source):
|
||||
"source": source,
|
||||
"type": vehicle_type,
|
||||
"track_id": int(track_id),
|
||||
"total": int(total),
|
||||
"ts": datetime.now(LOCAL_TZ).isoformat(),
|
||||
}
|
||||
try:
|
||||
@@ -424,7 +426,7 @@ def process_frame(frame, det_model, det_names, line_start, line_end, state, sour
|
||||
recent_counts.append((center_x, center_y, frame_idx))
|
||||
state["count"] += 1
|
||||
types[label_name] += 1
|
||||
publish_crossing(label_name, track_id, source)
|
||||
publish_crossing(label_name, track_id, source, state["count"])
|
||||
cv2.circle(frame, (center_x, center_y), 25, (0, 255, 0), 5)
|
||||
dbg_counted += 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user