Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/GaelCeballos/Smart_Enviro_Backend/llms.txt

Use this file to discover all available pages before exploring further.

Returns sensor readings averaged over time intervals for chart rendering. For a daily view, readings are averaged per hour over the last 24 hours. For weekly and monthly views, readings are averaged per calendar day. This endpoint requires Bearer token authentication.

Endpoint

GET /api/sensor-data/history Auth: Bearer token required (Sanctum)
This route is defined before the apiResource registration in routes/api.php to avoid route conflicts with the show action. It requires authentication with a Sanctum Bearer token — requests without a valid token will receive a 401 Unauthenticated response.

Query Parameters

device_id
integer
required
The integer database ID of the device whose readings should be aggregated.
sensor_type_id
integer
required
The integer database ID of the sensor type to aggregate. This endpoint expects the integer ID, not the metric_key string.
period
string
required
The time window and grouping strategy for aggregation. Accepted values: day, week, month.

Period Reference

PeriodWindowGroupingSQL Aggregation
dayLast 24 hoursPer hourAVG grouped by DATE_FORMAT(recorded_at, '%H:00')
weekLast 7 daysPer calendar dayAVG grouped by DATE(recorded_at)
monthLast 30 daysPer calendar dayAVG grouped by DATE(recorded_at)

Example Request

curl -X GET "http://localhost/api/sensor-data/history?device_id=3&sensor_type_id=2&period=day" \
  -H "Authorization: Bearer YOUR_TOKEN"

Responses

200 OK

Returns the averaged data points ordered chronologically by label (ascending). Only time slots that have at least one reading are included — empty hours or days are omitted.
{
  "status": "success",
  "period": "day",
  "count": 6,
  "data": [
    {"label": "08:00", "value": 71.2},
    {"label": "09:00", "value": 72.8},
    {"label": "10:00", "value": 73.5},
    {"label": "11:00", "value": 74.1},
    {"label": "12:00", "value": 70.9},
    {"label": "13:00", "value": 69.4}
  ]
}
status
string
Always "success" on a 200 response.
period
string
Echoes back the requested period value ("day", "week", or "month").
count
integer
The number of aggregated data points returned in the data array. Equals the number of distinct hours or days that had at least one reading in the time window.
data
array
Array of aggregated data point objects, ordered ascending by label.

401 Unauthenticated

No Bearer token was provided or the token is invalid/expired.

422 Unprocessable Entity

One or more required query parameters (device_id, sensor_type_id, period) are missing, or period is not one of day, week, month.
The label field is ready to use as a chart x-axis label. For day period, labels are like "08:00". For week and month periods, labels are ISO date strings like "2024-01-15". Only time slots with actual readings are included, so the array may have gaps.

Build docs developers (and LLMs) love