Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FS.h>
- #include <ESP8266WiFi.h> //WIFI
- //#include <FirebaseArduino.h> //FIREBASE
- //#include <DNSServer.h> //SERVER PORTAL WIFI
- #include <ESP8266WebServer.h> //SERVIDOR
- #include <WiFiManager.h> // SCAN WIFI REDES WIFI
- #include <EEPROM.h>
- int val1; byte val2;
- int addr = 0; int addr1 = 1; int addr2 = 2;
- int comando;
- int value;
- int limitMen = 128;
- int qtdeControl = limitMen / 4;
- unsigned long dadosMem[32]; // Matriz para guardar dados lidos da EEPRO
- int addrEEPROM = 0; // Endereco inicial da EEPROM
- int controlOk = 0; // Marca que encontrou controle na EEPROM
- int posicaoOk = limitMen / 4 + 1; // Localizaçao do match Inical é maior q qq memoria
- //#define FIREBASE_HOST "kenniacasa.firebaseio.com"
- //#define FIREBASE_AUTH "be8OFUwX1NVAxbP2XljoNnR4Xz2FgS57gbC7jBdE" // TOKEN BANCO DE DADOS FIREBASE
- bool requestRestart = false; // REINICIAR FALSO
- byte l = 5; //D1 // PINO LUZ
- byte p = 4; //D4 // PINO INTERRUPTOR
- byte status = 0; // STATUS INICIAL DA LAMPADA
- //-----------------------------------------------
- void setup()
- {
- Serial.begin(115200); // VELOCIDADE DA PORTA SERIAL
- pinMode(p, INPUT_PULLUP); // DECLARANDO PINO SWITE EM ALTA DO INTERRUPTOR
- pinMode(l, OUTPUT); // DECLARANDO PINO SAIDA DA LAMPADA
- EEPROM.begin(limitMen); // limitMen/4 enderecos de 4 byte = 128 bytes
- Serial.println(" ");
- Serial.print("addr EEPROM : "); Serial.println(addr1);
- val2 = EEPROM.read(addr1); //cases eprom+
- Serial.print("valor EEPROM : "); Serial.println(val2);
- digitalWrite(l, val2);
- Serial.println();
- WiFiManager wifiManager; // AUTENTICANDO DADOS DAS REDES WIFI
- wifiManager.setBreakAfterConfig(true); // SALVANDO
- if (!wifiManager.autoConnect("InSert Wifi", "12345678")) //NOME QUE IRA APARECER NA REDE WIFI DO CLIENTE
- {
- Serial.println("falha ao conectar na rede wifi");
- delay(3000); // REINCIIAR QUANDO ENCONTRAR A REDE WIFI
- // ESP.reset();
- delay(5000);
- }
- Serial.println("conectado :)"); /// EXIBIR QUANDO ESTIVER CONECTADO REDE LOCAL
- Serial.println("local ip"); // IP LOCAL QUANDO ESTIVER CONECTADO
- Serial.println(WiFi.localIP());
- //Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
- //Firebase.set("sensor/-LJjA6vy0_uYYFAij-OY/st_status", 0); //-------------------------------> --MUDAR------------------------->>>>>
- }
- //----------------------------------------------
- void loop()
- {
- if (WiFi.status() == WL_CONNECTED)
- {
- //digitalWrite(l, Firebase.getInt("sensor/-LJjA6vy0_uYYFAij-OY/st_status")); //------------------>MUDAR TOKEN---------------------->>>>-----------
- // Serial.println("passei");
- }
- if ((digitalRead(p) == 0) && (status == 0) && WiFi.status() == WL_CONNECTED)
- {
- Serial.println("passei 1");
- digitalWrite(l, HIGH); // LIGAR LAMPADA
- EEPROM.write(addr1, 1); // Salvando na eeprom
- EEPROM.end();
- status = 1; // MUDAR STATUS
- Serial.print("valor EEPROM : "); Serial.println(EEPROM.read(addr1));
- //Firebase.set("sensor/-LJjA6vy0_uYYFAij-OY/st_status", 1); // --------------------------------------MUdar TOKEN---------------------------------------->>>>
- }
- else
- {
- if ((digitalRead(p) == 1) && (status == 1) && WiFi.status() == WL_CONNECTED)
- {
- Serial.println("passei 2");
- digitalWrite(l, LOW);
- EEPROM.write(addr1, 1); // Salvando na eeprom
- EEPROM.end();
- Serial.print("valor EEPROM : "); Serial.println(EEPROM.read(addr1));
- status = 0;
- //Firebase.set("sensor/-LJjA6vy0_uYYFAij-OY/st_status", 0); // ENVIA STATUS 0 PARA O FIREBASE
- }
- else
- {
- if ((digitalRead(p) == 0) && (status == 0)) // SE FOR ACIONADO O PULSO
- {
- Serial.println("passei 3");
- digitalWrite(l, HIGH); // LIGAR LAMPADA
- status = 1; // MUDAR STATUS
- EEPROM.write(addr1, 1); // Salvando na eeprom
- EEPROM.end();
- }
- else // SENAO
- {
- if ((digitalRead(p) == 1) && (status == 1))
- {
- Serial.println("passei 4");
- digitalWrite(l, LOW); // DESLIGA LAMPADA
- status = 0;
- EEPROM.write(addr1, 0); // Salvando na eeprom
- EEPROM.end();
- // wdt_reset ();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement