POST JSON - Send power monitoring data using JSON payload
POST /api.php

Required Headers

KeyValue
Content-Typeapplication/json

JSON Body Example

{ "voltage": 251.5, "current": 0.063, "power": 6.6, "energy": 0.006, "frequency": 50.0, "power_factor": 0.42 }

Database Schema

FieldTypeUnitDescription
voltageFLOATVoltsMeasured voltage
currentFLOATAmperesMeasured current
powerFLOATWattsActive power
energyFLOATWatt-hoursCumulative energy
frequencyFLOATHertzLine frequency
power_factorFLOAT0-1Power factor ratio

Arduino ESP32 Code (WiFiClientSecure)

// ESP32 POST JSON to /api.php #include <WiFi.h> #include <WiFiClientSecure.h> #include <HTTPClient.h> const char* WIFI_SSID = "YourWiFi"; const char* WIFI_PASS = "YourPassword"; const char* API_HOST = "192.168.1.100"; void setup() { Serial.begin(115200); WiFi.begin(WIFI_SSID, WIFI_PASS); while (WiFi.status() != WL_CONNECTED) delay(500); Serial.println("WiFi Connected"); } void loop() { if (WiFi.status() == WL_CONNECTED) { WiFiClientSecure client; client.setInsecure(); // skip cert verification HTTPClient http; http.begin(client, "http://" + String(API_HOST) + "/iot-dashboard/api.php"); http.addHeader("Content-Type", "application/json"); float voltage = 251.5; float current = 0.063; float power = voltage * current; float energy = 0.006; float freq = 50.0; float pf = 0.42; String json = "{" "\"voltage\":" + String(voltage,1) + "," "\"current\":" + String(current,3) + "," "\"power\":" + String(power,1) + "," "\"energy\":" + String(energy,3) + "," "\"frequency\":" + String(freq,1) + "," "\"power_factor\":" + String(pf,2) "}"; int code = http.POST(json); Serial.println("HTTP " + String(code)); Serial.println(http.getString()); http.end(); } delay(30000); // send every 30s }
POST Form - Send sensor data using form-urlencoded format
POST /api.php

Required Headers

KeyValue
Content-Typeapplication/x-www-form-urlencoded

Form Fields

Form POST Example
# HTML form action <form method="POST" action="http://localhost/iot-dashboard/api.php"> <input name="voltage" value="251.5" /> <input name="current" value="0.063" /> <input name="power" value="6.6" /> <input name="energy" value="0.006" /> <input name="frequency" value="50.0" /> <input name="power_factor" value="0.42" /> <button type="submit">Submit</button> </form> # JavaScript fetch with form data const data = new URLSearchParams(); data.append('voltage', 251.5); data.append('current', 0.063); data.append('power', 6.6); data.append('energy', 0.006); data.append('frequency', 50.0); data.append('power_factor', 0.42); fetch('/api.php', { method: 'POST', body: data }) .then(r => r.json()) .then(d => console.log(d));
GET - Query power monitoring data from the database
GET /api.php

Available Endpoints

EndpointDescription
/api.php?action=summaryMin/Max/Avg statistics for all fields
/api.php?action=timeseriesTime series data for charts
/api.php?action=dailyDaily aggregated readings
/api.php?action=table&page=1Paginated table data

Try It

GET Query Examples
# Summary statistics (Min/Max/Avg) GET /api.php?action=summary # Time series data GET /api.php?action=timeseries # Daily aggregated data GET /api.php?action=daily # Paginated table GET /api.php?action=table&page=1
curl Examples - Test the API from command line
POST JSON via curl
# POST JSON data to /api.php curl -X POST http://localhost/iot-dashboard/api.php ^ -H "Content-Type: application/json" ^ -d '{"voltage":251.5,"current":0.063,"power":6.6,"energy":0.006,"frequency":50.0,"power_factor":0.42}'
POST Form via curl
# POST form-urlencoded data curl -X POST http://localhost/iot-dashboard/api.php ^ -H "Content-Type: application/x-www-form-urlencoded" ^ -d "voltage=251.5¤t=0.063&power=6.6&energy=0.006&frequency=50.0&power_factor=0.42"
GET Summary
# GET summary statistics (Min/Max/Avg) curl "http://localhost/iot-dashboard/api.php?action=summary"
GET Time Series
# GET time series data curl "http://localhost/iot-dashboard/api.php?action=timeseries"
GET Daily
# GET daily aggregated data curl "http://localhost/iot-dashboard/api.php?action=daily"
GET Table (Paginated)
# GET paginated table data curl "http://localhost/iot-dashboard/api.php?action=table&page=1"
Home