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 ชั่วคราวสำหรับการทดสอบของอาจารย์ หลังสาธิตเสร็จควรซ่อนคีย์กลับอีกครั้ง
🔐 Production API Key
a3c43d1a91a4f9c57d38d5f8dec938729075fffaab105d84
Temporarily displayed for instructor testing.This is the real key used by insert_data.php. แสดงชั่วคราวสำหรับการทดสอบของอาจารย์
คีย์นี้เป็นคีย์จริงที่ใช้กับ insert_data.php
🧪 Demo API Key
🧪 Demo API Key สำหรับทดสอบ
AIRMONITOR_DEMO_2026
Used only by the Demo POST Tester.Demo requests do not write to sensor_data. ใช้เฉพาะกับ Demo POST Tester
ข้อมูล Demo จะไม่บันทึกลง 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.
Production POST จะบันทึกลง sensor_data จริงและกลายเป็นค่าล่าสุดใน Dashboard / History
ส่วน Demo POST แยกออกจากข้อมูลจริงและไม่กระทบ sensor_data
GET Tester
Endpoint
—
GET Endpoint Guide
คำอธิบาย GET Endpoint
get_latest.php
Read the latest sensor record.
อ่านค่าจากเซนเซอร์รายการล่าสุด
get_history.php
Read history for 1H / 24H / 7D / 30D.
อ่านข้อมูลย้อนหลัง 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.
อ่านประวัติ Alert และ Recovery
get_settings.php
Read sampling and threshold settings.
อ่านค่าการตั้ง Sampling และ Threshold
Production POST Tester ทดสอบ Production POST
⚠️ 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.
⚠️ นี่คือ POST จริง เมื่อ API Key ถูกต้อง ค่าที่กรอกจะถูกบันทึกลง sensor_data และกลายเป็นข้อมูลล่าสุดใน Dashboard / History
—
Demo POST Tester ทดสอบ Demo POST
🧪 Demo only: sends to demo_insert_data.php and does not write to sensor_data or replace the latest real reading.
🧪 Demo เท่านั้น: ส่งไป demo_insert_data.php และไม่บันทึกลง sensor_data จึงไม่แทนค่าล่าสุดของข้อมูลจริง
—
Demo POST Log ประวัติ Demo POST
Latest 5 records from api_test_log
5 รายการล่าสุดจาก api_test_log
| Timeเวลา | Device | Temp | Hum | eCO₂ | TVOC | AQI | RSSI |
|---|---|---|---|---|---|---|---|
| Loading demo log… กำลังโหลด Demo Log… | |||||||
Demo records are isolated from sensor_data and do not change the real Dashboard / History.
ข้อมูล Demo แยกจาก sensor_data และไม่เปลี่ยนข้อมูลจริงใน 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_key | string | yes | Production access key (displayed temporarily for testing) |
| device_id | string | no | Device identifier. Optional — defaults to BEDROOM_ESP32 when omitted. |
| temperature | decimal | yes | Temperature in °C |
| humidity | decimal | yes | Relative humidity in % |
| eco2 | integer | yes | Equivalent CO₂ (eCO₂) in ppm from ENS160 |
| tvoc | integer | yes | Total Volatile Organic Compounds in ppb |
| aqi | integer | yes | Air Quality Index 1–5 |
| rssi | integer | yes | Wi-Fi signal strength in dBm |
| ens160_ok | integer | no | ENS160 health from firmware: 1 = OK, 0 = fault. Omit when not reporting. |
| aht21_ok | integer | no | AHT21 health from firmware: 1 = OK, 0 = fault. Omit when not reporting. |
| sensor_disconnected | integer | no | Physical 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)ข้อมูลล่าสุด (อุณหภูมิ ความชื้น 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ข้อมูลย้อนหลัง range รับค่า 1h, 24h, 7d หรือ 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)ข้อมูลย้อนหลังระหว่างวันที่สองวันที่ (prepared statements, ไม่เกิน 90 วัน)
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)บันทึกการแจ้งเตือน/คืนค่าปกติ limit ไม่บังคับ (ค่าเริ่มต้น 10 สูงสุด 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"}}