CREATE DATABASE water_monitoring; USE water_monitoring; CREATE TABLE flow_readings ( id INT(11) AUTO_INCREMENT PRIMARY KEY, sensor_id INT(2) NOT NULL, volume_liters FLOAT NOT NULL, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); ------------------------------------------------------- connect_error) die("Connection failed: " . $conn->connect_error); // Get JSON input $json = file_get_contents('php://input'); $data = json_decode($json, true); if (!empty($data)) { foreach ($data as $index => $volume) { $sensor_id = $index + 1; $sql = "INSERT INTO flow_readings (sensor_id, volume_liters) VALUES ($sensor_id, $volume)"; $conn->query($sql); } echo "Data recorded successfully"; } else { echo "No data received"; } $conn->close(); ?> --------------------------------------------------------- #include #include #include // WiFi and Server Config const char* ssid = "YOUR_SSID"; const char* password = "YOUR_PASSWORD"; const char* serverUrl = "http://YOUR_SERVER_IP/post_data.php"; // Sensor Pins const uint8_t flowPins[5] = {32, 33, 25, 26, 27}; volatile long pulseCounts[5] = {0, 0, 0, 0, 0}; // Calibration factor for YF-S201 (pulses per liter) const float calibrationFactor = 450.0; // Interrupt Handlers void IRAM_ATTR pulse0() { pulseCounts[0]++; } void IRAM_ATTR pulse1() { pulseCounts[1]++; } void IRAM_ATTR pulse2() { pulseCounts[2]++; } void IRAM_ATTR pulse3() { pulseCounts[3]++; } void IRAM_ATTR pulse4() { pulseCounts[4]++; } void (*handlers[5])() = {pulse0, pulse1, pulse2, pulse3, pulse4}; void setup() { Serial.begin(115200); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } for(int i=0; i<5; i++) { pinMode(flowPins[i], INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(flowPins[i]), handlers[i], RISING); } } void loop() { static unsigned long lastSend = 0; if (millis() - lastSend > 10000) { // Send every 10 seconds lastSend = millis(); sendData(); } } void sendData() { if (WiFi.status() == WL_CONNECTED) { JsonDocument doc; JsonArray volumes = doc.to(); for (int i = 0; i < 5; i++) { float liters = pulseCounts[i] / calibrationFactor; volumes.add(liters); } String jsonPayload; serializeJson(doc, jsonPayload); HTTPClient http; http.begin(serverUrl); http.addHeader("Content-Type", "application/json"); int httpResponseCode = http.POST(jsonPayload); Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); http.end(); } }