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 "BD_EEPROM.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()
- {
- 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);
- setup2();
- /*
- 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()
- {
- loop2();
- 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