feat: OpenRemote smartcity realm support + DB assets copy + fixed auth
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
27
simulator.py
27
simulator.py
@@ -360,9 +360,10 @@ except:
|
|||||||
pass
|
pass
|
||||||
ORION_URL = f"http://{ORION_IP or ORION_HOST}:1026" if ORION_IP else "http://fiware-gis-quickstart-orion-1:1026"
|
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"
|
STELLIO_URL = "http://stellio-api-gateway:8080"
|
||||||
FROST_URL = "http://frost-server:8080/FROST-Server/v1.1"
|
# Configuration OpenRemote (URLs dynamiques)
|
||||||
OR_URL = "http://192.168.192.10:8080" # IP directe (évite DNS)
|
OR_URL = os.environ.get("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"
|
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
|
OR_TOKEN_TTL = 3600 # Refresh token every hour
|
||||||
def publish_stellio(sid: str, sensor: dict) -> bool:
|
def publish_stellio(sid: str, sensor: dict) -> bool:
|
||||||
"""Publie sur Stellio (gère le 409)."""
|
"""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)
|
# Utiliser le client openremote avec client secret (service account)
|
||||||
data = urllib.parse.urlencode({
|
data = urllib.parse.urlencode({
|
||||||
"grant_type": "client_credentials",
|
"grant_type": "client_credentials",
|
||||||
"client_id": OR_CLIENT_ID,
|
"client_id": os.environ.get('OR_CLIENT_ID', 'openremote'),
|
||||||
"client_secret": OR_CLIENT_SECRET,
|
"client_secret": os.environ.get('OR_CLIENT_SECRET', ''),
|
||||||
}).encode()
|
}).encode()
|
||||||
req = urllib.request.Request(OR_TOKEN_URL, data=data)
|
req = urllib.request.Request(OR_TOKEN_URL, data=data)
|
||||||
with urllib.request.urlopen(req, timeout=5) as resp:
|
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."""
|
"""Met à jour les attributs d'un asset OpenRemote via REST."""
|
||||||
# Mapping sid → asset ID (créés manuellement dans OR)
|
# Mapping sid → asset ID (créés manuellement dans OR)
|
||||||
ASSET_MAP = {
|
ASSET_MAP = {
|
||||||
"traffic_000": "5lWTn6j465OxdZNaPzvsyR",
|
"traffic_000": "7b5c5670d1b84865ba3ac7", # Traffic Fort-de-France Centre
|
||||||
"traffic_001": "7DKGIoNRmUYpnJTC28agTz",
|
"traffic_001": "557f6e993b994d3cb81017", # Traffic Fort-de-France North
|
||||||
"traffic_002": "7OQgueePcokDBPZr7LSyHH",
|
"traffic_002": "cb81dfd2d2dc4d25adc9c2", # Traffic Fort-de-France South
|
||||||
"airquality_000": "5nq957HaY24ZWfv5t1hHon",
|
"airquality_000": "a51c982a2d3e451898b978", # Air Quality Fort-de-France
|
||||||
"parking_000": "53SYT1qg09uXp8bvQeru9O",
|
"parking_000": "b8f0df19e0af47b386ebb9", # Parking Fort-de-France Centre
|
||||||
"noise_000": "22FCFLp8J27zvrsr1qA5Bs",
|
"noise_000": "9035103d1866454fb7e451", # Noise Fort-de-France Centre
|
||||||
"weather_000": "7WPIekDiCnrMPh3hhTWJxl",
|
"weather_000": "b9de80905ac640f488ab27", # Weather Lamentin Airport
|
||||||
"light_000": "4fzQwMIiYQh5ncRcxFixqF",
|
"light_000": "ee7823a41e594851ba202f", # Light Fort-de-France
|
||||||
}
|
}
|
||||||
asset_id = ASSET_MAP.get(sid)
|
asset_id = ASSET_MAP.get(sid)
|
||||||
if not asset_id:
|
if not asset_id:
|
||||||
|
|||||||
Reference in New Issue
Block a user