class FlowSensor { final int id; final double flowRate; final double volume; FlowSensor({required this.id, required this.flowRate, required this.volume}); factory FlowSensor.fromJson(Map json) { return FlowSensor( id: json['sensor_id'], flowRate: json['flow_rate'].toDouble(), volume: json['total_volume'].toDouble(), ); } } ----------------------------------------- query($sql); } echo json_encode(["status" => "success"]); } $conn->close(); ?> -------------------------------------------------- #include #include #include const char* ssid = "YOUR_WIFI_SSID"; const char* password = "YOUR_WIFI_PASSWORD"; const char* serverUrl = "http://your-server-ip/api/upload_flow.php"; const int SENSOR_PINS[] = {32, 33, 25, 26, 27}; volatile long pulseCounts[] = {0, 0, 0, 0, 0}; float calibrationFactor = 7.5; // YF-S201 constant // IRAM_ATTR is required for ESP32 interrupt routines void IRAM_ATTR isr0() { pulseCounts[0]++; } void IRAM_ATTR isr1() { pulseCounts[1]++; } void IRAM_ATTR isr2() { pulseCounts[2]++; } void IRAM_ATTR isr3() { pulseCounts[3]++; } void IRAM_ATTR isr4() { pulseCounts[4]++; } void setup() { Serial.begin(115200); WiFi.begin(ssid, password); void (*isrFuncs[])() = {isr0, isr1, isr2, isr3, isr4}; for (int i = 0; i < 5; i++) { pinMode(SENSOR_PINS[i], INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(SENSOR_PINS[i]), isrFuncs[i], FALLING); } } void loop() { static unsigned long lastMillis = 0; if (millis() - lastMillis > 5000) { // Send data every 5 seconds lastMillis = millis(); StaticJsonDocument<512> doc; JsonArray data = doc.to(); for (int i = 0; i < 5; i++) { float flowRate = (pulseCounts[i] / calibrationFactor); // L/min float totalVolume = pulseCounts[i] / 450.0; // 450 pulses per Liter JsonObject sensor = data.createNestedObject(); sensor["id"] = i + 1; sensor["flow_rate"] = flowRate; sensor["volume"] = totalVolume; } String jsonString; serializeJson(doc, jsonString); if (WiFi.status() == WL_CONNECTED) { HTTPClient http; http.begin(serverUrl); http.addHeader("Content-Type", "application/json"); int httpResponseCode = http.POST(jsonString); http.end(); } } }