Dashboard
Air Monitor
ห้องนอนของฉัน • นายเมธา อินสิม • รหัส 67172310085-7 My Bedroom • Metha Insim • Student ID 67172310085-7
Offline --:--:--

REST API

API documentation for integration
Production API Key is displayed temporarily for instructor testing. Remove or mask it again after the demonstration.
🔐 Production API Key
a3c43d1a91a4f9c57d38d5f8dec938729075fffaab105d84
Temporarily displayed for instructor testing.
This is the real key used by insert_data.php.
🧪 Demo API Key
AIRMONITOR_DEMO_2026
Used only by the Demo POST Tester.
Demo requests do not write to sensor_data.

Interactive API Tester

Production POST writes to the real sensor_data table and becomes the latest Dashboard / History reading. Demo POST is isolated and does not affect real sensor data.

GET Tester

Endpoint
—
GET Endpoint Guide
get_latest.php
Read the latest sensor record.
get_history.php
Read history for 1H / 24H / 7D / 30D.
get_history_custom.php
Read history between custom date/time values.
get_summary.php
Read today's summary statistics.
get_alerts.php
Read alert and recovery history.
get_settings.php
Read sampling and threshold settings.

Production POST Tester

⚠️ This is a REAL POST. When the API Key is valid, the submitted values are saved to sensor_data and become the latest Dashboard / History reading.
—

Demo POST Tester

🧪 Demo only: sends to demo_insert_data.php and does not write to sensor_data or replace the latest real reading.
—

Demo POST Log

Latest 5 records from api_test_log
Time Device Temp Hum eCO₂ TVOC AQI RSSI
Loading demo log…
Demo records are isolated from sensor_data and do not change the real Dashboard / History.

POST Endpoint

POST insert_data.php
Save sensor data from ESP32 (device -> server)

Request example

{ "api_key": "a3c43d1a91a4f9c57d38d5f8dec938729075fffaab105d84", "device_id": "BEDROOM_ESP32", "temperature": 26.5, "humidity": 62.8, "eco2": 499, "tvoc": 72, "aqi": 2, "rssi": -28, "ens160_ok": 1, "aht21_ok": 1, "sensor_disconnected": 0 }

Request parameters

Parameter Type Required Description
api_keystringyesProduction access key (displayed temporarily for testing)
device_idstringnoDevice identifier. Optional — defaults to BEDROOM_ESP32 when omitted.
temperaturedecimalyesTemperature in °C
humiditydecimalyesRelative humidity in %
eco2integeryesEquivalent CO₂ (eCO₂) in ppm from ENS160
tvocintegeryesTotal Volatile Organic Compounds in ppb
aqiintegeryesAir Quality Index 1–5
rssiintegeryesWi-Fi signal strength in dBm
ens160_okintegernoENS160 health from firmware: 1 = OK, 0 = fault. Omit when not reporting.
aht21_okintegernoAHT21 health from firmware: 1 = OK, 0 = fault. Omit when not reporting.
sensor_disconnectedintegernoPhysical sensor connection from firmware: 1 = disconnected, 0 = connected. Only accepted when actually reported by the firmware.

Required sensor fields: temperature, humidity, eco2, tvoc, aqi, rssi. device_id is optional and defaults to BEDROOM_ESP32. The firmware health fields (ens160_ok, aht21_ok, sensor_disconnected) are optional and are only used to raise SENSOR_ERROR_*/SENSOR_DISCONNECTED alerts when the ESP32 reports them — they are never inferred server-side.

Example response

{ "success": true, "message": "Data saved", "id": 43 }

GET Endpoints

GET get_latest.php
Latest sensor reading (temperature, humidity, eCO₂, TVOC, AQI, RSSI)

Example response

{"success":true,"data":{"id":43,"device_id":"BEDROOM_ESP32","temperature":"25.77","humidity":"60.76","eco2":464,"tvoc":54,"aqi":1,"rssi":-31,"created_at":"2026-09-18 17:15:24"}}
GET get_history.php?range=24h
Historical readings. range accepts 1h, 24h, 7d or 30d

Example response

{"success":true,"range":"24h","count":14,"data":[{"id":43,"temperature":"25.77","humidity":"60.76","eco2":464,"tvoc":54,"aqi":1,"rssi":-31,"created_at":"2026-09-18 17:15:24"}]}
GET get_history_custom.php?start=2026-09-16%2000:00:00&end=2026-09-18%2023:59:59
History between two datetimes (prepared statements, max 90 days)

Example response

{"success":true,"count":31,"start":"2026-09-16 00:00:00","end":"2026-09-18 23:59:59","data":[{"id":43,"temperature":"25.77","humidity":"60.76","eco2":464,"tvoc":54,"aqi":1,"rssi":-31,"created_at":"2026-09-18 17:15:24"}]}
GET get_summary.php
Today's aggregated statistics

Example response

{"success":true,"date":"2026-09-18","data":{"total_records":14,"avg_temperature":"26.11","min_temperature":"25.77","max_temperature":"26.51","avg_humidity":"61.21","min_humidity":"59.61","max_humidity":"63.17","max_eco2":521,"max_tvoc":84,"worst_aqi":2}}
GET get_alerts.php?limit=5
Alert / recovery log. Optional limit (default 10, max 100)

Example response

{"success":true,"count":2,"data":[{"id":2,"device_id":"BEDROOM_ESP32","alert_type":"HUMIDITY_HIGH","sensor_value":"62.84","threshold_value":"70.00","status":"NORMAL","message":"Humidity returned to normal","created_at":"2026-09-18 17:00:21"}]}
GET get_settings.php
System settings (sampling interval, retention, thresholds) read-only

Example response

{"success":true,"data":{"sampling_interval":"5","data_retention_days":"7","temperature_high":"30","humidity_high":"70","tvoc_high":"500","eco2_high":"1200","aqi_alert":"4"}}