i wanted to sending telegram message only one time after the sensor range was reached . But after my sensor went to deep sleep when it awake up it will detected the same range and sending the same message again and again it was irritated. I have been tried "Bot_lasttime = 0; " But seems not working well . Is there any way to let it will not sending the same message after recover from a deep sleep ?
void loop() {
Serial.println("Wake up Waiting 5 sec for sensor detetcing");
delay(5000);
Serial.print("\tRange: "); //empited
Serial.println(sensor.readRangeSingleMillimeters());
unsigned long currentMillis = millis();
static bool Range_reach = false;
if(sensor.readRangeSingleMillimeters()>80) {
delay(1000);
Serial.println("Checking Empited Condition1");
delay(2000); //delay 1 second for checking propose.
Serial.print("\tRange: ");
Serial.println(sensor.readRangeSingleMillimeters());
Serial.println("Checking Empited Condition2");
delay(2000); //delay 1 second for checking propose.
Serial.print("\tRange: ");
Serial.println(sensor.readRangeSingleMillimeters());
if(!Range_reach) {
{
Serial.println("Reading for sending Empty message");
delay(1000);
Serial.print("\tRange: ");
Serial.println(sensor.readRangeSingleMillimeters());
delay(2000);
if(sensor.readRangeSingleMillimeters()>80){
Serial.println("sent notifcation1 to Telegram");
sendTelegramMessage();
delay(bulk_messages_mtbs);
Bot_lasttime = 0;
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Going to sleep now!");
delay(3000);
esp_deep_sleep_start();
Serial.println("This will never be printed");
Range_reach = false;
}
}
}
}
else if (sensor.readRangeSingleMillimeters()<30) { //Full
delay(1000);
Serial.println("Checking Full Condition1");
delay(2000); //delay 30 second for checking propose.
Serial.print("\tRange: ");
Serial.println(sensor.readRangeSingleMillimeters());
Serial.println("Checking Full Condition2");
delay(2000); //delay 30 second for checking propose.
Serial.print("\tRange: ");
Serial.println(sensor.readRangeSingleMillimeters());
Serial.println("Reading for sending Full message");
delay(1000);
Serial.print("\tRange: ");
Serial.println(sensor.readRangeSingleMillimeters());
delay(2000);
if(Range_reach) {
if(sensor.readRangeSingleMillimeters()<30){
Serial.println("sent notifcation2 to Telegram");
sendTelegramMessage2();
delay(bulk_messages_mtbs);
Bot_lasttime = 0;
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
Range_reach = false;
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Going to sleep now!");
delay(3000);
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
}
}
if(currentMillis - lastTick >= 1000){
countDown--;
displayCountdownToSerial();
lastTick += 1000;
}
}
void displayCountdownToSerial(){
int mins = countDown / 60;
int secs = countDown % 60;
Serial.print(" Time Remain To Sleep = ");
Serial.print(mins);
Serial.print(" : ");
Serial.println(secs);
if(countDown == 0 ){
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
Serial.println("Going to sleep now!");
delay(3000);
esp_deep_sleep_start();
Serial.println("This will never be printed");
}
}