API Documentation

RESTful API endpoints for the Leaf Link smart plant monitoring system.

Base URL

http://localhost:8080

Authentication

All API endpoints require an API key to be passed in the header:

X-API-Key: your-api-key-here

Endpoints

POST /add-new-device

Register a new plant monitoring device

Request Body

{
    "device_id": "PLANT_001",
    "plant_name": "Tomato Plant",
    "location": "Garden Bed A",
    "moisture_threshold": 30
}

Response

{
    "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"
    }
}
POST /delete-device

Remove a registered device

Request Body

{
    "device_id": "PLANT_001"
}

Response

{
    "status": "success",
    "message": "Device PLANT_001 deleted successfully"
}
POST /check-registered-devices

Retrieve all registered devices or filter by criteria

Request Body (Optional)

{
    "location": "Garden Bed A",
    "status": "active"
}

Response

{
    "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"
        }
    ]
}
POST /update-moisture

Update moisture reading for a device

Request Body

{
    "device_id": "PLANT_001",
    "moisture_level": 42,
    "timestamp": "2024-01-15T11:00:00Z"
}

Response

{
    "status": "success",
    "message": "Moisture level updated",
    "should_water": false
}
POST /water-plant

Trigger watering for a specific plant

Request Body

{
    "device_id": "PLANT_001",
    "duration_seconds": 30
}

Response

{
    "status": "success",
    "message": "Watering command sent to device PLANT_001",
    "duration": 30
}
GET /device/:device_id/history

Get moisture and watering history for a device

Query Parameters

GET /device/PLANT_001/history?days=7

Response

{
    "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
        }
    ]
}

Error Responses

All endpoints may return error responses in the following format:

{
    "status": "error",
    "message": "Device not found",
    "error_code": "DEVICE_NOT_FOUND"
}

Status Codes