Quick Start
Base URL:
https://project12569.theeeiot.com/EE67172310161/API/V1/
API Keys:
esp8266_key_001
esp32_key_001
demo_key
ทดสอบเร็ว - Copy & Paste
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
| Parameter | Required | Description |
api_key | Yes | API Key สำหรับยืนยันตัวตน |
action | Yes | ฟังก์ชันที่ต้องการเรียก |
limit | No | จำนวน records (action=history, default=20, max=100) |
room | No | หมายเลขห้อง (action=latest_room, stats, average) |
date | No | วันที่ format dd/mm/yyyy (action=bydate) |
2 Actions ทั้งหมด
| Action | คำอธิบาย | ตัวอย่าง Parameters |
ping | ทดสอบการเชื่อมต่อ API | - |
latest | ข้อมูลล่าสุด 1 record | - |
latest_room | ข้อมูลล่าสุดของห้องที่กำหนด | room=18207 |
history | ข้อมูลล่าสุด N records | limit=10 |
bydate | ข้อมูลตามวันที่ | date=25/08/2026 |
average | ค่าเฉลี่ยทั้งหมดของห้อง | room=18207 |
stats | สถิติ Min/Max ของห้อง | room=18207 |
rooms | รายชื่อห้องทั้งหมด | - |
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 - ข้อมูลตามวันที่
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)
| Field | Type | Required | Description |
temp1 | float | No | อุณหภูมิเซ็นเซอร์ 1 (°C) |
temp2 | float | No | อุณหภูมิเซ็นเซอร์ 2 (°C) |
humi1 | float | No | ความชื้นเซ็นเซอร์ 1 (%) |
humi2 | float | No | ความชื้นเซ็นเซอร์ 2 (%) |
volt1 | float | No | แรงดันไฟฟ้า (V) |
current1 | float | No | กระแสไฟฟ้า (A) |
power1 | float | No | กำลังไฟฟ้า (W) |
kwh1 | float | No | หน่วยไฟฟ้า (kWh) |
freq1 | float | No | ความถี่ (Hz) |
pf1 | float | No | Power Factor |
หมายเหตุ: ส่งอย่างน้อย 1 field ก็ได้ ไม่ต้องส่งครบทุก field
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 ส่งข้อมูล
#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 ส่งข้อมูล
#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);
}
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 Code | Error | สาเหตุ | วิธีแก้ |
401 | Missing API Key | ไม่ได้ส่ง api_key | เพิ่ม ?api_key=xxx หรือ header X-API-Key |
403 | Invalid API Key | api_key ผิดหรือถูกปิดใช้งาน | ตรวจสอบ api_key ใน config.php |
405 | Method not allowed | ใช้ method ผิด (GET แทน POST) | เปลี่ยนเป็น method ที่ถูกต้อง |
400 | Invalid JSON | JSON body ผิด format | ตรวจสอบ JSON syntax |
400 | No sensor data | ไม่ได้ส่ง field ใดเลย | ส่งอย่างน้อย 1 field |
429 | Rate limit | ส่งเร็วเกินไป (รอ 30 วินาที) | delay อย่างน้อย 30 วินาที |
404 | No data found | ไม่มีข้อมูลในระบบ | ตรวจสอบ action/room/date |
1 Error Response Examples
{ "status": "error", "message": "Missing API Key. Send as parameter \"api_key\"" }
{ "status": "error", "message": "Invalid or inactive API Key" }
{ "status": "error", "message": "Method not allowed. Use POST." }
{ "status": "error", "message": "Rate limit: Wait 25 seconds before next send" }
{ "status": "error", "message": "Invalid JSON body" }
{ "status": "error", "message": "No sensor data provided. Send at least one: temp1, temp2, ..." }
{ "status": "error", "message": "No data found for room 18207" }
{ "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
unsigned long lastSendTime = 0;
const unsigned long RATE_LIMIT = 30000;
void loop() {
if (millis() - lastSendTime >= RATE_LIMIT) {
sendData(temp, humi, volt, current);
lastSendTime = millis();
}
delay(1000);
}