Documentation
API Reference
Access MudPi data and controls programmatically through the REST API.
Overview
The MudPi API is served by the Solarbeam platform and provides endpoints for reading sensor data, controlling relays, and managing your system configuration.
Authentication
API requests require an API key passed in the Authorization header:
Shell
curl -H "Authorization: Bearer YOUR_API_KEY" \
https://your-mudpi.local/api/sensors
Endpoints
GET
/api/sensors
Returns a list of all configured sensors and their latest readings.
GET
/api/sensors/{id}
Returns detailed data for a specific sensor including historical readings.
GET
/api/controls
Returns a list of all controls and their current state.
POST
/api/controls/{id}/toggle
Toggles the state of a specific control (e.g., turn a relay on or off).
GET
/api/events
Returns recent system events.
Response Format
All API responses are JSON. Successful responses include a data key:
JSON
{
"data": {
"id": "garden-bed-1",
"name": "Garden Bed 1",
"type": "soil_moisture",
"value": 62.5,
"unit": "percent",
"last_reading": "2024-03-15T10:30:00Z"
}
}
Error responses include an error key with a message:
JSON
{
"error": {
"code": 404,
"message": "Sensor not found"
}
}
Full Example
Fetch all sensors and toggle a control based on the response:
Shell
# Get all sensor readings
curl -s -H "Authorization: Bearer YOUR_API_KEY" \
https://your-mudpi.local/api/sensors | python3 -m json.tool
# Toggle a specific control
curl -X POST -H "Authorization: Bearer YOUR_API_KEY" \
https://your-mudpi.local/api/controls/main-water-valve/toggle