Advertisement
Guest User

Estado led

a guest
Aug 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1.  
  2. #include <FS.h>
  3. #include <ESP8266WiFi.h> //WIFI
  4. #include <FirebaseArduino.h> //FIREBASE
  5. #include <DNSServer.h> //SERVER PORTAL WIFI
  6. #include <ESP8266WebServer.h> //SERVIDOR
  7. #include <WiFiManager.h> // SCAN WIFI REDES WIFI
  8. #include <EEPROM.h>
  9.  
  10. int val1; int val2;
  11. int addr = 0; int addr1 = 1; int addr2 = 2;
  12. int comando;
  13. int value;
  14. int limitMen = 128;
  15. int qtdeControl = limitMen / 4;
  16. unsigned long dadosMem[32]; // Matriz para guardar dados lidos da EEPRO
  17. int addrEEPROM = 0; // Endereco inicial da EEPROM
  18. int controlOk = 0; // Marca que encontrou controle na EEPROM
  19. int posicaoOk = limitMen / 4 + 1; // Localizaçao do match Inical é maior q qq memoria
  20.  
  21.  
  22. #define FIREBASE_HOST "kenniacasa.firebaseio.com"
  23. #define FIREBASE_AUTH "be8OFUwX1NVAxbP2XljoNnR4Xz2FgS57gbC7jBdE" // TOKEN BANCO DE DADOS FIREBASE
  24.  
  25. bool requestRestart = false; // REINICIAR FALSO
  26. byte l = 5; //D1 // PINO LUZ
  27. byte p = 4; //D4 // PINO INTERRUPTOR
  28. byte status = 0; // STATUS INICIAL DA LAMPADA
  29. //-----------------------------------------------
  30. void setup()
  31. {
  32. Serial.begin(115200); // VELOCIDADE DA PORTA SERIAL
  33. pinMode(p, INPUT_PULLUP); // DECLARANDO PINO SWITE EM ALTA DO INTERRUPTOR
  34. pinMode(l, OUTPUT); // DECLARANDO PINO SAIDA DA LAMPADA
  35. EEPROM.begin(limitMen); // limitMen/4 enderecos de 4 byte = 128 bytes
  36. Serial.print("addr EEPROM : "); Serial.println(addr1);
  37. val2 = EEPROM.read(addr1); //cases eprom+
  38. Serial.print("valor EEPROM : "); Serial.println(val2);
  39. digitalWrite(l, val2);
  40. Serial.print("addr EEPROM : "); Serial.println(addr2);
  41. val2 = EEPROM.read(addr2); //cases eprom+
  42. Serial.print("valor EEPROM : "); Serial.println(val1);
  43. digitalWrite(l, val1);
  44. Serial.println();
  45. WiFiManager wifiManager; // AUTENTICANDO DADOS DAS REDES WIFI
  46. wifiManager.setBreakAfterConfig(true); // SALVANDO
  47.  
  48. if (!wifiManager.autoConnect("ESP Wifi", "12345678")) //NOME QUE IRA APARECER NA REDE WIFI DO CLIENTE
  49. {
  50. Serial.println("falha ao conectar na rede wifi");
  51. delay(500); // REINCIIAR QUANDO ENCONTRAR A REDE WIFI
  52. ESP.reset();
  53. delay(500);
  54. }
  55. Serial.println("conectado :)"); /// EXIBIR QUANDO ESTIVER CONECTADO REDE LOCAL
  56. Serial.println("local ip"); // IP LOCAL QUANDO ESTIVER CONECTADO
  57. Serial.println(WiFi.localIP());
  58.  
  59. Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  60. Firebase.set("sensor/-LJjA6vy0_uYYFAij-OY/st_status", 0); //-------------------------------> --MUDAR----------------------->>>>>
  61. }
  62. //----------------------------------------------
  63. void loop()
  64. {
  65. if (WiFi.status() == WL_CONNECTED)
  66. {
  67. digitalWrite(l, Firebase.getInt("sensor/-LJjA6vy0_uYYFAij-OY/st_status")); //------------------>MUDAR TOKEN------------------->>>>
  68. }
  69. if ((digitalRead(p) == 0) && (status == 0) && WiFi.status() == WL_CONNECTED)
  70. {
  71. digitalWrite(l, HIGH); // LIGAR LAMPADA
  72. status = 1; // MUDAR STATUS
  73. Firebase.set("sensor/-LJjA6vy0_uYYFAij-OY/st_status", 1); // --------------------------------------MUdar TOKEN------------------->>>>
  74. Serial.println(Firebase.getFloat("sensor/-LJjA6vy0_uYYFAij-OY/st_status"));
  75. EEPROM.write(addr2, 1); // Salvando na eeprom
  76. }
  77. else
  78. {
  79. if ((digitalRead(p) == 1) && (status == 1) && WiFi.status() == WL_CONNECTED)
  80. {
  81. digitalWrite(l, LOW);
  82. status = 0;
  83. Firebase.set("sensor/-LJjA6vy0_uYYFAij-OY/st_status", 0); // ENVIA STATUS 0 PARA O FIREBASE
  84. Serial.println(Firebase.getFloat("sensor/-LJjA6vy0_uYYFAij-OY/st_status"));
  85. EEPROM.write(addr2, 0); // Salvando na eeprom
  86. }
  87. else
  88. {
  89. if ((digitalRead(p) == 0) && (status == 0)) // SE FOR ACIONADO O PULSO
  90. {
  91. digitalWrite(l, HIGH); // LIGAR LAMPADA
  92. status = 1; // MUDAR STATUS
  93. EEPROM.write(addr1, 1); // Salvando na eeprom
  94. }
  95. else // SENAO
  96. {
  97. if ((digitalRead(p) == 1) && (status == 1))
  98. {
  99. digitalWrite(l, LOW); // DESLIGA LAMPADA
  100. status = 0;
  101. EEPROM.write(addr1, 0); // Salvando na eeprom
  102.  
  103. }
  104. }
  105. }
  106. }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement