The backend provides a REST API for device control and data access. All endpoints require authentication except /health.
http://localhost:8000
All API endpoints (except /health and /api/login) require a Bearer token.
POST /api/login
Content-Type: application/json
{
"password": "your_password"
}Response:
{
"access_token": "eyJ0eXAiOiJKV1QiLCJh...",
"token_type": "bearer"
}Use the token in subsequent requests:
Authorization: Bearer eyJ0eXAiOiJKV1QiLCJh...GET /api/statusResponse:
{
"power": true,
"current_humidity": 65,
"target_humidity": 60,
"temperature": 23.5,
"fan_speed": "high",
"mode": "normal",
"tank_full": false,
"timer": 0,
"timestamp": "2024-12-03T10:30:00"
}POST /api/power
Content-Type: application/json
{
"value": true
}POST /api/humidity
Content-Type: application/json
{
"value": 55
}Value must be between 30 and 80.
POST /api/fan
Content-Type: application/json
{
"value": "high"
}Valid values: low, high
POST /api/timer
Content-Type: application/json
{
"value": 4
}Value is hours (0-24). 0 means timer off.
GET /api/history?hours=24Query parameters:
hours- Number of hours to retrieve (default: 24)from_date- ISO 8601 start date (optional)to_date- ISO 8601 end date (optional)
Response:
{
"count": 1440,
"readings": [
{
"timestamp": "2024-12-03T10:30:00",
"current_humidity": 65,
"target_humidity": 60,
"temperature": 23.5,
"power": true,
"fan_speed": "high"
}
]
}GET /api/events?limit=100&offset=0&event_type=allQuery parameters:
limit- Number of events to return (default: 100)offset- Pagination offset (default: 0)event_type- Filter by type:all,user,system,power,humidity,temperature(default: all)
Response:
{
"count": 100,
"total": 450,
"events": [
{
"id": 123,
"timestamp": "2024-12-03T10:30:00",
"event_type": "humidity_changed",
"description": "Target humidity changed from 60% to 55%",
"user_initiated": true,
"old_value": "60",
"new_value": "55"
}
]
}GET /api/statistics?period=todayQuery parameters:
period- Time period:today,week,month,all(default: today)
Response:
{
"period": "today",
"avg_humidity": 62.5,
"avg_temperature": 23.2,
"min_humidity": 58,
"max_humidity": 70,
"min_temperature": 22.1,
"max_temperature": 24.3,
"total_readings": 720,
"runtime_hours": 8.5,
"tank_full_count": 0
}GET /api/configResponse:
{
"polling_interval": 60
}POST /api/config/interval
Content-Type: application/json
{
"value": 30
}Value is in seconds. Minimum 10, recommended 60.
For real-time updates, connect to the WebSocket endpoint:
ws://localhost:8000/ws
The server will push device status updates automatically whenever the device state changes.
Message format:
{
"power": true,
"current_humidity": 65,
"target_humidity": 60,
"temperature": 23.5,
"fan_speed": "high",
"mode": "normal",
"tank_full": false,
"timer": 0,
"timestamp": "2024-12-03T10:30:00"
}GET /healthNo authentication required. Returns:
{
"status": "ok",
"timestamp": "2024-12-03T10:30:00",
"polling_active": true
}All endpoints return standard HTTP status codes:
200- Success400- Bad Request (invalid parameters)401- Unauthorized (missing or invalid token)500- Internal Server Error
Error response format:
{
"detail": "Error message here"
}The backend provides auto-generated interactive API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
These interfaces allow you to test API endpoints directly from your browser.