Hola. Estoy realizando un proyecto en el que necesito almacenar un código por infrarrojo en una memoria, y luego desde un web server acceder a la memoria y retransmitirlo. La parte de capturar y almacenar el código y la programación del web server en el arduino están resueltas de forma separada pero cuando intento realizar un web server y coloco en el programa la librería <IRremote.h>, el arduino no me carga la página o empieza a comportarse erráticamente. Probé con varios IDE, desde el 022 para abajo.
El programa en cuestión es el siguiente:
#if ARDUINO > 18
#include <SPI.h> // needed for Arduino versions later than 0018
#endif
#include <Ethernet.h>
#include <IRremote.h>
#include <EEPROM.h> //LIBRERÍA PARA MANEJO DE EEPROM (COPIAR DESPUES DENTRO DE LA CARPETA)
#include <Wire.h> //LIBRERÍA WIRE
#include <TextFinder.h>
#include <avr/pgmspace.h> // for progmem
#define P(name) static const prog_uchar name[] PROGMEM // declare a static string
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,0,20 };
Server server(80);
char buffer[8]; // make this buffer big enough to hold requested page names
void setup()
{
Serial.begin(9600);
Ethernet.begin(mac, ip);
server.begin();
delay(3000);
Serial.println("Ready");
}
void loop()
{
Client client = server.available();
if (client) {
TextFinder finder(client );
int type = 0;
while (client.connected()) {
if (client.available()) {
// GET, POST, or HEAD
if( finder.getString("","/", buffer,sizeof(buffer)) )
{ //int getString(char *pre_string,char *post_string,char *buf,int length);
if(strcmp(buffer, "GET ") == 0 )
type = 1;
else if(strcmp(buffer,"POST ") == 0)
type = 2;
Serial.print("Type = ");
Serial.println(type);
// look for the page name
if(finder.getString( "", "/", buffer, sizeof(buffer) ))
{//int getString(char *pre_string,char *post_string,char *buf,int length);
Serial.print(buffer);
Serial.print("|");
if(strcmp(buffer, "control")== 0)
showcontrol(client, finder, type == 2);
else
unknownPage(client, buffer);
}
}
Serial.println();
break;
}
}
// give the web browser time to receive the data
delay(1);
client.stop();
}
}
void showcontrol(Client client, TextFinder finder, boolean isPost)
{
Serial.println("ir");
sendHeader(client,"CONTROL REMOTO IR");
client.print("");
client.println("
CONTROL REMOTO IR
");
if(isPost){
Serial.println("isPost");
finder.find("\n\r"); // skip to the body - Salta al cuerpo
// find parameters starting with "pin" and stop on the first blank line
Serial.println("searching for parms");
int pin;
int val;
while(finder.findUntil("pinD", "\n\r")){
pin = finder.getValue(); // the pin number
val = finder.getValue(); // 0 or 1
Serial.print(pin);
Serial.print("=");
Serial.println(val);
//pinMode(pin, OUTPUT);
//digitalWrite(pin, val);
//Acciones a realizar...
}
switch( pin ) {
case 1: //Control Remoto 1
switch ( val ){
case 0:
Serial.println("Control Remoto 1: Accion 1");
break;
case 1:
Serial.println("Control Remoto 1: Accion 2");
break;
default:
Serial.println("No hubo coinsidencia con alguna accion del control remoto 2");
}
break;
case 2: //Control Remoto 2
switch ( val ){
case 0:
Serial.println("Control Remoto 2: Accion 1");
break;
case 1:
Serial.println("Control Remoto 2: Accion 2");
break;
default:
Serial.println("No hubo coinsidencia con alguna accion del control remoto 2");
}
break;
default:
Serial.println("No hubo coinsidencia con algun Control Remoto");
}
} // if(isPost){
client.println("<table border='0' width=""500"">");
// show output pins 6-9
// note pins 10-13 are used by the ethernet shield
for (int i = 1; i < 3 ; i++) {
client.print("<td width=""100"">Control Remoto ");
client.print(i);
client.print(" <td width=""70"" align=""center"">");
htmlButtonControl(client, "On", "pinD", i, "1");
client.print(" <td width=""70"" align=""center"">");
htmlButtonControl(client, "Off", "pinD", i, "0");
client.print(" <td width=""60"" align=""center"">");
client.println("");
}
client.println("");
client.print("<a href=");
client.print("http://www.controlethernet.com.ar:1030/");
client.println("
}
// Crea los botones para la solapa de Controles Remotos
void htmlButtonControl( Client client, char * label, char *name, int nameId, char *value)
{
//print( "
<input type='hidden'name='pinD9' value='1'>" );
P(buttonBegin) = "
<input type='hidden'name='";
printP(client, buttonBegin);
client.print(name);
client.print(nameId);
client.print("' value='");
client.print(value);
P(buttonType) = "'>";
printP(client, buttonEnd);
}
void unknownPage(Client client, char *page)
{
Serial.println("index");
sendHeader(client,"DOMOTICA");
client.print("");
client.println("
DOMOTICA
");
client.print("<a href=");
client.print("http://192.168.0.20:1030/control");
client.println("
client.println("");
}
void sendHeader(Client client, char *title)
{
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("");
client.println(title);
client.println("");
}
void printP(Client client, const prog_uchar *str)
{
// copy data out of program memory into local storage, write out in
// chunks of 32 bytes to avoid extra short TCP/IP packets
// from webduino library Copyright 2009 Ben Combee, Ran Talbott
uint8_t buffer[32];
size_t bufferEnd = 0;
while (buffer[bufferEnd++] = pgm_read_byte(str++)){
if (bufferEnd == 32){
client.write(buffer, 32);
bufferEnd = 0;
}
}
// write out everything left but trailing NUL
if (bufferEnd > 1)
client.write(buffer, bufferEnd - 1);
}
Con este programa tengo una página inicial que se titula Domotica y cuando se hace click en el link Control Remoto IR se queda cargando la página y nunca la termina de cargar. Por otro lado, al eliminar una parte del programa o bien comentar <IRremote.h>, la página se carga correctamente.
Me gustaría saber si alguien tuvo problemas similares usando dicha librería y la Ethernet Shield.
Desde ya, muchas gracias.