From 29af64e90e8737d45aa50e6588efe7c24a6ca2b9 Mon Sep 17 00:00:00 2001 From: Eric FELIXINE Date: Sun, 3 May 2026 02:49:25 -0400 Subject: [PATCH] feat: OpenRemote smartcity realm support + DB assets copy + fixed auth Co-Authored-By: Claude Opus 4.6 --- simulator.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/simulator.py b/simulator.py index d6225543..496b33c9 100644 --- a/simulator.py +++ b/simulator.py @@ -360,9 +360,10 @@ except: pass ORION_URL = f"http://{ORION_IP or ORION_HOST}:1026" if ORION_IP else "http://fiware-gis-quickstart-orion-1:1026" STELLIO_URL = "http://stellio-api-gateway:8080" -FROST_URL = "http://frost-server:8080/FROST-Server/v1.1" -OR_URL = "http://192.168.192.10:8080" # IP directe (évite DNS) -OR_TOKEN_URL = "https://openremote.digitribe.fr/auth/realms/master/protocol/openid-connect/token" +# Configuration OpenRemote (URLs dynamiques) +OR_URL = os.environ.get("OR_URL", "http://192.168.192.10:8080") # IP directe (évite DNS) +OR_REALM = os.environ.get("OR_REALM", "smartcity") # Default: smartcity +OR_TOKEN_URL = f"{OR_URL}/auth/realms/{OR_REALM}/protocol/openid-connect/token" OR_TOKEN_TTL = 3600 # Refresh token every hour def publish_stellio(sid: str, sensor: dict) -> bool: """Publie sur Stellio (gère le 409).""" @@ -552,8 +553,8 @@ def _get_or_token() -> str: # Utiliser le client openremote avec client secret (service account) data = urllib.parse.urlencode({ "grant_type": "client_credentials", - "client_id": OR_CLIENT_ID, - "client_secret": OR_CLIENT_SECRET, + "client_id": os.environ.get('OR_CLIENT_ID', 'openremote'), + "client_secret": os.environ.get('OR_CLIENT_SECRET', ''), }).encode() req = urllib.request.Request(OR_TOKEN_URL, data=data) with urllib.request.urlopen(req, timeout=5) as resp: @@ -593,14 +594,14 @@ def publish_openremote(sid: str, sensor: dict, values: dict) -> bool: """Met à jour les attributs d'un asset OpenRemote via REST.""" # Mapping sid → asset ID (créés manuellement dans OR) ASSET_MAP = { - "traffic_000": "5lWTn6j465OxdZNaPzvsyR", - "traffic_001": "7DKGIoNRmUYpnJTC28agTz", - "traffic_002": "7OQgueePcokDBPZr7LSyHH", - "airquality_000": "5nq957HaY24ZWfv5t1hHon", - "parking_000": "53SYT1qg09uXp8bvQeru9O", - "noise_000": "22FCFLp8J27zvrsr1qA5Bs", - "weather_000": "7WPIekDiCnrMPh3hhTWJxl", - "light_000": "4fzQwMIiYQh5ncRcxFixqF", + "traffic_000": "7b5c5670d1b84865ba3ac7", # Traffic Fort-de-France Centre + "traffic_001": "557f6e993b994d3cb81017", # Traffic Fort-de-France North + "traffic_002": "cb81dfd2d2dc4d25adc9c2", # Traffic Fort-de-France South + "airquality_000": "a51c982a2d3e451898b978", # Air Quality Fort-de-France + "parking_000": "b8f0df19e0af47b386ebb9", # Parking Fort-de-France Centre + "noise_000": "9035103d1866454fb7e451", # Noise Fort-de-France Centre + "weather_000": "b9de80905ac640f488ab27", # Weather Lamentin Airport + "light_000": "ee7823a41e594851ba202f", # Light Fort-de-France } asset_id = ASSET_MAP.get(sid) if not asset_id: