ESP32 + Firebase
Posted: Sun Oct 27, 2019 5:53 pm
Hello, I made a program to read a String of firebase and active 16relays, it runs well, but around 10 minutes, even with the watchdog, my esp, stops and the blue LED it's ON, but dont receive any command. And I have to reset it by pressing the reset button. Please help.
#include <WiFi.h>
#include <IOXhop_FirebaseESP32.h>
#define FIREBASE_HOST "8888888/" //URL DO FIREBASE
#define FIREBASE_AUTH "8888888" //SEGREDO DO FIREBASE
#define WIFI_SSID "8888888" //NOME DA WIFI
#define WIFI_PASSWORD "8888888" //SENHA DO WIFI
hw_timer_t *timer = NULL; //faz o controle do temporizador (interrupção por tempo)
//função que o temporizador irá chamar, para reiniciar o ESP32
void IRAM_ATTR resetModule(){
ets_printf("(watchdog) reiniciar\n"); //imprime no log
ESP.restart(); //reinicia o chip
}
char comando;
//faz o controle do temporizador (interrupção por tempo)
#define pin01 23 // D23
#define pin02 22 // D22
#define pin03 21 // D21
#define pin04 19 // D19
#define pin05 18 // D18
#define pin06 5 // D5
#define pin07 4 // D4
#define pin08 2 // D2
#define pin09 15 // D15
#define pin10 16 // D10 34
#define pin11 17 // D11 35
#define pin12 32 // D32
#define pin13 33 // D33
#define pin14 25 // D25
#define pin15 26 // D26
#define pin16 14 // D14
int deg1,deg2,deg3,deg4,deg5,deg6,deg7,deg8,deg9,deg10,deg11,deg12,deg13,deg14,deg15,deg16,degall,portao = 0,alarme = 0;
String fireStatus = "20";
String fireStatus2 = "";
String fireStatus3 = "";
String fireStatus4 = "";
String fireStatus5 = "";
String fireStatus6 = "";
String fireStatus7 = "";
String fireStatus8 = "";
String fireStatus9 = "";
String fireStatus10 = "";
String fireStatus11 = "";
String fireStatus12 = "";
String fireStatus13 = "";
String fireStatus14 = "";
String fireStatus15 = "";
String fireStatus16 = "";
void setup()
{
timer = timerBegin(0, 80, true); //timerID 0, div 80
//timer, callback, interrupção de borda
timerAttachInterrupt(timer, &resetModule, true);
//timer, tempo (us), repetição
timerAlarmWrite(timer, 3000000, true);
timerAlarmEnable(timer); //habilita a interrupção
pinMode(pin01,OUTPUT);
pinMode(pin02,OUTPUT);
pinMode(pin03,OUTPUT);
pinMode(pin04,OUTPUT);
pinMode(pin05,OUTPUT);
pinMode(pin06,OUTPUT);
pinMode(pin07,OUTPUT);
pinMode(pin08,OUTPUT);
pinMode(pin09,OUTPUT);
pinMode(pin10,OUTPUT);
pinMode(pin11,OUTPUT);
pinMode(pin12,OUTPUT);
pinMode(pin13,OUTPUT);
pinMode(pin14,OUTPUT);
pinMode(pin15,OUTPUT);
pinMode(pin16,OUTPUT);
digitalWrite(pin01,HIGH);
digitalWrite(pin02,HIGH);
digitalWrite(pin03,HIGH);
digitalWrite(pin04,HIGH);
digitalWrite(pin05,HIGH);
digitalWrite(pin06,HIGH);
digitalWrite(pin07,HIGH);
digitalWrite(pin08,HIGH);
digitalWrite(pin09,HIGH);
digitalWrite(pin10,HIGH);
digitalWrite(pin11,HIGH);
digitalWrite(pin12,HIGH);
digitalWrite(pin13,HIGH);
digitalWrite(pin14,HIGH);
digitalWrite(pin15,HIGH);
digitalWrite(pin16,HIGH);
Serial.begin(115200);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
// digitalWrite(LED_BUILTIN,LOW); //Wifi ye bağlandığında blue led yanacaktır.
Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH); //Firebase database url ve key kontrol edilerek bağlanıyor.
// Firebase.setInt("rele1",0);
// Firebase.setInt("rele2",0);
// Firebase.setInt("rele3",0);
// Firebase.setInt("rele4",0);
}
void firebasereconnect(){
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop(){
timerWrite(timer, 0); //reseta o temporizador (alimenta o watchdog)
long tme = millis(); //tempo inicial do loop
//reseta o temporizador (alimenta o watchdog)
if (Firebase.failed())
{
Serial.print("setting number failed:");
Serial.println(Firebase.error());
firebasereconnect();
return;
}
fireStatus = Firebase.getString("status");
char aux0 = fireStatus[0];
char aux1 = fireStatus[1];
char aux2 = fireStatus[2];
char aux3 = fireStatus[3];
char aux4 = fireStatus[4];
char aux5 = fireStatus[5];
char aux6 = fireStatus[6];
char aux7 = fireStatus[7];
char aux8 = fireStatus[8];
char aux9 = fireStatus[9];
char aux10 = fireStatus[10];
char aux11 = fireStatus[11];
char aux12 = fireStatus[12];
char aux13 = fireStatus[13];
char aux14 = fireStatus[14];
char aux15 = fireStatus[15];
char aux16 = fireStatus[16];
char aux17 = fireStatus[17];
char aux18 = fireStatus[18];
if (aux2 == '1' && portao == 0) { // compare the input of led status received from firebase
digitalWrite(pin15, LOW); // make output led ON
delay(500);
digitalWrite(pin15, HIGH);
portao = 1;
}
if (aux2 == '0' && portao == 1) { // compare the input of led status received from firebase
digitalWrite(pin01, HIGH); // make output led OFF
portao = 0;
}
if (aux3 == '1') { // compare the input of led status received from firebase
digitalWrite(pin02, LOW); // make output led ON
}
if (aux3 == '0') { // compare the input of led status received from firebase
digitalWrite(pin02, HIGH); // make output led OFF
}
if (aux4 == '1') { // compare the input of led status received from firebase
digitalWrite(pin03, LOW); // make output led ON
}
if (aux4 == '0') { // compare the input of led status received from firebase
digitalWrite(pin03, HIGH); // make output led OFF
}
if (aux5 == '1') { // compare the input of led status received from firebase
digitalWrite(pin04, LOW); // make output led ON
}
else if (aux5 == '0') { // compare the input of led status received from firebase
digitalWrite(pin04, HIGH); // make output led OFF
}
if (aux6 == '1') { // compare the input of led status received from firebase
digitalWrite(pin05, LOW); // make output led ON
}
else if (aux6 == '0') { // compare the input of led status received from firebase
digitalWrite(pin05, HIGH); // make output led OFF
}
if (aux7 == '1') { // compare the input of led status received from firebase
digitalWrite(pin06, LOW); // make output led ON
}
else if (aux7 == '0') { // compare the input of led status received from firebase
digitalWrite(pin06, HIGH); // make output led OFF
}
if (aux8 == '1') { // compare the input of led status received from firebase
digitalWrite(pin07, LOW); // make output led ON
}
else if (aux8 == '0') { // compare the input of led status received from firebase
digitalWrite(pin07, HIGH); // make output led OFF
}
if (aux9 == '1') { // compare the input of led status received from firebase
digitalWrite(pin08, LOW); // make output led ON
}
else if (aux9 == '0') { // compare the input of led status received from firebase
digitalWrite(pin08, HIGH); // make output led OFF
}
if (aux10 == '1') { // compare the input of led status received from firebase
digitalWrite(pin01, LOW); // make output led ON
}
else if (aux10 == '0') { // compare the input of led status received from firebase
digitalWrite(pin01, HIGH); // make output led OFF
}
if (aux11 == '1') { // compare the input of led status received from firebase
digitalWrite(pin10, LOW); // make output led ON
}
else if (aux11 == '0') { // compare the input of led status received from firebase
digitalWrite(pin10, HIGH); // make output led OFF
}
if (aux12 == '1') { // compare the input of led status received from firebase
digitalWrite(pin11, LOW); // make output led ON
}
else if (aux12 == '0') { // compare the input of led status received from firebase
digitalWrite(pin11, HIGH); // make output led OFF
}
if (aux13 == '1') { // compare the input of led status received from firebase
digitalWrite(pin12, LOW); // make output led ON
}
else if (aux13 == '0') { // compare the input of led status received from firebase
digitalWrite(pin12, HIGH); // make output led OFF
}
if (aux14 == '1') { // compare the input of led status received from firebase
digitalWrite(pin13, LOW); // make output led ON
}
else if (aux14 == '0') { // compare the input of led status received from firebase
digitalWrite(pin13, HIGH); // make output led OFF
}
if (aux15 == '1') { // compare the input of led status received from firebase
digitalWrite(pin14, LOW);// make output led ON
}
else if (aux15 == '0') { // compare the input of led status received from firebase
digitalWrite(pin14, HIGH); // make output led OFF
}
if (aux16 == '1') { // compare the input of led status received from firebase
digitalWrite(pin15, LOW);// make output led ON
// make output led ON
}
else if (aux16 == '0') { // compare the input of led status received from firebase
digitalWrite(pin15, HIGH);
}
if (aux17 == '1') { // compare the input of led status received from firebase
digitalWrite(pin16, LOW); // make output led ON
}
else if (aux17 == '0') { // compare the input of led status received from firebase
digitalWrite(pin16, HIGH); // make output led OFF
}
if (aux18 == '1') { // compare the input of led status received from firebase
digitalWrite(pin01, LOW);
digitalWrite(pin02, LOW);
digitalWrite(pin03, LOW);
digitalWrite(pin04, LOW);
digitalWrite(pin05, LOW);
digitalWrite(pin06, LOW);
digitalWrite(pin07, LOW);
digitalWrite(pin08, LOW);
digitalWrite(pin09, LOW);
digitalWrite(pin10, LOW);
digitalWrite(pin11, LOW);
digitalWrite(pin12, LOW);
digitalWrite(pin13, LOW);
digitalWrite(pin14, LOW);
//digitalWrite(pin15, LOW);
//digitalWrite(pin16, LOW);
}
else if (aux18 == '0') { // compare the input of led status received from firebase
digitalWrite(pin01, HIGH);
digitalWrite(pin02, HIGH);
digitalWrite(pin03, HIGH);
digitalWrite(pin04, HIGH);
digitalWrite(pin05, HIGH);
digitalWrite(pin06, HIGH);
digitalWrite(pin07, HIGH);
digitalWrite(pin08, HIGH);
digitalWrite(pin09, HIGH);
digitalWrite(pin10, HIGH);
digitalWrite(pin11, HIGH);
digitalWrite(pin12, HIGH);
digitalWrite(pin13, HIGH);
digitalWrite(pin14, HIGH);
//digitalWrite(pin15, HIGH);
//digitalWrite(pin16, HIGH);
// make output led OFF
}
}
//fim
#include <WiFi.h>
#include <IOXhop_FirebaseESP32.h>
#define FIREBASE_HOST "8888888/" //URL DO FIREBASE
#define FIREBASE_AUTH "8888888" //SEGREDO DO FIREBASE
#define WIFI_SSID "8888888" //NOME DA WIFI
#define WIFI_PASSWORD "8888888" //SENHA DO WIFI
hw_timer_t *timer = NULL; //faz o controle do temporizador (interrupção por tempo)
//função que o temporizador irá chamar, para reiniciar o ESP32
void IRAM_ATTR resetModule(){
ets_printf("(watchdog) reiniciar\n"); //imprime no log
ESP.restart(); //reinicia o chip
}
char comando;
//faz o controle do temporizador (interrupção por tempo)
#define pin01 23 // D23
#define pin02 22 // D22
#define pin03 21 // D21
#define pin04 19 // D19
#define pin05 18 // D18
#define pin06 5 // D5
#define pin07 4 // D4
#define pin08 2 // D2
#define pin09 15 // D15
#define pin10 16 // D10 34
#define pin11 17 // D11 35
#define pin12 32 // D32
#define pin13 33 // D33
#define pin14 25 // D25
#define pin15 26 // D26
#define pin16 14 // D14
int deg1,deg2,deg3,deg4,deg5,deg6,deg7,deg8,deg9,deg10,deg11,deg12,deg13,deg14,deg15,deg16,degall,portao = 0,alarme = 0;
String fireStatus = "20";
String fireStatus2 = "";
String fireStatus3 = "";
String fireStatus4 = "";
String fireStatus5 = "";
String fireStatus6 = "";
String fireStatus7 = "";
String fireStatus8 = "";
String fireStatus9 = "";
String fireStatus10 = "";
String fireStatus11 = "";
String fireStatus12 = "";
String fireStatus13 = "";
String fireStatus14 = "";
String fireStatus15 = "";
String fireStatus16 = "";
void setup()
{
timer = timerBegin(0, 80, true); //timerID 0, div 80
//timer, callback, interrupção de borda
timerAttachInterrupt(timer, &resetModule, true);
//timer, tempo (us), repetição
timerAlarmWrite(timer, 3000000, true);
timerAlarmEnable(timer); //habilita a interrupção
pinMode(pin01,OUTPUT);
pinMode(pin02,OUTPUT);
pinMode(pin03,OUTPUT);
pinMode(pin04,OUTPUT);
pinMode(pin05,OUTPUT);
pinMode(pin06,OUTPUT);
pinMode(pin07,OUTPUT);
pinMode(pin08,OUTPUT);
pinMode(pin09,OUTPUT);
pinMode(pin10,OUTPUT);
pinMode(pin11,OUTPUT);
pinMode(pin12,OUTPUT);
pinMode(pin13,OUTPUT);
pinMode(pin14,OUTPUT);
pinMode(pin15,OUTPUT);
pinMode(pin16,OUTPUT);
digitalWrite(pin01,HIGH);
digitalWrite(pin02,HIGH);
digitalWrite(pin03,HIGH);
digitalWrite(pin04,HIGH);
digitalWrite(pin05,HIGH);
digitalWrite(pin06,HIGH);
digitalWrite(pin07,HIGH);
digitalWrite(pin08,HIGH);
digitalWrite(pin09,HIGH);
digitalWrite(pin10,HIGH);
digitalWrite(pin11,HIGH);
digitalWrite(pin12,HIGH);
digitalWrite(pin13,HIGH);
digitalWrite(pin14,HIGH);
digitalWrite(pin15,HIGH);
digitalWrite(pin16,HIGH);
Serial.begin(115200);
// connect to wifi.
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print("connecting");
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println();
Serial.print("connected: ");
Serial.println(WiFi.localIP());
// digitalWrite(LED_BUILTIN,LOW); //Wifi ye bağlandığında blue led yanacaktır.
Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH); //Firebase database url ve key kontrol edilerek bağlanıyor.
// Firebase.setInt("rele1",0);
// Firebase.setInt("rele2",0);
// Firebase.setInt("rele3",0);
// Firebase.setInt("rele4",0);
}
void firebasereconnect(){
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}
void loop(){
timerWrite(timer, 0); //reseta o temporizador (alimenta o watchdog)
long tme = millis(); //tempo inicial do loop
//reseta o temporizador (alimenta o watchdog)
if (Firebase.failed())
{
Serial.print("setting number failed:");
Serial.println(Firebase.error());
firebasereconnect();
return;
}
fireStatus = Firebase.getString("status");
char aux0 = fireStatus[0];
char aux1 = fireStatus[1];
char aux2 = fireStatus[2];
char aux3 = fireStatus[3];
char aux4 = fireStatus[4];
char aux5 = fireStatus[5];
char aux6 = fireStatus[6];
char aux7 = fireStatus[7];
char aux8 = fireStatus[8];
char aux9 = fireStatus[9];
char aux10 = fireStatus[10];
char aux11 = fireStatus[11];
char aux12 = fireStatus[12];
char aux13 = fireStatus[13];
char aux14 = fireStatus[14];
char aux15 = fireStatus[15];
char aux16 = fireStatus[16];
char aux17 = fireStatus[17];
char aux18 = fireStatus[18];
if (aux2 == '1' && portao == 0) { // compare the input of led status received from firebase
digitalWrite(pin15, LOW); // make output led ON
delay(500);
digitalWrite(pin15, HIGH);
portao = 1;
}
if (aux2 == '0' && portao == 1) { // compare the input of led status received from firebase
digitalWrite(pin01, HIGH); // make output led OFF
portao = 0;
}
if (aux3 == '1') { // compare the input of led status received from firebase
digitalWrite(pin02, LOW); // make output led ON
}
if (aux3 == '0') { // compare the input of led status received from firebase
digitalWrite(pin02, HIGH); // make output led OFF
}
if (aux4 == '1') { // compare the input of led status received from firebase
digitalWrite(pin03, LOW); // make output led ON
}
if (aux4 == '0') { // compare the input of led status received from firebase
digitalWrite(pin03, HIGH); // make output led OFF
}
if (aux5 == '1') { // compare the input of led status received from firebase
digitalWrite(pin04, LOW); // make output led ON
}
else if (aux5 == '0') { // compare the input of led status received from firebase
digitalWrite(pin04, HIGH); // make output led OFF
}
if (aux6 == '1') { // compare the input of led status received from firebase
digitalWrite(pin05, LOW); // make output led ON
}
else if (aux6 == '0') { // compare the input of led status received from firebase
digitalWrite(pin05, HIGH); // make output led OFF
}
if (aux7 == '1') { // compare the input of led status received from firebase
digitalWrite(pin06, LOW); // make output led ON
}
else if (aux7 == '0') { // compare the input of led status received from firebase
digitalWrite(pin06, HIGH); // make output led OFF
}
if (aux8 == '1') { // compare the input of led status received from firebase
digitalWrite(pin07, LOW); // make output led ON
}
else if (aux8 == '0') { // compare the input of led status received from firebase
digitalWrite(pin07, HIGH); // make output led OFF
}
if (aux9 == '1') { // compare the input of led status received from firebase
digitalWrite(pin08, LOW); // make output led ON
}
else if (aux9 == '0') { // compare the input of led status received from firebase
digitalWrite(pin08, HIGH); // make output led OFF
}
if (aux10 == '1') { // compare the input of led status received from firebase
digitalWrite(pin01, LOW); // make output led ON
}
else if (aux10 == '0') { // compare the input of led status received from firebase
digitalWrite(pin01, HIGH); // make output led OFF
}
if (aux11 == '1') { // compare the input of led status received from firebase
digitalWrite(pin10, LOW); // make output led ON
}
else if (aux11 == '0') { // compare the input of led status received from firebase
digitalWrite(pin10, HIGH); // make output led OFF
}
if (aux12 == '1') { // compare the input of led status received from firebase
digitalWrite(pin11, LOW); // make output led ON
}
else if (aux12 == '0') { // compare the input of led status received from firebase
digitalWrite(pin11, HIGH); // make output led OFF
}
if (aux13 == '1') { // compare the input of led status received from firebase
digitalWrite(pin12, LOW); // make output led ON
}
else if (aux13 == '0') { // compare the input of led status received from firebase
digitalWrite(pin12, HIGH); // make output led OFF
}
if (aux14 == '1') { // compare the input of led status received from firebase
digitalWrite(pin13, LOW); // make output led ON
}
else if (aux14 == '0') { // compare the input of led status received from firebase
digitalWrite(pin13, HIGH); // make output led OFF
}
if (aux15 == '1') { // compare the input of led status received from firebase
digitalWrite(pin14, LOW);// make output led ON
}
else if (aux15 == '0') { // compare the input of led status received from firebase
digitalWrite(pin14, HIGH); // make output led OFF
}
if (aux16 == '1') { // compare the input of led status received from firebase
digitalWrite(pin15, LOW);// make output led ON
// make output led ON
}
else if (aux16 == '0') { // compare the input of led status received from firebase
digitalWrite(pin15, HIGH);
}
if (aux17 == '1') { // compare the input of led status received from firebase
digitalWrite(pin16, LOW); // make output led ON
}
else if (aux17 == '0') { // compare the input of led status received from firebase
digitalWrite(pin16, HIGH); // make output led OFF
}
if (aux18 == '1') { // compare the input of led status received from firebase
digitalWrite(pin01, LOW);
digitalWrite(pin02, LOW);
digitalWrite(pin03, LOW);
digitalWrite(pin04, LOW);
digitalWrite(pin05, LOW);
digitalWrite(pin06, LOW);
digitalWrite(pin07, LOW);
digitalWrite(pin08, LOW);
digitalWrite(pin09, LOW);
digitalWrite(pin10, LOW);
digitalWrite(pin11, LOW);
digitalWrite(pin12, LOW);
digitalWrite(pin13, LOW);
digitalWrite(pin14, LOW);
//digitalWrite(pin15, LOW);
//digitalWrite(pin16, LOW);
}
else if (aux18 == '0') { // compare the input of led status received from firebase
digitalWrite(pin01, HIGH);
digitalWrite(pin02, HIGH);
digitalWrite(pin03, HIGH);
digitalWrite(pin04, HIGH);
digitalWrite(pin05, HIGH);
digitalWrite(pin06, HIGH);
digitalWrite(pin07, HIGH);
digitalWrite(pin08, HIGH);
digitalWrite(pin09, HIGH);
digitalWrite(pin10, HIGH);
digitalWrite(pin11, HIGH);
digitalWrite(pin12, HIGH);
digitalWrite(pin13, HIGH);
digitalWrite(pin14, HIGH);
//digitalWrite(pin15, HIGH);
//digitalWrite(pin16, HIGH);
// make output led OFF
}
}
//fim