Arduino + Ethernet Shield + IR - Não funciona!

Amigos, boa tarde. Estou com um código que eu adaptei mais não está funcionando:

#include <IRremote.h>
#include <SPI.h>
#include <Ethernet.h>

IRsend irsend;

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0x9B, 0x36 }; //MAC ADRESS UNIVERSAL PARA PLACAS GENÉRICAS
byte ip[] = { 192, 168, 1, 99 }; // ENDEREÇO DE IP - DEFINIDO PELO USUÁRIO
byte gateway[] = { 192, 168, 1, 1 }; // ENDEREÇO GATEWAY DO ROTEADOR
byte subnet[] = { 255, 255, 255, 0 }; //SUBMASCARA DO ROTEADOR
EthernetServer server(80); //PORTA QUE SERÁ ABERTA

String readString;

//////////////////////

void setup() {

  Ethernet.begin(mac, ip, gateway, subnet); //COMEÇAR O ETHERNET SHIELD, COM OS DADOS ACIMA
  server.begin(); //COMECAR O WEBSERVER
  Serial.begin(9600);  //HABILITAR O SERIAL
  Serial.println("Arduino + Ethernet Shield + TV"); //IMPRIMIR NO SERIAL
}

void ligaTV() {
  int khz = 38; // 38kHz carrier frequency for the NEC protocol
  unsigned int irSignal[] = {8760, 4480, 484, 628, 484, 628, 484, 1724, 700, 356, 540, 628, 484, 628, 484, 628, 564, 548, 484, 1728, 484, 1724, 568, 544, 488, 1724, 484, 1700, 592, 1644, 484, 1728, 564, 1644, 564, 548, 564, 548, 568, 464, 644, 1648, 488, 620, 488, 624, 564, 496, 620, 544, 564, 1644, 488, 1724, 488, 1704, 504, 628, 564, 1644, 568, 1644, 564, 1648, 564, 1644, 568, 39152, 8840, 2200, 564}; //AnalysIR Batch Export (IRremote) - RAW
  
  irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz); //Note the approach used to automatically calculate the size of the array.

}

void loop() {
  // CRIAR A CONEXÃO COM O CLIENTE
  EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        //read char by char HTTP request
        if (readString.length() < 100) {

          //store characters to string
          readString += c;
        }

        //if HTTP request has ended
        if (c == '\n') {

          ///////////////////// control arduino pin
          Serial.println(readString); //print to serial monitor for debuging
          if (readString.indexOf("?tv") > 0) //checks for off
          {
            Serial.println("TV On/Off");
            ligaTV();
          }
        }
        
        //clearing string for next read
        readString = "";


        /////////////// PAGINA HTML //////////////////////////

        client.println("HTTP/1.1 200 OK"); //send new page
        client.println("Content-Type: text/html");
        client.println();

        client.println("<html>");
        client.println("<head>");
        client.println("<title>Arduino + Ethernet Shield + TV</title>");
        client.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>");
        client.println("<meta name='viewport' content='width=device-width, initial-scale=1, user-scalable=no'>");
        client.println("</head>");
        client.println("<body>");
        client.println("<div id='container' align='center'>");
        client.println("<h2>Arduino + Ethernet Shield + TV</h2>");
        client.println("<hr>");
        client.println("<br>");
        client.println("<a href='/?tv'>TV</a>");
        client.println("</div>");
        client.println("</body>");
        client.println("</head>");

        delay(1);
        //stopping client
        client.stop();
      }
    }
  }
}

O que estou fazendo de errado?

Obs: se eu colocar esse mesmo código raw no IRSendRawDemo, ele funciona normalmente! =/

Syntax

Ethernet.begin(mac);
Ethernet.begin(mac, ip);
Ethernet.begin(mac, ip, dns);
Ethernet.begin(mac, ip, dns, gateway);
Ethernet.begin(mac, ip, dns, gateway, subnet);

Não era isso. Resolvi em casa! =)

1 curtida

Qual a solução? Compartilhe

Fiz um post no meu blog. Estou começando agora! =)