#include <RCSwitch.h>
#include "CTBot.h"
CTBot myBot;
RCSwitch mySwitch = RCSwitch();
// wifi and telegram var
String ssid = "Wokwi-GUEST"; // REPLACE mySSID WITH YOUR WIFI SSID
String pass = ""; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
//String ssid = "Tenda_8D1778" ; // REPLACE mySSID WITH YOUR WIFI SSID
//String pass = "ironmanapesta"; // REPLACE myPassword YOUR WIFI PASSWORD, IF ANY
String token = "7385807503:AAECFO_S5u7g0adjYWERtVXrXb8rGU7sCRs" ; // REPLACE myToken WITH YOUR TELEGRAM BOT TOKEN
// pins of ESP32-01
int Pin1 = 0; // GPIO0 of ESP-01
int Pin2 = 1; // GPIO1 of ESP-01 (TX)
int Pin3 = 2; // GPIO2 of ESP-01
int Pin4 = 3; // GPIO3 of ESP-01 (RX)
#define LED 2 // variables del rele 1 para esp01, 2 para esp01s
#define RF_REC_PIN 0 // D1=GPIO0
int rfValue = 0; // codigo RF recibido
int alarmMode = 1; //0=off, 1=on, 2=monitor sensors
String text = ""; //texto de los mensajes
void blink_LED(){
digitalWrite(LED, LOW); //enciende 400
delay(400);
digitalWrite(LED, HIGH);
delay(400);
digitalWrite(LED, LOW); //enciende 1000
delay(1000);
digitalWrite(LED, HIGH);
}
void reciveRF() {
if (mySwitch.available()) {
rfValue = mySwitch.getReceivedValue();
Serial.println(String(rfValue));
mySwitch.resetAvailable();
text = "ERROR";
switch (rfValue){ // ver que detector se activo
case 2384329: text = "SENSOR PUERTA FRENTE"; break;
case 2040393: text = "SENSOR PUERTA PATIO"; break;
case 12535129: text = "SENSOR PUERTA GALPONCITO"; break;
case 980009: text = "SENSOR VENTANA FRENTE"; break;
case 787193: text = "SENSOR VENTANA DORMITORIO"; break;
case 2480937: text = "SENSOR VENTANA MAXI"; break;
case 900665: text = "SENSOR VENTANA PAULA"; break;
case 13705700: text = "Control black OFF"; break;
case 13705704: text = "Control black ON"; break;
case 4885732: text = "Control white OFF"; break;
case 4885736: text = "Control white ON"; break;
}
mensaje(text);
blink_LED();
}
}
void mensaje(String texto){
myBot.sendMessage(5333228648, texto);
Serial.println(texto);
}
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
blink_LED();
mySwitch.enableReceive(RF_REC_PIN);
myBot.wifiConnect(ssid, pass);
myBot.setTelegramToken(token);
mensaje("ALARMA INICIADA");
}
void loop() {
reciveRF();
}