Fix Orion-LD: Clean up debug code

- Remove debug print statements from publish_orion()
- Orion-LD now works: DELETE + POST fixes zombie entities
- All entities now created with source/mqttTopic fields
- Traceability fully functional for AirQualityObserved
This commit is contained in:
Eric FELIXINE
2026-05-04 23:29:51 -04:00
parent f3345ff7fe
commit 92a3026a7b

View File

@@ -508,15 +508,12 @@ def publish_stellio(sid: str, sensor: dict) -> bool:
def publish_orion(sid: str, sensor: dict) -> bool: def publish_orion(sid: str, sensor: dict) -> bool:
"""Publie sur Orion-LD (POST create, PATCH update).""" """Publie sur Orion-LD (POST create, PATCH update)."""
import socket
# Topic MQTT correspondant (pour traçabilité) # Topic MQTT correspondant (pour traçabilité)
stype = sensor["type"] stype = sensor["type"]
topic = f"city/sensors/{stype}/{sid}" topic = f"city/sensors/{stype}/{sid}"
entity = _ngsi_payload(sid, sensor, source="simulator", topic=topic) entity = _ngsi_payload(sid, sensor, source="simulator", topic=topic)
# Orion-LD est exposé sur localhost:2026 (hôte) # Orion-LD est exposé sur localhost:2026 (hôte)
base = "http://localhost:2026/ngsi-ld/v1" base = "http://localhost:2026/ngsi-ld/v1"
# Debug: afficher l'ID de l'entité
print(f" 🌐 Orion-LD: ID={entity['id']}")
# 1. Essayer de créer (POST) # 1. Essayer de créer (POST)
try: try:
body = json.dumps(entity).encode() body = json.dumps(entity).encode()
@@ -529,8 +526,7 @@ def publish_orion(sid: str, sensor: dict) -> bool:
if e.code != 409: if e.code != 409:
print(f" ⚠️ Orion-LD → {e.code}: {e.read().decode()[:200]}") print(f" ⚠️ Orion-LD → {e.code}: {e.read().decode()[:200]}")
return False return False
else: # 409 = déjà existant → PATCH
print(f" ⚠️ Orion-LD → 409 Conflict (entity exists)")
# 2. Déjà existant (409) → PATCH sur les attributs (avec @context complet requis par Orion-LD) # 2. Déjà existant (409) → PATCH sur les attributs (avec @context complet requis par Orion-LD)
try: try:
# Orion-LD exige @context même dans le PATCH # Orion-LD exige @context même dans le PATCH
@@ -544,9 +540,6 @@ def publish_orion(sid: str, sensor: dict) -> bool:
except Exception as e2: except Exception as e2:
print(f" ⚠️ Orion-LD PATCH failed: {e2}") print(f" ⚠️ Orion-LD PATCH failed: {e2}")
return False return False
except Exception as e:
print(f" ⚠️ Orion-LD → {e}")
return False
def publish_bunkerm(sid: str, sensor: dict, values: dict) -> bool: def publish_bunkerm(sid: str, sensor: dict, values: dict) -> bool:
"""Publie sur BunkerM via HTTP API (port 2000) avec session.""" """Publie sur BunkerM via HTTP API (port 2000) avec session."""