Intelligent Flow Monitoring System with Predictive Analytics
We have developed a comprehensive solution that democratizes access to advanced water monitoring technology by combining:
Affordable hardware: Using ESP32 XIAO, inexpensive flow sensors, and standard components with an approximate cost of 350, 000 pesos per system
A capacitor
A 5V power supply
Resistors
Intelligent backend: Automatic analysis platform that detects anomalous patterns and predicts potential leaks before they become apparent
The Python backend used a database with the following initial schema
The frontend allows for a pleasant understanding of the
##code
#include <WiFi.h>
#include <HTTPClient.h>
// Wi-Fi credentials
const char* ssid = "Hacking";
const char* password = "overpatojito";
// Backend URL
const char* serverUrl = "http://192.168.248.49:8000/flujo";
// Pin del potenciómetro
const int potPin = A0;
float flujoAnterior = -1; // Valor anterior del flujo
const float delta = 10; // Umbral de cambio mínimo (%)
void setup() {
Serial.begin(115200);
delay(1000);
WiFi.begin(ssid, password);
Serial.print("Conectando a WiFi...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConectado a WiFi");
}
void loop() {
// Leer y mapear el valor del potenciómetro
int potValue = analogRead(potPin);
float flujoActual = map(potValue, 0, 4095, 0, 100); // Valor de 0 a 100%
// Comprobar si cambió significativamente
if (abs(flujoActual - flujoAnterior) >= delta) {
flujoAnterior = flujoActual;
Serial.print("Flujo de agua: ");
Serial.println(flujoActual);
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin(serverUrl);
http.addHeader("Content-Type", "application/json");
String jsonPayload = "{\"flujo\":" + String(flujoActual) + "}";
int httpResponseCode = http.POST(jsonPayload);
if (httpResponseCode > 0) {
String response = http.getString();
Serial.println("Respuesta del servidor: " + response);
} else {
Serial.print("Error al enviar datos. Código: ");
Serial.println(httpResponseCode);
}
http.end();
} else {
Serial.println("WiFi desconectado");
}
} else {
Serial.println("Sin cambio en el flujo.");
}
delay(500); // Revisa cada 0.5 segundos
}
Comments
Please log in or sign up to comment.