How to send Water threshold Alert via email or telegram [Esp32,Water flow Sensor,thinger.io]

Hello,

I developed a smart IOT system using ESP32 & Thinger.io enables the user to monitor their water consumption ,but I couldn’t setup Water threshold Alert via email or telegram to notify users on their abnormal water consumption.

could you plz help me to settle it down.

Here you can find the project code

#include <ThingerESP32.h>
#define USERNAME " "
#define DEVICE_ID1 " "
#define DEVICE_CREDENTIAL1 " "
#define SSID " " //wifi name
#define SSID_PASSWORD " " //wifi pass
#define SENSOR1 13
#define SENSOR2 12
ThingerESP32 thing(USERNAME, DEVICE_ID1, DEVICE_CREDENTIAL1);

#include <WiFiClientSecure.h>

#define BoTtoken " " //
#define CHAT_ID " " //

long currentMillis1 = 0,currentMillis2 = 0;
long previousMillis1 = 0,previousMillis2 = 0;
int interval1 = 1000,interval2 = 1000;
//boolean ledState = LOW;
float calibrationFactor1 = 7.95,calibrationFactor2 = 7.95; // 477 pulses per liters /60 to convert to min .
volatile byte pulseCount1,pulseCount2;
byte pulse1Sec1 = 0,pulse1Sec2 = 0;
float flowRate1,flowRate2;
float speed1,speed2; //in rpm
float frequency1,frequency2;
float speedvsfreq1,speedvsfreq2;
unsigned int flowMilliLitres1,flowMilliLitres2;
unsigned long totalMilliLitres1,totalMilliLitres2;
float totalLitres1,totalLitres2;
void IRAM_ATTR pulseCounter1()
{
pulseCount1++;

}
void IRAM_ATTR pulseCounter2()
{
pulseCount2++;
}
void setup()
{
Serial.begin(115200);
pinMode(SENSOR1, INPUT_PULLUP);
pinMode(SENSOR2, INPUT_PULLUP);
thing.add_wifi(SSID, SSID_PASSWORD);

pulseCount1 = 0;
flowRate1 = 0.0;
flowMilliLitres1 = 0;
totalMilliLitres1 = 0;
totalLitres1 = 0;
previousMillis1 = 0;

pulseCount2 = 0;
flowRate2 = 0.0;
flowMilliLitres2 = 0;
totalMilliLitres2 = 0;
totalLitres2 = 0;
previousMillis2 = 0;
attachInterrupt(digitalPinToInterrupt(SENSOR1), pulseCounter1, FALLING);
attachInterrupt(digitalPinToInterrupt(SENSOR2), pulseCounter2, FALLING);
}
void loop()
{
currentMillis1 = millis();
if (currentMillis1 - previousMillis1 > interval1)
{
pulse1Sec1 = pulseCount1;
pulseCount1 = 0;
frequency1 =((1000.0 / (millis() - previousMillis1)) * pulse1Sec1); // pulse per sec
speed1 = pulse1Sec1 *60/4; //rev per min
flowRate1 = frequency1 / calibrationFactor1;
speedvsfreq1= speed1/frequency1;
previousMillis1 = millis();
flowMilliLitres1 = (flowRate1 / 60) * 1000;
totalMilliLitres1 += flowMilliLitres1;
totalLitres1=totalMilliLitres1/1000.0;
// Print the flow rate for this second in litres / minute
Serial.print(“1: Flow rate: “);
Serial.print(int(flowRate1)); // Print the integer part of the variable
Serial.print(“L/min”);
Serial.print(”\t”); // Print tab space
// Print the cumulative total of litres flowed since starting
Serial.print("Output Liquid Quantity: ");
Serial.print(totalMilliLitres1);
Serial.print("mL / ");
Serial.print(totalLitres1);
Serial.println(“L”);
thing[“data 1”] >> (pson& out){
out[“Flow Rate”] = flowRate1;
out[“frequency”] = frequency1;
out[“Speedvsfreq”] = speedvsfreq1;
out[“Speed”] = speed1;
out[“Total”] = totalMilliLitres1;
out[“Total in L”]= totalLitres1;
};
thing.handle();
thing.stream(thing[“data 1”]);
}

currentMillis2 = millis();

if (currentMillis2 - previousMillis2 > interval2)
{
pulse1Sec2 = pulseCount2;
pulseCount2 = 0;
frequency2 =((1000.0 / (millis() - previousMillis2)) * pulse1Sec2); // pulse per sec
speed2 = pulse1Sec2 *60/4; //rev per min
flowRate2 = frequency2 / calibrationFactor2;
speedvsfreq2= speed2/frequency2;
previousMillis2 = millis();
flowMilliLitres2 = (flowRate2 / 60) * 1000;
totalMilliLitres2 += flowMilliLitres2;
totalLitres2=totalMilliLitres2/1000.0;
// Print the flow rate for this second in litres / minute
Serial.print(“2: Flow rate: “);
Serial.print(int(flowRate2)); // Print the integer part of the variable
Serial.print(“L/min”);
Serial.print(”\t”); // Print tab space
// Print the cumulative total of litres flowed since starting
Serial.print("Output Liquid Quantity: ");
Serial.print(totalMilliLitres2);
Serial.print("mL / ");
Serial.print(totalLitres2);
Serial.println(“L”);
thing[“data 2”] >> (pson& out){
out[“Flow Rate”] = flowRate2;
out[“frequency”] = frequency2;
out[“Speedvsfreq”] = speedvsfreq2;
out[“Speed”] = speed2;
out[“Total”] = totalMilliLitres2;
out[“Total in L”]= totalLitres2;
};
thing.handle();
thing.stream(thing[“data 2”]);
}
}

Hi,

I think it could be useful for you to apply endpoints, check the documentation → ENDPOINTS - Thinger.io Documentation

You need to establish an strategy to detect the condition that you want to trigger the notification send, once you get it, check how to call an endpoint → CODING GUIDE - Thinger.io Documentation

Hope this helps.