IoT Dashboard เป็นระบบประมวลผลและแสดงผลข้อมูลจากอุปกรณ์ IoT ที่เชื่อมต่อผ่าน REST API ออกแบบมาสำหรับบันทึกและวิเคราะห์ข้อมูลไฟฟ้าจาก PZEM004T ที่เชื่อมต่อกับ ESP32 วัดค่า แรงดัน, กระแส, กำลัง, พลังงาน, ความถี่, และ Power Factor
IoT Dashboard ให้บริการ REST API สำหรับรับส่งข้อมูลระหว่างอุปกรณ์ IoT และเซิร์ฟเวอร์
| รายการ | ค่า |
|---|---|
| API Endpoint | http://localhost/iot-dashboard/api.php |
| Database | power_monitor |
| Table | sensor_readings |
| API Key | eeiot2024 |
| Method (ส่งข้อมูล) | POST |
| Method (ดึงข้อมูล) | GET |
| Content-Type | application/json หรือ application/x-www-form-urlencoded |
| ชื่อ | ประเภท | จำเป็น | คำอธิบาย |
|---|---|---|---|
voltage | float | ใช่ | แรงดันไฟฟ้า (V) |
current | float | ใช่ | กระแสไฟฟ้า (A) |
power | float | ใช่ | กำลังไฟฟ้า (W) |
energy | float | ไม่ | พลังงานไฟฟ้า (Wh) |
frequency | float | ไม่ | ความถี่ไฟฟ้า (Hz) |
power_factor | float | ไม่ | Power Factor (0-1) |
curl -X POST http://localhost/iot-dashboard/api.php \
-H "Content-Type: application/json" \
-H "X-API-Key: eeiot2024" \
-d '{"voltage":251.5,"current":0.063,"power":6.6,"energy":0.006,"frequency":50.0,"power_factor":0.42}'
curl -X POST http://localhost/iot-dashboard/api.php \ -H "X-API-Key: eeiot2024" \ -d "voltage=251.5¤t=0.063&power=6.6&energy=0.006&frequency=50.0&power_factor=0.42"
eeiot2024 ใน Header ของทุกคำขอ
หน้า Dashboard แสดงข้อมูลสรุปและกราฟแบบ Real-time จากอุปกรณ์ IoT ทั้งหมดที่เชื่อมต่ออยู่
แถบเมนูด้านซ้ายใช้สำหรับนำทางระหว่างหน้าต่างๆ ของระบบ คลิกที่ไอคอนเพื่อเปิดหน้าที่ต้องการ
ใช้ปุ่มกรองด้านบนกราฟเพื่อเลือกช่วงเวลาที่ต้องการ:
| ปุ่ม | คำอธิบาย |
|---|---|
Today | แสดงข้อมูลของวันนี้ |
Yesterday | แสดงข้อมูลของเมื่อวาน |
7D | แสดงข้อมูล 7 วันย้อนหลัง |
30D | แสดงข้อมูล 30 วันย้อนหลัง |
All | แสดงข้อมูลทั้งหมด |
คลิกปุ่ม PDF หรือ Excel เพื่อดาวน์โหลดข้อมูลในรูปแบบที่ต้องการ
คลิกไอคอน บนกราฟเพื่อขยายเต็มจอสำหรับการนำเสนอ
ข้อมูลไฟฟ้าที่ระบบรองรับจาก PZEM004T แสดงผลเป็นตารางและกราฟแบบ Real-time
| ชื่อเซ็นเซอร์ | ค่า | หน่วย | คำอธิบาย |
|---|---|---|---|
voltage | 251.5 | V | แรงดันไฟฟ้า |
current | 0.063 | A | กระแสไฟฟ้า |
power | 6.6 | W | กำลังไฟฟ้า |
energy | 0.006 | Wh | พลังงานไฟฟ้า (สะสม) |
frequency | 50.0 | Hz | ความถี่ไฟฟ้า |
power_factor | 0.42 | - | Power Factor |
ขั้นตอนการตั้งค่า ESP32 หรือ ESP8266 เพื่อส่งข้อมูลไปยัง IoT Dashboard
arduino/esp32/ หรือ arduino/esp8266/
// WiFi Configuration const char* WIFI_SSID = "YourWiFiName"; const char* WIFI_PASS = "YourWiFiPassword"; // API Configuration const char* API_HOST = "http://your-server/iot-dashboard/api.php"; const char* API_KEY = "eeiot2024";
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
void sendData(float voltage, float current, float power, float energy, float frequency, float pf) {
HTTPClient http;
http.begin(API_HOST);
http.addHeader("Content-Type", "application/json");
http.addHeader("X-API-Key", API_KEY);
StaticJsonDocument<200> doc;
doc["voltage"] = voltage;
doc["current"] = current;
doc["power"] = power;
doc["energy"] = energy;
doc["frequency"] = frequency;
doc["power_factor"] = pf;
String requestBody;
serializeJson(doc, requestBody);
int httpResponseCode = http.POST(requestBody);
if (httpResponseCode > 0) {
Serial.println("Data sent successfully");
} else {
Serial.println("Error sending data");
}
http.end();
}
ปัญหาที่พบบ่อยและวิธีการแก้ไข
| ปัญหา | สาเหตุ | วิธีแก้ไข |
|---|---|---|
Connection refused |
Apache ไม่ได้ทำงาน | เปิด XAMPP Control Panel แล้วคลิก Start ที่ Apache |
Access denied |
API Key ไม่ถูกต้อง | ตรวจสอบ API Key eeiot2024 ใน Header ของคำขอ |
CORS error |
ไฟล์ config ไม่ถูกต้อง | ตรวจสอบการตั้งค่าในไฟล์ config.php |
ไม่มีข้อมูลแสดงผล |
ชื่อตารางไม่ถูกต้อง | ตรวจสอบชื่อตารางใน config ว่าตรงกับฐานข้อมูลจริง |
ESP32 ไม่ส่งข้อมูล |
WiFi ไม่เชื่อมต่อ | ตรวจสอบ SSID และ Password ที่ถูกต้อง |
ทดสอบว่า API ทำงานโดยใช้คำสั่ง:
curl "http://localhost/iot-dashboard/api.php?action=ping" -H "X-API-Key: eeiot2024"
ผลลัพธ์ที่ถูกต้องควรมี "status":"ok" หรือ "message":"pong"
ไฟล์ log ของระบบอยู่ที่ logs/ โฟลเดอร์ ตรวจสอบไฟล์ error.log หากมีปัญหา