Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=================================( DECLARA E CONFIGURA AS BIBLIOTECAS )=================================//
- #include <IRutils.h>
- #include <EEPROM.h>
- #include <IRrecv.h>
- #include "salvaIR.h"
- int codIR[52];
- byte num;
- #include <ESP8266WiFi.h>
- #include <WiFiClient.h>
- #include <ESP8266mDNS.h>
- #include <ESP8266WebServer.h>
- #include <WiFiManager.h>
- #include"FS.h"
- #ifndef UNIT_TEST
- #include <Arduino.h>
- #endif
- //#include <IRremoteESP8266.h>
- #include <IRsend.h>
- #define IR_LED 5 // ESP8266 GPIO pin to use. Recommended: 0 (D8).
- IRsend irsend(IR_LED); // Set the GPIO to be used to sending the message.
- //inicializacao servidor
- ESP8266WebServer server(80);
- //Inicializacao do WiFiManager
- WiFiManager wifiManager;
- bool inicio2 = 1;
- //=================================( DEFINE VARIAVEIS DE SISTEMA )=================================//
- //=================================( VOID SETUP CONFIGURAÇÕES )=================================//
- void setup()
- {
- EEPROM.begin(1024);
- irrecv.enableIRIn();
- irsend.begin();
- pinMode(2, OUTPUT);
- //pinMode(0, OUTPUT);
- Serial.begin(115200);
- SPIFFS.begin();
- //WiFi.begin(ssid, password);
- wifiManager.setConfigPortalTimeout(180);
- wifiManager.autoConnect("MeuWebServer");
- conectRede();
- carregarHTML();
- digitalWrite(2, HIGH);
- Serial.println("Selecione numero do controle remoto de 0 a 9, ");
- // Serial.println("ou S (s) para não entrar nas rotinas de gravção de codes ");
- selectRC();
- listaRC();
- Serial.println("Fim");
- Serial.println("apaga EEPROM = 2. Novo code = qq digito. ");
- }
- //=================================( VOID CONECTANDO NA REDE WIFI )=================================//
- void conectRede()
- {
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
- Serial.println("");
- Serial.print("IP address: ");
- Serial.println(WiFi.localIP());
- }
- //=================================( VOID SETUP CONFIGURAÇÕES )=================================//
- void loop()
- {
- while (inicio2 == 1)
- {
- if (Serial.available() > 0)
- {
- char javali = Serial.read();
- if ( javali == '2')
- {
- Serial.println("EEPROM Apagada: ");
- EEPROM.put(addrControl, 0xDAD0DAD0);
- EEPROM.commit();
- displayRC = 0;
- listaRC();
- addrControl = pulga * 0x64;;
- Serial.println(" ");
- Serial.print("Prox. End. : "); Serial.println(addrControl);
- Serial.println(" ");
- addr = addrControl;
- inicio2 = 0;
- Serial.println("Digite um valor na serial");
- }
- else
- {
- inicio2 = 0;
- if ((addr - (pulga * 0x64)) > 3)
- addr = addr - 4;
- Serial.println("Digite um valor na serial");
- }
- }
- }
- if (Serial.available() > 0)
- {
- int pulga = Serial.read();
- irrecv.resume(); // limpa buffer irrecv
- guardaRC_Code();
- }
- server.handleClient();
- }
- //===============================( VOID ENVIA PAGINA HTML PARA O CLIENT )================================//
- void carregarHTML()
- {
- server.begin();
- Serial.println("Web server started!");
- server.on("/", []() {
- // carregar o html aki
- bool exist = SPIFFS.exists("/INDEX.html");
- if (exist)
- {
- Serial.println("O arquivo INDEX.html existe");
- File f = SPIFFS.open("/INDEX.html", "r");
- //int s = f.size();
- //Serial.printf("Size=%d\r\n", s);
- String data = f.readString();
- server.send(200, "text/html", data);
- f.close();
- }
- });
- server.on("/data", []() {
- irsend.sendNEC(0x002FD58A7, 32);
- server.send(200, "192.168.0.28", "Resposta OK");
- });
- server.on("/teste", []() {
- if (digitalRead(2) == HIGH) {
- digitalWrite(2, LOW);
- }
- else {
- digitalWrite(2, HIGH);
- }
- server.send(200, "192.168.0.28", "Resposta texto OK");
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement