From 1ed03b5a57901fb1f047854a987c2ea970797fa1 Mon Sep 17 00:00:00 2001 From: Eric FELIXINE Date: Mon, 4 May 2026 23:12:56 -0400 Subject: [PATCH] Fix Orion-LD: Add source to @context + PATCH with full payload - ORION_CONTEXT now includes source definition (uri.fiware.org) - PATCH /entities/{id}/attrs now sends full entity (with @context) - Orion-LD requires @context even in PATCH requests - This fixes 400 Bad Request errors on update --- simulator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/simulator.py b/simulator.py index a1191f08..7151315f 100644 --- a/simulator.py +++ b/simulator.py @@ -168,6 +168,7 @@ for stype, locs in SENSOR_LOCATIONS.items(): # Orion-LD ne peut pas résoudre raw.githubusercontent.com — utiliser uri.etsi.org uniquement ORION_CONTEXT = [ "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld", + {"source": "https://uri.fiware.org/ngsi-ld/default-context/source"} ] # Mapping sensor type → Smart Data Model type NGSI-LD @@ -527,13 +528,12 @@ def publish_orion(sid: str, sensor: dict) -> bool: if e.code != 409: print(f" ⚠️ Orion-LD → {e.code}: {e.read().decode()[:200]}") return False - # 2. Déjà existant (409) → PATCH sur les attributs (sans id/type/@context) + # 2. Déjà existant (409) → PATCH sur les attributs (avec @context complet requis par Orion-LD) try: - # PATCH ne doit contenir que les attributs (pas id/type/@context) - attrs = {k: v for k, v in entity.items() if k not in ("id", "type", "@context")} + # Orion-LD exige @context même dans le PATCH eid = urllib.parse.quote(entity['id'], safe='') patch_url = f"{base}/entities/{eid}/attrs" - req2 = urllib.request.Request(patch_url, data=json.dumps(attrs).encode(), + req2 = urllib.request.Request(patch_url, data=body, headers={"Content-Type": "application/ld+json", "Accept": "application/ld+json"}, method="PATCH") with urllib.request.urlopen(req2, timeout=8) as resp2: print(f" 🌐 Orion-LD: ✅ (HTTP {resp2.status} updated)")