RESTful API endpoints for the Leaf Link smart plant monitoring system.
http://localhost:8080
All API endpoints require an API key to be passed in the header:
X-API-Key: your-api-key-here
Register a new plant monitoring device
{
"device_id": "PLANT_001",
"plant_name": "Tomato Plant",
"location": "Garden Bed A",
"moisture_threshold": 30
}
{
"status": "success",
"message": "Device PLANT_001 added successfully",
"device": {
"device_id": "PLANT_001",
"plant_name": "Tomato Plant",
"location": "Garden Bed A",
"moisture_threshold": 30,
"created_at": "2024-01-15T10:30:00Z"
}
}
Remove a registered device
{
"device_id": "PLANT_001"
}
{
"status": "success",
"message": "Device PLANT_001 deleted successfully"
}
Retrieve all registered devices or filter by criteria
{
"location": "Garden Bed A",
"status": "active"
}
{
"status": "success",
"devices": [
{
"device_id": "PLANT_001",
"plant_name": "Tomato Plant",
"location": "Garden Bed A",
"moisture_threshold": 30,
"last_moisture": 45,
"last_watered": "2024-01-15T09:00:00Z",
"status": "active"
},
{
"device_id": "PLANT_002",
"plant_name": "Basil",
"location": "Garden Bed A",
"moisture_threshold": 35,
"last_moisture": 28,
"last_watered": "2024-01-15T10:00:00Z",
"status": "active"
}
]
}
Update moisture reading for a device
{
"device_id": "PLANT_001",
"moisture_level": 42,
"timestamp": "2024-01-15T11:00:00Z"
}
{
"status": "success",
"message": "Moisture level updated",
"should_water": false
}
Trigger watering for a specific plant
{
"device_id": "PLANT_001",
"duration_seconds": 30
}
{
"status": "success",
"message": "Watering command sent to device PLANT_001",
"duration": 30
}
Get moisture and watering history for a device
GET /device/PLANT_001/history?days=7
{
"status": "success",
"device_id": "PLANT_001",
"history": [
{
"timestamp": "2024-01-15T11:00:00Z",
"moisture_level": 42,
"watered": false
},
{
"timestamp": "2024-01-15T10:00:00Z",
"moisture_level": 28,
"watered": true,
"water_duration": 30
}
]
}
All endpoints may return error responses in the following format:
{
"status": "error",
"message": "Device not found",
"error_code": "DEVICE_NOT_FOUND"
}