Advertisement
RuiViana

IR_MPS.ino

May 13th, 2018
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.89 KB | None | 0 0
  1. //=================================( DECLARA E CONFIGURA AS BIBLIOTECAS )=================================//
  2. #include <IRutils.h>
  3. #include <EEPROM.h>
  4. #include <IRrecv.h>
  5. #include "salvaIR.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.   EEPROM.begin(1024);
  37.   irrecv.enableIRIn();
  38.   irsend.begin();
  39.   pinMode(2, OUTPUT);
  40.   //pinMode(0, OUTPUT);
  41.   Serial.begin(115200);
  42.   SPIFFS.begin();
  43.   //WiFi.begin(ssid, password);
  44.   wifiManager.setConfigPortalTimeout(180);
  45.   wifiManager.autoConnect("MeuWebServer");
  46.   conectRede();
  47.   carregarHTML();
  48.   digitalWrite(2, HIGH);
  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.   while (inicio2 == 1)
  73.   {
  74.     if (Serial.available() > 0)
  75.     {
  76.       char javali = Serial.read();
  77.       if ( javali == '2')
  78.       {
  79.         Serial.println("EEPROM Apagada:  ");
  80.         EEPROM.put(addrControl, 0xDAD0DAD0);
  81.         EEPROM.commit();
  82.         displayRC = 0;
  83.         listaRC();
  84.         addrControl = pulga * 0x64;;
  85.         Serial.println(" ");
  86.         Serial.print("Prox. End. : "); Serial.println(addrControl);
  87.         Serial.println(" ");
  88.         addr = addrControl;
  89.         inicio2 = 0;
  90.         Serial.println("Digite um valor na serial");
  91.       }
  92.       else
  93.       {
  94.         inicio2 = 0;
  95.         if ((addr - (pulga * 0x64)) > 3)
  96.           addr = addr - 4;
  97.         Serial.println("Digite um valor na serial");
  98.       }
  99.     }
  100.   }
  101.   if (Serial.available() > 0)
  102.   {
  103.     int pulga = Serial.read();
  104.     irrecv.resume();          // limpa buffer irrecv
  105.     guardaRC_Code();
  106.   }
  107.   server.handleClient();
  108. }
  109. //===============================(  VOID ENVIA PAGINA HTML PARA O CLIENT )================================//
  110. void carregarHTML()
  111. {
  112.   server.begin();
  113.   Serial.println("Web server started!");
  114.   server.on("/", []() {
  115.     // carregar o html aki
  116.     bool exist = SPIFFS.exists("/INDEX.html");
  117.     if (exist)
  118.     {
  119.       Serial.println("O arquivo INDEX.html existe");
  120.       File f = SPIFFS.open("/INDEX.html", "r");
  121.       //int s = f.size();
  122.       //Serial.printf("Size=%d\r\n", s);
  123.       String data = f.readString();
  124.       server.send(200, "text/html", data);
  125.       f.close();
  126.     }
  127.   });
  128.  
  129.   server.on("/data", []() {
  130.     irsend.sendNEC(0x002FD58A7, 32);
  131.     server.send(200, "192.168.0.28", "Resposta OK");
  132.   });
  133.  
  134.   server.on("/teste", []() {
  135.     if (digitalRead(2) == HIGH) {
  136.       digitalWrite(2, LOW);
  137.     }
  138.     else {
  139.       digitalWrite(2, HIGH);
  140.     }
  141.     server.send(200, "192.168.0.28", "Resposta texto OK");
  142.   });
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement