Base URL: http://127.0.0.1:5000/api
Get complete real-time dashboard data including campus load and optimization savings.
Response:
{
"status": "success",
"data": {
"campus_load": { ... },
"optimization_savings": { ... },
"last_updated": "2026-02-16T14:30:00"
}
}Get current total campus energy consumption.
Get current load for all buildings (sorted by consumption).
Get current load for a specific building.
Get hourly consumption data.
Query Parameters:
hours(optional, default: 24) - Number of hours to retrieve
Get daily consumption summary.
Query Parameters:
days(optional, default: 7) - Number of days to retrieve
Compare energy usage across all buildings.
Get total energy savings from optimization.
Query Parameters:
start_time(optional) - ISO format datetimeend_time(optional) - ISO format datetime
Response:
{
"status": "success",
"data": {
"total_optimizations": 15420,
"energy_saved_kwh": 2345.67,
"cost_saved_inr": 18765.36,
"co2_reduced_kg": 1923.45
}
}Get current optimization statistics.
Predict energy consumption for the next hour using ML model.
Response:
{
"status": "success",
"data": {
"predicted_load_kw": 1187.23,
"prediction_for": "2026-02-16T15:30:00",
"current_load_kw": 1234.56,
"confidence_interval": {
"lower": 1142.11,
"upper": 1232.35
},
"features_used": { ... }
}
}Manually trigger ML model training.
Request Body (optional):
{
"hours_back": 168
}Get ML model information and feature importance.
Get complete campus hierarchy (faculties → buildings → floors → rooms).
Get all faculties.
Get all buildings.
Get rooms with optional filtering.
Query Parameters:
type(optional) - Filter by room type: classroom, lab, staffbuilding_id(optional) - Filter by building ID
Get detailed information for a specific room including latest readings and timetable.
Get historical energy logs for a specific room.
Query Parameters:
hours(optional, default: 24) - Number of hours to retrieve
Get aggregated campus-wide historical data.
Query Parameters:
hours(optional, default: 24) - Number of hours to retrieve
Response:
{
"status": "success",
"data": [
{
"timestamp": "2026-02-16T14:30:00",
"total_load_kw": 1234.56,
"avg_temperature": 28.3,
"occupied_rooms": 450,
"optimized_rooms": 810
}
]
}Get overall system statistics including total logs, time ranges, and optimization metrics.
API health check endpoint.
Response:
{
"status": "healthy",
"timestamp": "2026-02-16T14:30:00",
"database": "connected",
"rooms": 1260,
"logs": 211680,
"simulation": "running",
"ml_model": "loaded"
}All endpoints return errors in this format:
{
"status": "error",
"message": "Error description here"
}Common HTTP status codes:
200- Success400- Bad Request (invalid parameters)404- Not Found (resource doesn't exist)500- Internal Server Error
CORS is enabled for all origins, allowing frontend applications to access the API from any domain.
Run the test suite:
python test_api_endpoints.pyThis will test all endpoints and provide a detailed report.
curl http://127.0.0.1:5000/api/live/campuscurl http://127.0.0.1:5000/api/prediction/next-hourcurl http://127.0.0.1:5000/api/optimization/savingscurl -X POST http://127.0.0.1:5000/api/prediction/train \
-H "Content-Type: application/json" \
-d '{"hours_back": 168}'