DFDGDGF

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

#include <WiFi.

h>
#include <WebServer.h>
#include <AutoConnect.h>
#include <FirebaseESP32.h>

#define FIREBASE_HOST "kranzzic.firebaseio.com"


#define FIREBASE_AUTH "Vr4bQQ7B4gKyomMJ1zXKN4rUUAI67882Z3vPEPU0"
#define uS_TO_S_FACTOR 1000000 /* Conversion factor for micro seconds to seconds
*/
#define TIME_TO_SLEEP 2

RTC_DATA_ATTR int bootCount = 0;

FirebaseData firebaseData;

WebServer Server;
AutoConnect Portal(Server);

void printJsonObjectContent(FirebaseData &data);

void rootPage(){
char content[] = "CONECTADO";
Server.send(200, "text/plain", content);
}

void setup() {
Serial.begin(115200);
delay(1000);
Serial.println();
pinMode(2,OUTPUT);
pinMode(26,OUTPUT);
for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}
Server.on("/", rootPage);
Portal.begin();
Serial.println("Web server started:" + WiFi.localIP().toString());
Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
}

void print_wakeup_reason(){
esp_sleep_wakeup_cause_t wakeup_reason;

wakeup_reason = esp_sleep_get_wakeup_cause();

switch(wakeup_reason)
{
case ESP_SLEEP_WAKEUP_EXT0 : Serial.println("Wakeup caused by external signal
using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1 : Serial.println("Wakeup caused by external signal
using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER : Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD : Serial.println("Wakeup caused by touchpad");
break;
case ESP_SLEEP_WAKEUP_ULP : Serial.println("Wakeup caused by ULP program");
break;
default : Serial.printf("Wakeup was not caused by deep sleep:
%d\n",wakeup_reason); break;
}
++bootCount;
print_wakeup_reason();
esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
esp_deep_sleep_start();
}

void loop() {
digitalWrite(26,HIGH);
delay(500);
digitalWrite(26,LOW);
delay(500);
Portal.handleClient();
if (Firebase.getString(firebaseData, "/FOCOS/prototipo")) {

if (firebaseData.stringData() == "true") {
digitalWrite(2,LOW);
}
else if (firebaseData.stringData() == "false") {
digitalWrite(2,HIGH);
}
}
}

You might also like