Fix: InfluxDB async write + Grafana Org rename + GeoServer workspace

This commit is contained in:
Eric FELIXINE
2026-05-04 18:37:29 -04:00
parent 42d1223b14
commit ee708fb4ab

View File

@@ -748,32 +748,37 @@ def publish_openremote(sid: str, sensor: dict, values: dict) -> bool:
return _or_put(asset_id, payload) return _or_put(asset_id, payload)
def publish_influx(sid: str, sensor: dict, values: dict) -> bool: def publish_influx(sid: str, sensor: dict, values: dict) -> bool:
"""Write sensor data to InfluxDB.""" """Write sensor data to InfluxDB (async, non-blocking)."""
if not _influx_write_api: if not _influx_write_api:
return False return False
try:
stype = sensor["type"] def _write_async():
lat = sensor.get("lat", BASE_LAT) try:
lon = sensor.get("lon", BASE_LON) stype = sensor["type"]
lat = sensor.get("lat", BASE_LAT)
points = [] lon = sensor.get("lon", BASE_LON)
for field, value in values.items():
if isinstance(value, (int, float)): points = []
p = influxdb_client.Point(stype)\ for field, value in values.items():
.tag("sensor_id", sid)\ if isinstance(value, (int, float)):
.tag("location", sensor.get("name", sid))\ p = influxdb_client.Point(stype)\
.field(field, float(value))\ .tag("sensor_id", sid)\
.field("lat", float(lat))\ .tag("location", sensor.get("name", sid))\
.field("lon", float(lon)) .field(field, float(value))\
points.append(p) .field("lat", float(lat))\
.field("lon", float(lon))
if points: points.append(p)
_influx_write_api.write(bucket=INFLUX_BUCKET, record=points)
print(f" 📈 InfluxDB: {len(points)} points written") if points:
return True _influx_write_api.write(bucket=INFLUX_BUCKET, record=points)
except Exception as e: print(f" 📈 InfluxDB: {len(points)} points written")
print(f" ⚠️ InfluxDB → {e}") except Exception as e:
return False print(f" ⚠️ InfluxDB → {e}")
# Exécution asynchrone (non-bloquante)
t = threading.Thread(target=_write_async, daemon=True)
t.start()
return True
def main(): def main():
print("╔══════════════════════════════════════════════════╗") print("╔══════════════════════════════════════════════════╗")