-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirebotalarm.ino
56 lines (44 loc) · 1.42 KB
/
firebotalarm.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>
// Replace with your network credentials
const char* ssid = "Legend 2.4";
const char* password = "Png@7870";
// Initialize Telegram BOT
#define BOTtoken "6090424763:AAG0mAmUBXJeZxAEvanInvgRPNYajE4xMXQ" // your Bot Token (Get from Botfather)
#define CHAT_ID "1429956409" // get from ID Bot
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
const int flamesensor = 3;
bool flameDetected = false;
void IRAM_ATTR detectsFlame() {
//Serial.println("Fire Alert!!!");
flameDetected = true;
}
void setup() {
Serial.begin(115200);
pinMode(flamesensor, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(flamesensor), detectsFlame, RISING);
Serial.print("Connecting Wifi: ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
client.setCACert(TELEGRAM_CERTIFICATE_ROOT);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
bot.sendMessage(CHAT_ID, "Device Activated and iniciating the process.", "");
}
void loop() {
if(flameDetected){
bot.sendMessage(CHAT_ID, "Fire Alert!!!", "");
Serial.println("Fire Alert!!!");
flameDetected = false;
}
}