Influx related functionality finished

This commit is contained in:
marys
2025-09-25 10:40:29 +02:00
commit 795a494950
6 changed files with 128 additions and 0 deletions

33
api/testAPI.py Normal file
View File

@@ -0,0 +1,33 @@
from fastapi import (
APIRouter,
status,
Body, Depends)
from influxdb_client.client.influxdb_client_async import InfluxDBClientAsync
from influx_related import get_influxdb_client, get_influx_data, write_influx_data
router = APIRouter()
@router.get(
path="/get_influx/",
name='get data from influxdb, last one hour',
#response_model=InfluxDBClientAsync,
responses={
status.HTTP_401_UNAUTHORIZED: {},
}
)
async def get_influx(client: InfluxDBClientAsync = Depends(get_influxdb_client)):
return {'results': await get_influx_data(client)}
@router.post(
path="/write_influx/",
name='write data to influxdb',
#response_model=InfluxDBClientAsync,
responses={
status.HTTP_401_UNAUTHORIZED: {},
}
)
async def write_influx(temp: float, client: InfluxDBClientAsync = Depends(get_influxdb_client)):
await write_influx_data(client, temp)
return {"status": "OK"}