//Including the two libraries
#include <UniversalTelegramBot.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
//------- WiFi Settings -------
char ssid[] = ""; // your network SSID (name)
char password[] = ""; // your network key
// ------- Telegram config --------
#define BOT_TOKEN "" // your Bot Token (Get from Botfather)
#define CHAT_ID "-100" // Chat ID of where you want the message to go (You can use MyIdBot to get the chat ID)
const int gasAnalogPin = 32;
long Bot_lasttime;
int bulk_messages_mtbs = 30000; // testing to delay 6sec to detecting another distance and which message been sent .
boolean Flag=false;
// SSL client needed for both libraries
WiFiClientSecure client;
UniversalTelegramBot bot(BOT_TOKEN, client);
String ipAddress = "";
volatile bool telegramButton1PressedFlag = false;
volatile bool telegramButton2PressedFlag = false;
volatile bool telegramButton3PressedFlag = false;
volatile bool telegramButton4PressedFlag = false;
volatile bool telegramButton5PressedFlag = false;
void setup() {
Serial.begin(115200);
pinMode(gasAnalogPin, INPUT);
// Set WiFi to station mode and disconnect from an AP if it was Previously
// connected
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(100);
// Attempt to connect to Wifi network:
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
IPAddress ip = WiFi.localIP();
Serial.println(ip);
ipAddress = ip.toString();
}
void sendTelegramMessage1() {
String message = "Air was fresh @ testing!";
if(bot.sendMessage(CHAT_ID, message, "Markdown")){
Serial.println("TELEGRAM Message 1 Successfully sent");
}
telegramButton1PressedFlag = false;
}
void sendTelegramMessage2() {
String message2 = "Air was good @ testing!";
if(bot.sendMessage(CHAT_ID, message2, "Markdown")){
Serial.println("TELEGRAM Message 1 Successfully sent");
}
telegramButton2PressedFlag = false;
}
void sendTelegramMessage3() {
String message3 = "Air was poor @ testing!";
if(bot.sendMessage(CHAT_ID, message3, "Markdown")){
Serial.println("TELEGRAM Message 1 Successfully sent");
}
telegramButton3PressedFlag = false;
}
void sendTelegramMessage4() {
String message4 = "Air was bad @ testing!";
if(bot.sendMessage(CHAT_ID, message4, "Markdown")){
Serial.println("TELEGRAM Message 1 Successfully sent");
}
telegramButton4PressedFlag = false;
}
void sendTelegramMessage5() {
String message5 = "Air was terrible , emergency evacuation @ testing!";
if(bot.sendMessage(CHAT_ID, message5, "Markdown")){
Serial.println("TELEGRAM Message 1 Successfully sent");
}
telegramButton5PressedFlag = false;
}
void loop() {
float V0 = 750;
float Rs = 0;
float R0 = 0;
float Voltage;
float Vout = 1183;
float ratio = 0;
R0 = ((20000*5000/V0)-40000);
Rs = ((20000*5000/analogRead(gasAnalogPin))-40000);
ratio = Rs/R0; //Replace R0 with the value found using the sketch above
Serial.println(R0);
Serial.println(Rs);
Serial.println(ratio); // How to calculate PPM?
delay(1000);
if (ratio > 0.90){ //Fresh stage 1
sendTelegramMessage1();
delay(bulk_messages_mtbs);
Bot_lasttime = 0;
Flag=true;
}else if (ratio < 0.90 && ratio > 0.70){ //good stage 2
sendTelegramMessage2();
delay(bulk_messages_mtbs);
Bot_lasttime = 0;
Flag=true;
}else if (ratio < 0.70 && ratio > 0.40){ //poor stage 3
sendTelegramMessage3();
delay(bulk_messages_mtbs);
Bot_lasttime = 0;
Flag=true;
}else if (ratio < 0.40 && ratio > 0.10){ //bad stage 4
sendTelegramMessage4();
delay(bulk_messages_mtbs);
Bot_lasttime = 0;
Flag=true;
}else if (ratio <0.10){ //Emergency stage 5
sendTelegramMessage5();
delay(bulk_messages_mtbs);
Bot_lasttime = 0;
Flag=true;
}
}
Above are my complete code , can some one help me ameliorate the bolean flag , the message will keep sending . I'm trying to doing sending message once by following 5 stage from stage 1-5. When it reach any stage only sending message 1 time .