Overview
| Item | Value |
| Base URL | http://119.59.96.93/api/v1/ |
| Local URL | http://localhost/api/v1/ |
| API Key | iot_rmuti_2024 |
| Database | DB12569_EE66172310386 |
| Table | data_iot_test |
| Format | JSON |
| Port | 3306 (MySQL) / 80 (HTTP) |
API Key ต้องส่งใน POST body เท่านั้น สำหรับ GET แนะนำให้ส่งผ่าน query string
POST API - ส่งข้อมูลจาก ESP
POST
http://119.59.96.93/api/v1/post.php
ส่งข้อมูล sensor จาก ESP32/ESP8266 ไปเก็บใน MySQL
Request Headers
Content-Type: application/json
Request Body (JSON)
| Field | Type | Required | Example | Description |
api_key | string | REQUIRED | "iot_rmuti_2024" | API Key สำหรับยืนยันตัวตน |
Room | integer | REQUIRED | "18207" | รหัสห้อง |
Temp1 | float | optional | "27.50" | อุณหภูมิ sensor 1 |
Temp2 | float | optional | "28.10" | อุณหภูมิ sensor 2 |
Humi1 | float | optional | "68.50" | ความชื้น sensor 1 |
Humi2 | float | optional | "65.20" | ความชื้น sensor 2 |
Volt1 | float | optional | "227.50" | แรงดันไฟฟ้า (V) |
Current1 | float | optional | "0.50" | กระแสไฟฟ้า (A) |
Power1 | float | optional | "113.75" | กำลังไฟฟ้า (W) |
Kwh1 | float | optional | "372.14" | พลังงานไฟฟ้า (kWh) |
Freq1 | float | optional | "49.90" | ความถี่ (Hz) |
Pf1 | float | optional | "1.00" | Power Factor |
(ddate, date1, time1) จะถูกสร้างอัตโนมัติจาก server time ไม่ต้องส่งมา
Response สำเร็จ 200 OK
{
"status": "success",
"message": "Data inserted successfully",
"id": 1001,
"datetime": "2026-08-25 13:37:45"
}
Response ผิดพลาด
{ "status": "error", "message": "Invalid API key" }
{ "status": "error", "message": "Missing required field: Room" }
{ "status": "error", "message": "Invalid JSON body" }
GET API - ดึงข้อมูล
GET
http://119.59.96.93/api/v1/get.php
ดึงข้อมูลจาก MySQL กลับมาในรูปแบบ JSON
Query Parameters
| Parameter | Type | Required | Example | Description |
api_key | string | optional | ?api_key=iot_rmuti_2024 | API Key |
latest | string | optional | ?latest=1 | ดึงข้อมูลล่าสุด 1 record |
limit | integer | optional | ?limit=50 | จำนวน records สูงสุด 1000 (default: 10) |
room | integer | optional | ?room=18207 | กรองตามห้อง |
from | string | optional | ?from=2022-08-05 | วันที่เริ่มต้น (YYYY-MM-DD) |
to | string | optional | &to=2022-08-06 | วันที่สิ้นสุด (YYYY-MM-DD) |
id | integer | optional | ?id=100 | ดึงข้อมูลตาม ID |
Request Examples
| URL | คำอธิบาย |
/get.php | ดึง 10 รายการล่าสุด |
/get.php?latest=1 | ดึงข้อมูลล่าสุด 1 record |
/get.php?limit=50 | ดึง 50 รายการล่าสุด |
/get.php?room=18207&limit=20 | ดึง 20 รายการของห้อง 18207 |
/get.php?from=2022-08-05&to=2022-08-06 | ดึงข้อมูลวันที่ 5-6 ส.ค. |
/get.php?id=100 | ดึง record ID=100 |
Response 200 OK
{
"status": "success",
"total": 2,
"data": [
{
"ID": "1000",
"ddate": "2022-08-09 18:04:53",
"Room": "18207",
"Temp1": "29.10",
"Temp2": "27.80",
"Humi1": "68.60",
"Humi2": "62.20",
"Volt1": "224.60",
"Current1": "0.00",
"Power1": "0.00",
"Kwh1": "388.00",
"Freq1": "50.00",
"Pf1": "1.00",
"date1": "09/08/2022",
"time1": "18:04:53"
}
]
}
cURL Test
เปิด Command Prompt หรือ PowerShell แล้วรันคำสั่งเหล่านี้
1. ทดสอบ POST - ส่งข้อมูล
curl -X POST http://119.59.96.93/api/v1/post.php ^
-H "Content-Type: application/json" ^
-d "{\"api_key\":\"iot_rmuti_2024\",\"Room\":\"18207\",\"Temp1\":\"28.50\",\"Temp2\":\"27.80\",\"Humi1\":\"70.20\",\"Humi2\":\"63.10\",\"Volt1\":\"226.30\",\"Current1\":\"0.75\",\"Power1\":\"169.35\",\"Kwh1\":\"388.50\",\"Freq1\":\"50.00\",\"Pf1\":\"0.98\"}"
2. ทดสอบ GET - ดึงข้อมูลล่าสุด
curl http://119.59.96.93/api/v1/get.php?latest=1
curl http://119.59.96.93/api/v1/get.php?limit=50
curl http://119.59.96.93/api/v1/get.php?room=18207&limit=10
curl http://119.59.96.93/api/v1/get.php?from=2022-08-05&to=2022-08-06
curl http://119.59.96.93/api/v1/get.php?id=100
3. cURL สำหรับ PowerShell
$body = '{"api_key":"iot_rmuti_2024","Room":"18207","Temp1":"28.50","Temp2":"27.80","Humi1":"70.20","Humi2":"63.10","Volt1":"226.30","Current1":"0.75","Power1":"169.35","Kwh1":"388.50","Freq1":"50.00","Pf1":"0.98"}'
Invoke-RestMethod -Uri "http://119.59.96.93/api/v1/post.php" -Method POST -Body $body -ContentType "application/json"
Invoke-RestMethod -Uri "http://119.59.96.93/api/v1/get.php?latest=1"
4. cURL สำหรับ Linux/Mac
curl -X POST http://119.59.96.93/api/v1/post.php \
-H "Content-Type: application/json" \
-d '{"api_key":"iot_rmuti_2024","Room":"18207","Temp1":"28.50","Temp2":"27.80","Humi1":"70.20","Humi2":"63.10","Volt1":"226.30","Current1":"0.75","Power1":"169.35","Kwh1":"388.50","Freq1":"50.00","Pf1":"0.98"}'
curl http://119.59.96.93/api/v1/get.php?latest=1
ESP32 Arduino Code
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
const char* SERVER_URL = "http://119.59.96.93/api/v1/post.php";
const char* API_KEY = "iot_rmuti_2024";
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
Serial.println("WiFi Connected!");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(SERVER_URL);
http.addHeader("Content-Type", "application/json");
StaticJsonDocument<512> doc;
doc["api_key"] = API_KEY;
doc["Room"] = "18207";
doc["Temp1"] = "28.50";
doc["Humi1"] = "70.20";
doc["Volt1"] = "226.30";
doc["Current1"] = "0.75";
doc["Power1"] = "169.35";
doc["Kwh1"] = "388.50";
doc["Freq1"] = "50.00";
doc["Pf1"] = "0.98";
String json;
serializeJson(doc, json);
int code = http.POST(json);
Serial.println(http.getString());
http.end();
}
delay(300000);
}
ESP8266 Arduino Code
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClient.h>
#include <ArduinoJson.h>
const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
const char* SERVER_URL = "http://119.59.96.93/api/v1/post.php";
const char* API_KEY = "iot_rmuti_2024";
WiFiClient wifiClient;
void setup() {
Serial.begin(115200);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }
Serial.println("WiFi Connected!");
}
void loop() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(wifiClient, SERVER_URL);
http.addHeader("Content-Type", "application/json");
StaticJsonDocument<512> doc;
doc["api_key"] = API_KEY;
doc["Room"] = "18207";
doc["Temp1"] = "28.50";
doc["Humi1"] = "70.20";
doc["Volt1"] = "226.30";
String json;
serializeJson(doc, json);
int code = http.POST(json);
Serial.println(http.getString());
http.end();
}
delay(300000);
}
File Locations
| File | Path |
| API Config | C:\xampp\htdocs\api\v1\config.php |
| POST API | C:\xampp\htdocs\api\v1\post.php |
| GET API | C:\xampp\htdocs\api\v1\get.php |
| Dashboard | C:\xampp\htdocs\index.php |
| API Docs | C:\xampp\htdocs\postget.html |
| ESP32 Code | C:\Users\Win10pro\Desktop\ไมโคร\arduino\ESP32_IoT_Sensor\ESP32_IoT_Sensor.ino |
| ESP8266 Code | C:\Users\Win10pro\Desktop\ไมโคร\arduino\ESP8266_IoT_Sensor\ESP8266_IoT_Sensor.ino |