Advertisement
RuiViana

IR_MPS_V02.ino

May 15th, 2018
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.99 KB | None | 0 0
  1. //=================================( DECLARA E CONFIGURA AS BIBLIOTECAS )=================================//
  2. #include <IRutils.h>
  3. #include <EEPROM.h>
  4. #include <IRrecv.h>
  5. #include "BD_EEPROM.h"
  6. int codIR[52];
  7. byte num;
  8.  
  9. #include <ESP8266WiFi.h>
  10. #include <WiFiClient.h>
  11. #include <ESP8266mDNS.h>
  12. #include <ESP8266WebServer.h>
  13. #include <WiFiManager.h>
  14. #include"FS.h"
  15.  
  16. #ifndef UNIT_TEST
  17. #include <Arduino.h>
  18. #endif
  19. //#include <IRremoteESP8266.h>
  20. #include <IRsend.h>
  21. #define IR_LED 5  // ESP8266 GPIO pin to use. Recommended: 0 (D8).
  22. IRsend irsend(IR_LED);  // Set the GPIO to be used to sending the message.
  23.  
  24. //inicializacao servidor
  25. ESP8266WebServer server(80);
  26.  
  27. //Inicializacao do WiFiManager
  28. WiFiManager wifiManager;
  29. bool inicio2 = 1;
  30. //=================================(     DEFINE VARIAVEIS DE SISTEMA    )=================================//
  31.  
  32.  
  33. //=================================(      VOID SETUP  CONFIGURAÇÕES     )=================================//
  34. void setup()
  35. {
  36.   irrecv.enableIRIn();
  37.   irsend.begin();
  38.   pinMode(2, OUTPUT);
  39.   //pinMode(0, OUTPUT);
  40.   Serial.begin(115200);
  41.   SPIFFS.begin();
  42.   //WiFi.begin(ssid, password);
  43.   wifiManager.setConfigPortalTimeout(180);
  44.   wifiManager.autoConnect("MeuWebServer");
  45.   conectRede();
  46.   carregarHTML();
  47.   digitalWrite(2, HIGH);
  48.    setup2();
  49. /*
  50.   Serial.println("Selecione numero do controle remoto de 0 a 9,  ");
  51. //  Serial.println("ou S (s) para não entrar nas rotinas de gravção de codes  ");
  52.   selectRC();
  53.   listaRC();
  54.   Serial.println("Fim");
  55.   Serial.println("apaga EEPROM = 2.  Novo code = qq digito. ");*/
  56. }
  57. //=================================(    VOID CONECTANDO NA REDE WIFI    )=================================//
  58. void conectRede()
  59. {
  60.   while (WiFi.status() != WL_CONNECTED)
  61.   {
  62.     delay(500);
  63.     Serial.print(".");
  64.   }
  65.   Serial.println("");
  66.   Serial.print("IP address: ");
  67.   Serial.println(WiFi.localIP());
  68. }
  69. //=================================(      VOID SETUP  CONFIGURAÇÕES     )=================================//
  70. void loop()
  71. {
  72.   loop2();
  73.   server.handleClient();
  74. }
  75. //===============================(  VOID ENVIA PAGINA HTML PARA O CLIENT )================================//
  76. void carregarHTML()
  77. {
  78.   server.begin();
  79.   Serial.println("Web server started!");
  80.   server.on("/", []() {
  81.     // carregar o html aki
  82.     bool exist = SPIFFS.exists("/INDEX.html");
  83.     if (exist)
  84.     {
  85.       Serial.println("O arquivo INDEX.html existe");
  86.       File f = SPIFFS.open("/INDEX.html", "r");
  87.       //int s = f.size();
  88.       //Serial.printf("Size=%d\r\n", s);
  89.       String data = f.readString();
  90.       server.send(200, "text/html", data);
  91.       f.close();
  92.     }
  93.   });
  94.  
  95.   server.on("/data", []() {
  96.     irsend.sendNEC(0x002FD58A7, 32);
  97.     server.send(200, "192.168.0.28", "Resposta OK");
  98.   });
  99.  
  100.   server.on("/teste", []() {
  101.     if (digitalRead(2) == HIGH) {
  102.       digitalWrite(2, LOW);
  103.     }
  104.     else {
  105.       digitalWrite(2, HIGH);
  106.     }
  107.     server.send(200, "192.168.0.28", "Resposta texto OK");
  108.   });
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement