REST API Documentation

IoT Dashboard - ESP8266 / ESP32

สารบัญ

Quick Start

Base URL:
https://project12569.theeeiot.com/EE67172310161/API/V1/
API Keys:
esp8266_key_001
esp32_key_001
demo_key

ทดสอบเร็ว - Copy & Paste

# ทดสอบการเชื่อมต่อ (ต้องได้รับ "API is working!") curl "https://project12569.theeeiot.com/EE67172310161/API/V1/get.php?api_key=demo_key&action=ping" # ส่งข้อมูลอุณหภูมิ curl -X POST "https://project12569.theeeiot.com/EE67172310161/API/V1/post.php?api_key=demo_key" \ -H "Content-Type: application/json" \ -d '{"temp1": 28.5, "humi1": 65.0}'

GET API - ดึงข้อมูล

GET /API/V1/get.php?api_key=xxx&action=xxx

1 Parameters

ParameterRequiredDescription
api_keyYesAPI Key สำหรับยืนยันตัวตน
actionYesฟังก์ชันที่ต้องการเรียก
limitNoจำนวน records (action=history, default=20, max=100)
roomNoหมายเลขห้อง (action=latest_room, stats, average)
dateNoวันที่ format dd/mm/yyyy (action=bydate)

2 Actions ทั้งหมด

Actionคำอธิบายตัวอย่าง Parameters
pingทดสอบการเชื่อมต่อ API-
latestข้อมูลล่าสุด 1 record-
latest_roomข้อมูลล่าสุดของห้องที่กำหนดroom=18207
historyข้อมูลล่าสุด N recordslimit=10
bydateข้อมูลตามวันที่date=25/08/2026
averageค่าเฉลี่ยทั้งหมดของห้องroom=18207
statsสถิติ Min/Max ของห้องroom=18207
roomsรายชื่อห้องทั้งหมด-

Live Test - GET

3 curl ตัวอย่าง - แต่ละ Action

Ping - ทดสอบการเชื่อมต่อ

curl "https://project12569.theeeiot.com/EE67172310161/API/V1/get.php?api_key=demo_key&action=ping"

Latest - ข้อมูลล่าสุด

curl "https://project12569.theeeiot.com/EE67172310161/API/V1/get.php?api_key=demo_key&action=latest"

Latest Room - ข้อมูลล่าสุดของห้อง

curl "https://project12569.theeeiot.com/EE67172310161/API/V1/get.php?api_key=demo_key&action=latest_room&room=18207"

History - ข้อมูลย้อนหลัง 10 records

curl "https://project12569.theeeiot.com/EE67172310161/API/V1/get.php?api_key=demo_key&action=history&limit=10"

History - ข้อมูลย้อนหลัง 100 records

curl "https://project12569.theeeiot.com/EE67172310161/API/V1/get.php?api_key=demo_key&action=history&limit=100"

By Date - ข้อมูลตามวันที่

# format: dd/mm/yyyy curl "https://project12569.theeeiot.com/EE67172310161/API/V1/get.php?api_key=demo_key&action=bydate&date=25/08/2026"

Average - ค่าเฉลี่ย

curl "https://project12569.theeeiot.com/EE67172310161/API/V1/get.php?api_key=demo_key&action=average"

Stats - สถิติ Min/Max

curl "https://project12569.theeeiot.com/EE67172310161/API/V1/get.php?api_key=demo_key&action=stats"

Rooms - รายชื่อห้องทั้งหมด

curl "https://project12569.theeeiot.com/EE67172310161/API/V1/get.php?api_key=demo_key&action=rooms"

POST API - ส่งข้อมูล

POST /API/V1/post.php?api_key=xxx
Headers ที่ต้องใช้:
Content-Type: application/json
X-API-Key: xxx (ทางเลือก แทน query param)

1 Request Body (JSON)

FieldTypeRequiredDescription
temp1floatNoอุณหภูมิเซ็นเซอร์ 1 (°C)
temp2floatNoอุณหภูมิเซ็นเซอร์ 2 (°C)
humi1floatNoความชื้นเซ็นเซอร์ 1 (%)
humi2floatNoความชื้นเซ็นเซอร์ 2 (%)
volt1floatNoแรงดันไฟฟ้า (V)
current1floatNoกระแสไฟฟ้า (A)
power1floatNoกำลังไฟฟ้า (W)
kwh1floatNoหน่วยไฟฟ้า (kWh)
freq1floatNoความถี่ (Hz)
pf1floatNoPower Factor
หมายเหตุ: ส่งอย่างน้อย 1 field ก็ได้ ไม่ต้องส่งครบทุก field

Live Test - POST

2 curl ตัวอย่าง - POST ส่งข้อมูล

ส่งข้อมูลครบทุก field

curl -X POST "https://project12569.theeeiot.com/EE67172310161/API/V1/post.php?api_key=demo_key" \ -H "Content-Type: application/json" \ -d '{ "temp1": 28.5, "temp2": 27.2, "humi1": 66.5, "humi2": 63.0, "volt1": 225.8, "current1": 0.42, "power1": 94.8, "kwh1": 380.5, "freq1": 50.0, "pf1": 0.98 }'

ส่งข้อมูลแค่บาง field

curl -X POST "https://project12569.theeeiot.com/EE67172310161/API/V1/post.php?api_key=demo_key" \ -H "Content-Type: application/json" \ -d '{"temp1": 29.0, "humi1": 70.5}'

ส่งแบบ URL Encoded (เหมาะสำหรับ Arduino)

curl -X POST "https://project12569.theeeiot.com/EE67172310161/API/V1/post.php?api_key=demo_key" \ -d "temp1=28.5&humi1=66.5&volt1=225.8¤t1=0.42&power1=94.8"

ใช้ Header X-API-Key แทน query param

curl -X POST "https://project12569.theeeiot.com/EE67172310161/API/V1/post.php" \ -H "Content-Type: application/json" \ -H "X-API-Key: demo_key" \ -d '{"temp1": 28.5, "humi1": 65.0}'

Arduino Code Example

1 ESP8266 - POST ส่งข้อมูล

// ESP8266 - POST ส่งข้อมูลไป API // ต้องติดตั้ง library: ESP8266HTTPClient, ArduinoJson #include <ESP8266WiFi.h> #include <ESP8266HTTPClient.h> #include <WiFiClient.h> #include <ArduinoJson.h> const char* WIFI_SSID = "YOUR_WIFI_SSID"; const char* WIFI_PASS = "YOUR_WIFI_PASSWORD"; const char* API_HOST = "project12569.theeeiot.com"; const char* API_KEY = "esp8266_key_001"; void sendData(float temp, float humi, float volt, float current) { if (WiFi.status() == WL_CONNECTED) { WiFiClient client; HTTPClient http; String url = "http://" + String(API_HOST) + "/EE67172310161/API/V1/post.php?api_key=" + API_KEY; http.begin(client, url); http.addHeader("Content-Type", "application/json"); StaticJsonDocument<256> doc; doc["temp1"] = temp; doc["humi1"] = humi; doc["volt1"] = volt; doc["current1"] = current; String json; serializeJson(doc, json); int httpCode = http.POST(json); if (httpCode > 0) { String response = http.getString(); Serial.println(response); } http.end(); } }

2 ESP8266 - GET ดึงข้อมูล

void getLatestData() { if (WiFi.status() == WL_CONNECTED) { WiFiClient client; HTTPClient http; String url = "http://" + String(API_HOST) + "/EE67172310161/API/V1/get.php?api_key=" + API_KEY + "&action=latest"; http.begin(client, url); int httpCode = http.GET(); if (httpCode > 0) { String response = http.getString(); DynamicJsonDocument doc(1024); deserializeJson(doc, response); float temp = doc["data"]["Temp1"]; float humi = doc["data"]["Humi1"]; float volt = doc["data"]["Volt1"]; Serial.printf("Temp: %.1fC, Humi: %.1f%%, Volt: %.1fV\n", temp, humi, volt); } http.end(); } }

3 ESP32 - POST ส่งข้อมูล

// ESP32 - POST ส่งข้อมูลไป API // ต้องติดตั้ง library: HTTPClient, ArduinoJson #include <WiFi.h> #include <HTTPClient.h> #include <ArduinoJson.h> const char* WIFI_SSID = "YOUR_WIFI_SSID"; const char* WIFI_PASS = "YOUR_WIFI_PASSWORD"; const char* API_HOST = "project12569.theeeiot.com"; const char* API_KEY = "esp32_key_001"; void sendData(float temp, float humi, float volt, float current) { if (WiFi.status() == WL_CONNECTED) { HTTPClient http; String url = "https://" + String(API_HOST) + "/EE67172310161/API/V1/post.php?api_key=" + API_KEY; http.begin(url); http.addHeader("Content-Type", "application/json"); StaticJsonDocument<256> doc; doc["temp1"] = temp; doc["humi1"] = humi; doc["volt1"] = volt; doc["current1"] = current; String json; serializeJson(doc, json); int httpCode = http.POST(json); if (httpCode > 0) { String response = http.getString(); Serial.println(response); } http.end(); } } void setup() { Serial.begin(115200); WiFi.begin(WIFI_SSID, WIFI_PASS); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("WiFi connected!"); } void loop() { sendData(28.5, 65.0, 226.0, 0.45); delay(30000); // รอ 30 วินาที (rate limit) }

Response Format

1 Success Response (GET latest)

{ "status": "success", "action": "latest", "data": { "ID": "1002", "ddate": "2026-08-25 15:06:52", "Room": "18207", "Temp1": "29.00", "Temp2": "0.00", "Humi1": "67.00", "Humi2": "0.00", "Volt1": "225.50", "Current1": "0.48", "Power1": "108.20", "Kwh1": "0.00", "Freq1": "0.00", "Pf1": "0.00" } }

2 Success Response (GET history)

{ "status": "success", "action": "history", "count": 10, "limit": 10, "data": [ { "ID": "1002", "ddate": "2026-08-25 15:06:52", ... }, { "ID": "1001", "ddate": "2026-08-25 08:30:03", ... }, ... ] }

3 Success Response (GET average)

{ "status": "success", "action": "average", "room": 18207, "data": { "total_records": 1002, "avg_temp1": 28.75, "avg_humi1": 71.33, "avg_volt1": 226.42, "avg_current1": 0.31, "avg_power1": 69.85, "first_record": "2022-07-28 17:34:47", "last_record": "2026-08-25 15:06:52" } }

4 Success Response (GET stats)

{ "status": "success", "action": "stats", "room": 18207, "data": { "min_temp1": 26.30, "max_temp1": 30.50, "min_humi1": 52.30, "max_humi1": 86.50, "min_volt1": 218.00, "max_volt1": 232.00, "total_records": 1002 } }

5 Success Response (POST)

{ "status": "success", "message": "Data saved successfully", "id": 1003, "device": "ESP8266-NodeMCU", "room": 18207, "timestamp": "2026-08-25 15:30:00", "data": { "temp1": 28.5, "humi1": 65, "volt1": 226, "current1": 0.45, "power1": 101.7, "kwh1": 0, "freq1": 0, "pf1": 0 } }

6 Success Response (GET ping)

{ "status": "success", "action": "ping", "message": "API is working!", "device": "Demo Device", "server": "2026-08-25 15:30:00", "version": "V1" }

Error Responses

HTTP CodeErrorสาเหตุวิธีแก้
401Missing API Keyไม่ได้ส่ง api_keyเพิ่ม ?api_key=xxx หรือ header X-API-Key
403Invalid API Keyapi_key ผิดหรือถูกปิดใช้งานตรวจสอบ api_key ใน config.php
405Method not allowedใช้ method ผิด (GET แทน POST)เปลี่ยนเป็น method ที่ถูกต้อง
400Invalid JSONJSON body ผิด formatตรวจสอบ JSON syntax
400No sensor dataไม่ได้ส่ง field ใดเลยส่งอย่างน้อย 1 field
429Rate limitส่งเร็วเกินไป (รอ 30 วินาที)delay อย่างน้อย 30 วินาที
404No data foundไม่มีข้อมูลในระบบตรวจสอบ action/room/date

1 Error Response Examples

// 401 - ไม่มี API Key { "status": "error", "message": "Missing API Key. Send as parameter \"api_key\"" } // 403 - API Key ผิด { "status": "error", "message": "Invalid or inactive API Key" } // 405 - Method ผิด { "status": "error", "message": "Method not allowed. Use POST." } // 429 - Rate limit { "status": "error", "message": "Rate limit: Wait 25 seconds before next send" } // 400 - JSON ผิด format { "status": "error", "message": "Invalid JSON body" } // 400 - ไม่มี sensor data { "status": "error", "message": "No sensor data provided. Send at least one: temp1, temp2, ..." } // 404 - ไม่มีข้อมูล { "status": "error", "message": "No data found for room 18207" } // 400 - action ผิด { "status": "error", "message": "Unknown action: xxx", "available_actions": ["latest", "latest_room", "history", ...] }

Rate Limit

จำกัดการส่งข้อมูลทุกๆ 30 วินาที ต่อห้อง
ถ้าส่งเร็วเกินไป จะได้ HTTP 429 พร้อมข้อความ "Rate limit: Wait X seconds"

1 วิธีตรวจสอบ Rate Limit

// Arduino - ตรวจสอบก่อนส่ง unsigned long lastSendTime = 0; const unsigned long RATE_LIMIT = 30000; // 30 วินาที void loop() { if (millis() - lastSendTime >= RATE_LIMIT) { sendData(temp, humi, volt, current); lastSendTime = millis(); } delay(1000); }