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"]
lat = sensor.get("lat", BASE_LAT)
lon = sensor.get("lon", BASE_LON)
points = [] def _write_async():
for field, value in values.items(): try:
if isinstance(value, (int, float)): stype = sensor["type"]
p = influxdb_client.Point(stype)\ lat = sensor.get("lat", BASE_LAT)
.tag("sensor_id", sid)\ lon = sensor.get("lon", BASE_LON)
.tag("location", sensor.get("name", sid))\
.field(field, float(value))\
.field("lat", float(lat))\
.field("lon", float(lon))
points.append(p)
if points: points = []
_influx_write_api.write(bucket=INFLUX_BUCKET, record=points) for field, value in values.items():
print(f" 📈 InfluxDB: {len(points)} points written") if isinstance(value, (int, float)):
return True p = influxdb_client.Point(stype)\
except Exception as e: .tag("sensor_id", sid)\
print(f" ⚠️ InfluxDB → {e}") .tag("location", sensor.get("name", sid))\
return False .field(field, float(value))\
.field("lat", float(lat))\
.field("lon", float(lon))
points.append(p)
if points:
_influx_write_api.write(bucket=INFLUX_BUCKET, record=points)
print(f" 📈 InfluxDB: {len(points)} points written")
except Exception as e:
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("╔══════════════════════════════════════════════════╗")