Servidor domotico con ethernet shield

Hace poco he adquirido una shield de ethernet para arduino y he estado cacharreando un poco con ella, es la basada en el enc28j60.

Encontré varios ejemplos, entre ellos el de nuelectronics y otro bastante interesante basado en el primero con funcionalidad para cambiar la configuracion ip por serie.

Yo he querido ampliar el número de botones para actuar en mas salidas, para consequir 4 he tenido que borrar toda la funcionalidad para cambiar la configuracion ip y ahora con 6 botones, sólo funcionan los 4 primeros :-[

Os dejo el código que he hecho para que le hecheis un vistazo y ver porqué no funcionan el boton 5 y 6 y ver si se podría ampliar a mas botones, ya que con 6 el proyecto se queda bastante escaso.

Saludos y gracias a toda la comunidad que hacen que todo sea mas facil.

1/2 del código

#include "etherShield.h"

// Based on Nuelecronics and JP Civade sample code
// Modified by Dricote on 2010/03/18
// Needs an ATMega368 beacuse of ram

// please modify the following two lines. mac and ip have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static uint8_t mymac[6] = {0x54,0x55,0x58,0x10,0x00,0x24}; 
static uint8_t myip[4] = {192,168,1,15};
static char baseurl[]="http://192.168.1.15/";
static uint16_t mywwwport =80; // listen port for tcp/www (max range 1-254)

// Relay status. Start Off.
byte on_off1;
byte on_off2;
byte on_off3;
byte on_off4;
byte on_off5;
byte on_off6;

#define BUFFER_SIZE 1500 
static uint8_t buf[BUFFER_SIZE+1];
#define STR_BUFFER_SIZE 22
static char strbuf[STR_BUFFER_SIZE+1];

EtherShield es=EtherShield();

// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf, byte on_off1, byte on_off2, byte on_off3, byte on_off4, byte on_off5, byte on_off6);
int8_t analyse_cmd(char *str);

// 6 relays connected to output
#define SW1  2
#define SW2  3
#define SW3  4
#define SW4  5
#define SW5  6
#define SW6  7

void setup(){
  
   /*initialize enc28j60*/
   es.ES_enc28j60Init(mymac);
   es.ES_enc28j60clkout(3); // change clkout from 6.25MHz to 12.5MHz
   delay(10);
        
      /* Magjack leds configuration, see enc28j60 datasheet, page 11 */
      // LEDA=greed LEDB=yellow
      //
      // 0x880 is PHLCON LEDB=on, LEDA=on
      // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
      es.ES_enc28j60PhyWrite(PHLCON,0x880);
      delay(250);
      //
      // 0x990 is PHLCON LEDB=off, LEDA=off
      // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
      es.ES_enc28j60PhyWrite(PHLCON,0x990);
      delay(250);
      //
      // 0x880 is PHLCON LEDB=on, LEDA=on
      // enc28j60PhyWrite(PHLCON,0b0000 1000 1000 00 00);
      es.ES_enc28j60PhyWrite(PHLCON,0x880);
      delay(250);
      //
      // 0x990 is PHLCON LEDB=off, LEDA=off
      // enc28j60PhyWrite(PHLCON,0b0000 1001 1001 00 00);
      es.ES_enc28j60PhyWrite(PHLCON,0x990);
      delay(250);
      //
  // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
  // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
  es.ES_enc28j60PhyWrite(PHLCON,0x476);
  delay(100);
        
  //init the ethernet/ip layer:
  es.ES_init_ip_arp_udp_tcp(mymac,myip,mywwwport);
  
  // Init outputs
       pinMode(SW1, OUTPUT); 
       digitalWrite(SW1, LOW);  // switch off LED
       pinMode(SW2, OUTPUT); 
       digitalWrite(SW2, LOW);  // switch off LED
        pinMode(SW3, OUTPUT); 
       digitalWrite(SW3, LOW);  // switch off LED
        pinMode(SW4, OUTPUT); 
       digitalWrite(SW4, LOW);  // switch off LED
        pinMode(SW5, OUTPUT); 
       digitalWrite(SW5, LOW);  // switch off LED
        pinMode(SW6, OUTPUT); 
       digitalWrite(SW6, LOW);  // switch off LED
}

void loop(){
  uint16_t plen, dat_p;
  int8_t cmd;

// Ethernet Mode
  plen = es.ES_enc28j60PacketReceive(BUFFER_SIZE, buf);

      /*plen will ne unequal to zero if there is a valid packet (without crc error) */
  if(plen!=0){
                 
    // arp is broadcast if unknown but a host may also verify the mac address by sending it to a unicast address.
    if(es.ES_eth_type_is_arp_and_my_ip(buf,plen)){
      es.ES_make_arp_answer_from_request(buf);
      return;
    }

    // check if ip packets are for us:
    if(es.ES_eth_type_is_ip_and_my_ip(buf,plen)==0){
      return;
    }
    
    if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
      es.ES_make_echo_reply_from_request(buf,plen);
      return;
    }
    
    // tcp port www start, compare only the lower byte
    if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==mywwwport){
      if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V){
         es.ES_make_tcp_synack_from_syn(buf); // make_tcp_synack_from_syn does already send the syn,ack
         return;     
      }
      if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V){
        es.ES_init_len_info(buf); // init some data structures
        dat_p=es.ES_get_tcp_data_pointer();
        if (dat_p==0){ // we can possibly have no data, just ack:
          if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V){
            es.ES_make_tcp_ack_from_any(buf);
          }
          return;
        }
        if (strncmp("GET",(char *)&(buf[dat_p]),4)!=0){
            // head, post and other methods for possible status codes see:
            // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
            plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>200 OK</h1>"));
            goto SENDTCP;
        }
        // If "get/" without parameters 
       if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){
            plen=print_webpage(buf, on_off1, on_off2, on_off3, on_off4, on_off5, on_off6);
            goto SENDTCP;
         }
        cmd=analyse_cmd((char *)&(buf[dat_p+6]));
        
        // Process commands
        switch (cmd) {
        case 2:
                on_off1=1;
              digitalWrite(SW1, HIGH);  // switch on LED1
                break;
        case 3:
                on_off1=0;
              digitalWrite(SW1, LOW);  // switch off LED1
                break;
        case 4:
                on_off2=1;
              digitalWrite(SW2, HIGH);  // switch on LED2
                break;
        case 5:
                on_off2=0;
              digitalWrite(SW2, LOW);  // switch off LED2
                break;
        case 6:
                on_off3=1;
              digitalWrite(SW3, HIGH);  // switch on LED3
                break;
        case 7:
                on_off3=0;
              digitalWrite(SW3, LOW);  // switch off LED3
                break;
        case 8:
                on_off4=1;
              digitalWrite(SW4, HIGH);  // switch on LED4
                break;
        case 9:
                on_off4=0;
              digitalWrite(SW4, LOW);  // switch off LED4
                break;
        case 10:
                on_off5=1;
              digitalWrite(SW5, HIGH);  // switch on LED5
                break;
        case 11:
                on_off5=0;
              digitalWrite(SW5, LOW);  // switch off LED5
                break;
        case 12:
                on_off6=1;
              digitalWrite(SW6, HIGH);  // switch on LED6
                break;
        case 13:
                on_off6=0;
              digitalWrite(SW6, LOW);  // switch off LED6
                break;                
            }
        plen=print_webpage(buf, on_off1, on_off2, on_off3, on_off4, on_off5, on_off6);
              
SENDTCP:  es.ES_make_tcp_ack_from_any(buf); // send ack for http get
           es.ES_make_tcp_ack_with_data(buf,plen); // send data       
      }
    }
  }
        
}
// The returned value is stored in the global var strbuf
uint8_t find_key_val(char *str,char *key)
{
        uint8_t found=0;
        uint8_t i=0;
        char *kp;
        kp=key;
        while(*str &&  *str!=' ' && found==0){
                if (*str == *kp){
                        kp++;
                        if (*kp == '\0'){ 
                                kp=key;
                                if (*str == '='){
                                        found=1;
                                }
                        }
                }else{
                        kp=key;
                }
                str++;
        }
        if (found==1){
                // copy the value to a buffer and terminate it with '\0'
                while(*str &&  *str!=' ' && *str!='&' && i<STR_BUFFER_SIZE){
                        strbuf[i]=*str;
                        i++;
                        str++;
                }
                strbuf[i]='\0';
        }
        return(found);
}

int8_t analyse_cmd(char *str)
{
        int8_t r=-1;
     
        if (find_key_val(str,"cmd")){
                if (*strbuf < 0x3a && *strbuf > 0x2f){
                        // is a ASCII number, return it
                        r=(*strbuf-0x30);
                }
        }
        return r;
}

uint16_t print_webpage(uint8_t *buf, byte on_off1, byte on_off2, byte on_off3, byte on_off4, byte on_off5, byte on_off6)
{
        int i=0;
        uint16_t plen;
        plen=es.ES_fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<FONT FACE=\"arial\"><center><p><A HREF=\"/\"><b>SERVIDOR DOMOTICO</b></A></p>"));
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<table bgcolor=\"#f7f7f7\"><tr><td align=center>"));

2/2 del código

        switch (on_off1) {
          case 1:
               plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 1: <font color=\"#00FF00\">On</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=3>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
                break;
          case 0:
                     plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 1: <font color=\"#CC0000\">Off</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=2>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
                break;
          }
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td><td align=center>"));
        switch (on_off2) {
          case 1:
               plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 2: <font color=\"#00FF00\">On</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=5>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
                break;
          case 0:
                     plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 2: <font color=\"#CC0000\">Off</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=4>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
                break;
          }
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td></tr><tr><td align=center>"));        
        switch (on_off3) {
          case 1:
               plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 3: <font color=\"#00FF00\">On</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=7>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
                break;
          case 0:
                     plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 3: <font color=\"#CC0000\">Off</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=6>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
                break;
          } 
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td><td align=center>"));  
        switch (on_off4) {
          case 1:
               plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 4: <font color=\"#00FF00\">On</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=9>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
                break;
          case 0:
                     plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 4: <font color=\"#CC0000\">Off</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=8>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
                break;
          }
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td></tr><tr><td align=center>"));  
        switch (on_off5) {
          case 1:
               plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 5: <font color=\"#00FF00\">On</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=11>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
                break;
          case 0:
                     plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 5: <font color=\"#CC0000\">Off</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=10>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
                break;
          }     
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td><td align=center>"));  
        switch (on_off6) {
          case 1:
               plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 6: <font color=\"#00FF00\">On</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=13>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch off\"></form>"));
                break;
          case 0:
                     plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("Out 6: <font color=\"#CC0000\">Off</font>
"));
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<form METHOD=get action=\""));
                plen=es.ES_fill_tcp_data(buf,plen,baseurl);
                plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("\">"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=hidden name=cmd value=12>"));
              plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"Switch on\"></form>"));
                break;
          }               
        plen=es.ES_fill_tcp_data_p(buf,plen,PSTR("</td></tr></table></center><hr>Ethernet Shield Arduino 1.0"));

        return(plen);
}

Buenas,

La verdad es que veo muy interesante tu proyecto, ya irás contando como avanza ...

Sobre lo de poder poner más entradas/salidas, te propongo que uses un Register Shifter como el 74HC595 (mira el tutorial de "ShiftOut" en esta misma página)

Si esto no es correcto, que me corrijan los que saben más, que yo me inicié en esto hace una semana :-p

Sobre el error en el código, si puedo me lo miro más a fondo, a ver si damos con el problema.

Saludos,

Yespi

Gracias yespi.

A noche estuve liado con el tema y modificando varias opciones, quitando botones, poniendo actuaciones solo por serie en vez de encender leds y la verdad que por mucho cambio que hice solo conseguí cuatro botones funcionando en la interfaz web, con mas se bloqueaba la página.

Seqún he leído es por el buffer que es pequeño y necesita que todo esté volcado a éste para luego poder enviarlo, pero entonces...de cual buffer estamos hablando?? del atmega o del enc28j60.

Como se podría solucionar esta cuestión?

Pues por lo que veo en el código, debe tratarse del buffer de la Ethernet.
Para mi, una manera de simplificar el código sería enviar un sólo parámetro en lugar de 4 o 6. En ese parámetro se indicarían los leds a encender en binario, hexadecimal, o con tu propia notación.

Por ejemplo, si pasas: 001001 podrías activar los leds 3 y 6
y con: 110000 activarías los leds 1 y 2

Podría ser una opción, un poco rústica a la vista en la interfaz web, pero pienso que aunque fuera así, habría que implementar en el código todo lo que tiene que hacer cada salida con lo cual estaríamos en las mismas.

El plan a lo mejor, aunque sea engorroso podría ser el ampliar el hard del ethernet, no lo se, es hablar por hablar :-[

yo he intentado lo mismo que tu y no lo conseguí. Me rompe la cabeza el HTML
sin embargo si que te puedo ayudar en el problema de que no funcionen los últimos botones.
en la línea 248 del programa "f (*strbuf < 0x3a && *strbuf > 0x2f)"
estás verificando que el dato que le pasas está entre 0 y 9, por eso no traga ni con 10, 11, 12 y similares. :wink:

Muchísimas gracias por contestar, todavía sigo con el tema.

Conseguí 6 botones funcionando haciendo un nuevo switch después del 9 jejejej era por eso y no me lo explicaba.

Yo de programación acabo de empezar como el que dice pero de html si llevo años con ello, si quieres podemos avanzar el tema.

Saludos

mi intención sería poder desde una página poder leer todos los datos posibles (entredas y salidas digitales y analógicas), y poder enviar valores a las que sean salidas, tado digitales como analógicas.
Mi problema es como pasar diferentes tidos de datos del arduino a la página web (floats y similares) o en caso contrario hacer la conversión matemática dentro de la página web(por ejemplo de una sonda de temperatura.

La versión que tenemos de ethernet shield es un poco puñetera, pues casi todo lo que hay en la red es para la standar.

después otra duda que tengo es si es más rápido pasar datos por ethernet que por el puerto serie. Porque mi otra intención es hacer un analizador de red.
Bueno, ya hablaremos.
Un saludo.

Me gusta tu proyecto, una de las funciones que pretendía hacer yo es una estación metereológica que dependiendo de varios estados los módulos hagan una cosa u otra a parte de toda la actuación manual.

Los módulos los tengo conectados todos mediante un bus y solo escucha el que tiene que escuchar, todos como esclavos y el servidor con la shield como master.

Sobre lo que dices de esta shield, tienes toda la razón y el buffer no ayuda mucho.

Sobre la sonda de temperatura hay algún ejemplo por ahí para plasmar el resultado en la web.

Otra de las cosas que intenté fué poner varias paginas pequeñas para no poner todo en el buffer y así saturarlo, funcionaba pero hacía muchísimas cosas raras.

Saludos

mira yo tengo este código que me parece mas simple porq no pruebas con este y me dices como te fue

#include <WString.h>
#include <Ethernet.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; 
byte ip[] = {192, 168, 1, 5};
Server server(80); 

int LDR = 3;

int LZC = 2;
int LZJ = 4; 
int LZD = 7;
int AAC = 8;

String readString = String(100);

boolean _LZJ = false; 
boolean _LZD = false;
boolean _AAC = false;
boolean _LZC = false;
///////////////////////
String url = String(100);
String teststring = String(100);
String finalstring = String(100);

int guardo = 0;
int limiteLDR = 18;
//////////////////////

void setup()
{

  Ethernet.begin(mac, ip);
  server.begin();

  pinMode(LDR, INPUT);

  pinMode(LZJ, OUTPUT);
  pinMode(LZD, OUTPUT);
  pinMode(AAC, OUTPUT);
  pinMode(LZC, OUTPUT);

}

void loop()
{

  Client client = server.available();
  if (client) 
  {
    while(client.connected()) 
    {
      if(client.available()) 
      {
        char c = client.read();
        if(readString.length() < 100) 
        {
          readString.append(c);
        }
        if(c == '\n') 
        {
          if(readString.contains("LuzDormitorio=1")) 
          {
            digitalWrite(LZD, HIGH);
            _LZD = true;

            //////////////////////LDR//////////////////////
            /* guardo = analogRead(LDR);
             if (guardo < limiteLDR)
             {
             digitalWrite(LZJ, HIGH);
             _LZJ=true;
             }
             else
             {
             digitalWrite(LZJ, LOW);
             _LZJ=false;
             }
             delay(10);    */
            //////////////////////FIN-LDR//////////////////

          }
          if(readString.contains("LuzDormitorio=0"))
          {
            digitalWrite(LZD, LOW);
            _LZD = false; 
          }
          if(readString.contains("LuzJardin=1")) 
          {
            digitalWrite(LZJ, HIGH);
            _LZJ = true;
          }
          if(readString.contains("LuzJardin=0"))
          {
            digitalWrite(LZJ, LOW);
            _LZJ = false;
          }
          if(readString.contains("AireAcondicionado=1")) 
          {
            digitalWrite(AAC, HIGH);
            _AAC = true;
          }
          if(readString.contains("AireAcondicionado=0"))
          {
            digitalWrite(AAC, LOW);
            _AAC = false; 
          }
          if(readString.contains("LuzCocina=1")) 
          {
            digitalWrite(LZC, HIGH);
            _LZC = true;
          }
          if(readString.contains("LuzCocina=0"))
          {
            digitalWrite(LZC, LOW);
            _LZC = false; 
          }

          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<head>");
          client.println("<meta http-equiv=Content-Type content=text/html; charset=utf-8 />");
          client.println("<title>Eco-Home</title>");
          client.println("</head>");
          client.println("<body>");

          client.println("Luz Jardin
");
          client.print("
Estado: ");
          if (_LZJ==true)
          {
            client.println("<font color='green'>ON");
            client.println("<form method=get name=LZJ><input type=hidden name=LuzJardin value=0><input type=submit value=OFF></form>");
          }
          if (_LZJ==false)
          {
            client.println("<font color='grey'>OFF");
            client.println("<form method=get name=LZJ><input type=hidden name=LuzJardin value=1><input type=submit value=ON></form>");
          }

          client.println("<hr><font color='black'>Aire Acondicionado
");
          client.print("
Estado: ");
          if (_AAC==true)
          {
            client.println("<font color='green'>ON");
            client.println("<form method=get name=AAC><input type=hidden name=AireAcondicionado value=0><input type=submit value=OFF></form>");
          }
          if (_AAC==false)
          {
            client.println("<font color='grey'>OFF");
            client.println("<form method=get name=AAC><input type=hidden name=AireAcondicionado value=1><input type=submit value=ON></form>");
          }

          client.println("<hr><font color='black'>Luz Dormitorio
");
          client.print("
Estado: ");
          if (_LZD==true)
          {
            client.println("<font color='green'>ON");
            client.println("<form method=get name=LZD><input type=hidden name=LuzDormitorio value=0><input type=submit value=OFF></form>");
          }
          if (_LZD==false)
          {
            client.println("<font color='grey'>OFF");
            client.println("<form method=get name=LZD><input type=hidden name=LuzDormitorio value=1><input type=submit value=ON></form>");
          }

          client.println("<hr><font color='black'>Luz Cocina
");
          client.print("
Estado: ");
          if (_LZC==true)
          {
            client.println("<font color='green'>ON");
            client.println("<form method=get name=LZC><input type=hidden name=LuzCocina value=0><input type=submit value=OFF></form>");
          }
          if (_LZC==false)
          {
            client.println("<font color='grey'>OFF");
            client.println("<form method=get name=LZC><input type=hidden name=LuzCocina value=1><input type=submit value=ON></form>");
          }

          readString="";
          client.stop();
        }
      }
    }
  }
}

lo que pasa que este código es para la shield que utiliza el chip wiznet verdad??

exacto, es para las ethernet con wiznet.

Nosotros estamos utilizando la basada en el enc28j60.

De todas maneras es interesante el código que has puesto, podrías explicarlo un poco y el circuito que has hecho?, por cierto, intenté compilarlo simplemente y me daba error, uso la 018.

mmm te da error?? ami me compila bien, quizás tengas que bajarte la librería WString.h

el código es sencillo defines la MAC, la IP y el puerto, luego defines los pines de entradas / salidas y una variable booleana para saber si esta activo o no.
luego por medio de GET pasas comandos a la url de la pagina, y el arduino atrapa esos comandos, los verifica y si esta en la lista de acciones simplemente hace lo que le pides. la pagina web muestra el botón ON en caso q este apagado y OFF en caso q este prendido. aparte de eso no mucho mas, cualquier duda me avisas

Acabo de bajarme la librería que me comentas en http://arduino.cc/en/uploads/Tutorial/String.zip la he incluído y sigue sin compilarme, no se si será la versión adecuada de la librería la que me he bajado.

Me dá los siguientes errores:

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:31: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:31: error: ISO C++ forbids declaration of 'Ethernet' with no type

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp: In function 'int Ethernet()':

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:31: error: 'int Ethernet()' redeclared as different kind of symbol

C:\arduino-0018\libraries\Ethernet/Ethernet.h:20: error: previous declaration of 'EthernetClass Ethernet'

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp: At global scope:

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:34: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:38: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:43: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:47: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:51: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:55: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:60: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:64: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:68: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:72: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:77: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:81: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:85: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:89: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:93: error: 'Ethernet' is not a class or namespace

C:\arduino-0018\libraries\Ethernet\Ethernet.cpp.cpp:97: error: 'Ethernet' is not a class or namespace

Luego lo he probado con la versión 019 y a parte de incorporar la librería SPI que me pide al compilar, me da los siguientes errores:

C:\arduino-0019\libraries\String\WString.cpp:34: error: prototype for 'String::String(int)' does not match any in class 'String'
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:39: error: candidates are: String::String(long unsigned int, int)
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:38: error: String::String(long int, int)
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:37: error: String::String(unsigned int, int)
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:36: error: String::String(int, int)
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:35: error: String::String(unsigned char)
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:34: error: String::String(char)
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:33: error: String::String(const String&)
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:32: error: String::String(const char*)
C:\arduino-0019\libraries\String\WString.cpp: In constructor 'String::String(const char*)':
C:\arduino-0019\libraries\String\WString.cpp:50: error: '_array' was not declared in this scope
C:\arduino-0019\libraries\String\WString.cpp:52: error: 'setArray' was not declared in this scope
C:\arduino-0019\libraries\String\WString.cpp: In copy constructor 'String::String(const String&)':
C:\arduino-0019\libraries\String\WString.cpp:60: error: '_array' was not declared in this scope
C:\arduino-0019\libraries\String\WString.cpp:61: error: 'clear' was not declared in this scope
C:\arduino-0019\libraries\String\WString.cpp:62: error: 'const class String' has no member named '_array'
C:\arduino-0019\libraries\String\WString.cpp:62: error: 'setArray' was not declared in this scope
C:\arduino-0019\libraries\String\WString.cpp: In member function 'const String& String::operator=(const String&)':
C:\arduino-0019\libraries\String\WString.cpp:77: error: '_array' was not declared in this scope
C:\arduino-0019\libraries\String\WString.cpp:83: error: 'clear' was not declared in this scope
C:\arduino-0019\libraries\String\WString.cpp:84: error: 'const class String' has no member named '_array'
C:\arduino-0019\libraries\String\WString.cpp:84: error: 'setArray' was not declared in this scope
C:\arduino-0019\libraries\String\WString.cpp: At global scope:
C:\arduino-0019\libraries\String\WString.cpp:90: error: prototype for 'const String& String::operator=(const char*)' does not match any in class 'String'
C:\arduino-0019\libraries\String\WString.cpp:70: error: candidate is: const String& String::operator=(const String&)
C:\arduino-0019\libraries\String\WString.cpp:107: error: prototype for 'const String& String::operator+=(const char*)' does not match any in class 'String'
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\arduino-0019\libraries\String\WString.cpp:127: error: prototype for 'const String& String::operator+=(char)' does not match any in class 'String'
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\arduino-0019\libraries\String\WString.cpp:145: error: prototype for 'const String& String::operator+=(int)' does not match any in class 'String'
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\arduino-0019\libraries\String\WString.cpp:159: error: prototype for 'const String& String::operator+=(long int)' does not match any in class 'String'
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:44: error: candidate is: const String& String::operator+=(const String&)
C:\arduino-0019\libraries\String\WString.cpp: In member function 'const String& String::operator+=(const String&)':
C:\arduino-0019\libraries\String\WString.cpp:176: error: '_array' was not declared in this scope
C:\arduino-0019\libraries\String\WString.cpp:179: error: 'setArray' was not declared in this scope
C:\arduino-0019\libraries\String\WString.cpp:183: error: '_array' was not declared in this scope
C:\arduino-0019\libraries\String\WString.cpp:183: error: 'const class String' has no member named '_array'
C:\arduino-0019\libraries\String\WString.cpp: At global scope:
C:\arduino-0019\libraries\String\WString.cpp:191: error: no 'const String& String::append(char)' member function declared in class 'String'
C:\arduino-0019\libraries\String\WString.cpp:196: error: no 'const String& String::append(char*)' member function declared in class 'String'
C:\arduino-0019\libraries\String\WString.cpp:201: error: no 'const String& String::append(const String&)' member function declared in class 'String'
C:\arduino-0019\libraries\String\WString.cpp:206: error: no 'const String& String::append(int, int)' member function declared in class 'String'
C:\arduino-0019\libraries\String\WString.cpp:217: error: no 'const String& String::append(long int, int)' member function declared in class 'String'
C:\arduino-0019\libraries\String\WString.cpp:226: error: no 'const String& String::append(int)' member function declared in class 'String'
C:\arduino-0019\libraries\String\WString.cpp:234: error: no 'const String& String::append(long int)' member function declared in class 'String'
C:\arduino-0019\libraries\String\WString.cpp:323: error: prototype for 'char String::charAt(int)' does not match any in class 'String'
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:57: error: candidate is: char String::charAt(unsigned int) const
C:\arduino-0019\libraries\String\WString.cpp:339: error: prototype for 'void String::setCharAt(int, char)' does not match any in class 'String'
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:71: error: candidate is: void String::setCharAt(unsigned int, char)
C:\arduino-0019\libraries\String\WString.cpp:355: error: prototype for 'boolean String::equals(char*)' does not match any in class 'String'
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:60: error: candidate is: unsigned char String::equals(const String&) const
C:\arduino-0019\libraries\String\WString.cpp:366: error: prototype for 'boolean String::equals(const String&)' does not match any in class 'String'
C:\arduino-0019\hardware\arduino\cores\arduino/WString.h:60: error: candidate is: unsigned char String::equals(const String&) const
C:\arduino-0019\libraries\String\WString.cpp:372: error: no 'boolean String::contains(char*)' member function declared in class 'String'
C:\arduino-0019\libraries\String\WString.cpp:380: error: prototype for 'byte* String::getBytes()' does not match any in class 'String'
C:\arduino-0019\hardware................

ya salio la 019 woow, voy a tener q actualizar yo tengo la 018.

el error q te da con la 018 es algo en la librería ethernet, la modificaste ?? o es la original, trata de bajártela nuevamente, sino me avisas y te subo la mía.

te dejo una cap de mi código compilado.

mira subí el código en pde y las librerías necesarias a mediafire, no se cuanto tiempo estará activo el link así q bájalas rápido ;D

http://www.mediafire.com/file/ppyu04gj1y7d02c/Arduino.rar

Pues algo debí tocar en la librería de ethernet porque la he borrado y la he vuelto a meter y ahora por fin me compila con la 018, antes lo hice también pero en vez de borrarla entera conbiné archivos y por eso persistían los errores.

Gracias por los archivos, he podido confirmar que tienes los mismos que yo :wink: , por cierto, el pde creo que no estaba en el rar.

Unas cosillas mas, podrías subir, si puedes, un pantallazo de como se ve en el navegador tu código? tengo curiosidad, ya que como no tengo esa shield no puedo probarlo ;D

Cuántos botones se podrían llegar a poner?
Has probado a poner varias páginas enlazadas entre si o enlazar a otra ip?

Saludos