Ethernet shield

Hi guys, I got a problem with my ethernet-shield.
I'm using it on an arduino duemilanove und it has worked before.
When im turning it off an on a lot of times sometimes i can connect and see the page and its just driving me crazy.
Im guessing it has something to do with the code, i think the hardware is ok.
I would be VERY glad if someone could take a look at it.
It has a lot of stuffe unrelatet to the ethernet, but i'll post it complete as i dont know which parts are relavant.

Thanks you allready =)

#include "SPI.h"
#include "Ethernet.h"
#include "WebServer.h"
#include <RCSwitch.h>
#include <VirtualWire.h>

int RF_TX_PIN = 2;

RCSwitch mySwitch = RCSwitch();
int red = 0;            //integer for red darkness
int blue = 0;           //integer for blue darkness
int green = 0;          //integer for green darkness

int i=0;
char befehl[40];
int bar1redmix=0;
int bar1greenmix=0;
int bar1bluemix=0;

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = {192, 168, 0, 16};
  byte gateway[] = { 192, 168, 0, 1 };

#define PREFIX ""
WebServer webserver(PREFIX, 80);

void indexCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  server.httpSuccess();
  if (type != WebServer::HEAD)
  {
    P(helloMsg) =    
      "<!DOCTYPE html><html><head><title>Homeserver</title>"     
      "<meta charset=\"utf-8\"><meta name=\"apple-mobile-web-app-capable\" content=\"yes\" /><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"><meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">"
      "<link rel=\"stylesheet\" href=\"http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css\" />"
      "<script src=\"http://code.jquery.com/jquery-1.6.4.min.js\"></script>"
      "<script src=\"http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js\"></script>"
      "</head>" 
      "<body>"
      "<center>"
      "<h1>Index!</h1>"
      "<form action='/tv.html' method='POST'>"
      "<p><button value='0'>Tv</button></p>"
      "</form>"
      "<form action='/bar.html' method='POST'>"
      "<p><button value='0'>Bar</button></p>"
      "</form>"
      "<form action='/lights.html' method='POST'>"
      "<p><button value='0'>Lights</button></p>"
      "</form>"
      "</center></body></html>";
    server.printP(helloMsg);
  }
}
void barCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{

  if (type == WebServer::POST)
  {
    bool repeat;
    char name[16], value[16];
    do
    {
      repeat = server.readPOSTparam(name, 16, value, 16);

      if (strcmp(name, "+") == 0)
      {        
        const char *msg = "bar1up/";
        vw_send((uint8_t *)msg, strlen(msg));
      }
      else if (strcmp(name, "-") == 0)
      {        
        const char *msg = "bar1down/";
        vw_send((uint8_t *)msg, strlen(msg));
      }
      else if (strcmp(name, "on") == 0)
      {
        const char *msg = "bar1on/";
        vw_send((uint8_t *)msg, strlen(msg));
      }
      else if (strcmp(name, "off") == 0)
      {        
        const char *msg = "bar1off/";
        vw_send((uint8_t *)msg, strlen(msg));
      }
      else if (strcmp(name, "flash") == 0)
      {        
        const char *msg = "bar1flash/";
        vw_send((uint8_t *)msg, strlen(msg));
      }
      else if (strcmp(name, "strobe") == 0)
      {
        const char *msg = "bar1strobe/";
        vw_send((uint8_t *)msg, strlen(msg));
      }
      else if (strcmp(name, "fade") == 0)
      {        
        const char *msg = "bar1fade/";
        vw_send((uint8_t *)msg, strlen(msg));
      }
      else if (strcmp(name, "mix") == 0)
      {        
        const char *msg = "bar1mix/";
        vw_send((uint8_t *)msg, strlen(msg));
      }

    } 
    while (repeat);
    server.httpSeeOther(PREFIX);
    return;
  }

  server.httpSuccess();
  if (type != WebServer::HEAD)
  {
    P(helloMsg) =    
      "<!DOCTYPE html><html><head>"
      "<title>Bar Remote</title>"      
      "</head>" 
      "<body>"
      "<center>"
      "<h1>Bar</h1>"
      "<form action='/index.html' method='POST'>"
      "<p><button value='0'>Index</button></p>"
      "</form>"

      "<table border='0'>"
      "<tr>"
      "<td><form action='/bar.html' method='POST'><p><button name='+' value='0'>+</button></form></p></td>"
      "<td><form action='/bar.html' method='POST'><p><button name='-' value='0'>-</button></form></p></td>"
      "<td><form action='/bar.html' method='POST'><p><button name='on' value='0'>On</button></form></p></td>"
      "<td><form action='/bar.html' method='POST'><p><button name='off' value='0'>Off</button></form></p></td>"
      "</tr>"
      "
"
      "<tr>"
      "<td><form action='/bar.html' method='POST'><p><button name='flash' value='0'>Flash</button></form></p></td>"
      "<td><form action='/bar.html' method='POST'><p><button name='strobe' value='0'>Strobe</button></form></p></td>"
      "<td><form action='/bar.html' method='POST'><p><button name='fade' value='0'>Fade</button></form></p></td>"
      "<td><form action='/bar.html' method='POST'><p><button name='mix' value='0'>Mix</button></form></p></td>"
      "</tr>"
      "</table></center>"



      "</body></html>";
    server.printP(helloMsg);
  }
}


void tvCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  if (type == WebServer::POST)
  {
    bool repeat;
    char name[16], value[16];
    do
    {
      repeat = server.readPOSTparam(name, 16, value, 16);

      if (strcmp(name, "on/off") == 0)
      {
        Serial.print("irbatvonoff/");
      }
      else if (strcmp(name, "tv/av") == 0)
      {
        Serial.print("irbatvav/"); 
      }
      else if (strcmp(name, "txt") == 0)
      {
        Serial.print("irbatvtxt/"); 
      }
      else if (strcmp(name, "mute") == 0)
      {        
        Serial.print("irbatvmute/");
      }
      else if (strcmp(name, "vol+") == 0)
      {
        Serial.print("irbatvvolup/"); 
      }
      else if (strcmp(name, "vol-") == 0)
      {
        Serial.print("irbatvvoldown/"); 
      }
      else if (strcmp(name, "prog+") == 0)
      {
        Serial.print("irbatvproup/");
      }
      else if (strcmp(name, "prog-") == 0)
      {
        Serial.print("irbatvprodown/"); 
      }
    } 
    while (repeat);
    server.httpSeeOther(PREFIX);
    return;
  }
 server.httpSuccess();
  if (type != WebServer::HEAD)
  {
    P(helloMsg) =    
      "<!DOCTYPE html><html>"
      "<head>"
      "<title>Tv Remote</title>"
      "</head>" 
      "<body>"
      "<center>"
      "<h1>TV</h1>"
      "<form action='/index.html' method='POST'>"
      "<p><button value='0'>Index</button></p>"
      "</form>"
      "<form action='/tvprog.html' method='POST'>"
      "<p><button value='0'>Programme</button></p>"
      "</form>"

      "<table border='0'>"

      "<tr>"
      "<td><form action='/tv.html' method='POST'><button name='on/off' value='0'>On/Off</button></form></td>"
      "<td><form action='/tv.html' method='POST'><p><button name='prog+' value='+'>Prog +</button></form></p></td>"
      "<td><form action='/tv.html' method='POST'><button name='tv/av' value='0'>Tv/Av</button></form></td>"
      "</tr>"
      "<tr>"
      "<td><form action='/tv.html' method='POST'><p><button name='vol-' value='4'>Vol -</button></form></p></td>"
      "<td><form action='/tv.html' method='POST'><p><button name='txt' value='5'>Txt</button></form></p></td>"
      "<td><form action='/tv.html' method='POST'><p><button name='vol+' value='6'>Vol +</button></form></p></td>"
      "</tr>"
      "<td><form action='/tv.html' method='POST'><p><button name='mute' value='0'>Mute</button></form></p></td>"
      "<td><form action='/tv.html' method='POST'><p><button name='prog-' value='8'>Prog -</button></form></p></td>"
      "<td>&#160;</td>"
      "</tr>"
      "</table>"
      "</center>"
      "</body></html>";
    server.printP(helloMsg);
  }
}

void lightsCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  if (type == WebServer::POST)
  {
    bool repeat;
    char name[16], value[16];
    do
    {
      repeat = server.readPOSTparam(name, 16, value, 16);
      if (strcmp(name, "max") == 0)
      {
        Serial.print("rmaxswitch/"); 
      }
      else if (strcmp(name, "Aon") == 0)
      {
        mySwitch.switchOn("11111", 1); 
      }
      else if (strcmp(name, "Bon") == 0)
      {
        mySwitch.switchOn("11111", 2); 
      }
      else if (strcmp(name, "Con") == 0)
      {
        mySwitch.switchOn("11111", 3); 
      }
      else if (strcmp(name, "Don") == 0)
      {
        mySwitch.switchOn("11111", 4); 
      }
      else if (strcmp(name, "Aoff") == 0)
      {
        mySwitch.switchOff("11111", 1); 
      }
      else if (strcmp(name, "Boff") == 0)
      {
        mySwitch.switchOff("11111", 2); 
      }
      else if (strcmp(name, "Coff") == 0)
      {
        mySwitch.switchOff("11111", 3); 
      }
      else if (strcmp(name, "Doff") == 0)
      {
        mySwitch.switchOff("11111", 4); 
      }
    } 
    while (repeat);

    server.httpSeeOther(PREFIX);
    return;
  }


  server.httpSuccess();
  if (type != WebServer::HEAD)
  {
    P(helloMsg) =    
      "<!DOCTYPE html><html><head><title>Light Remote</title>"
      "<meta charset=\"utf-8\"><meta name=\"apple-mobile-web-app-capable\" content=\"yes\" /><meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"><meta name=\"viewport\" content=\"width=device-width, user-scalable=no\">"
      "<link rel=\"stylesheet\" href=\"http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css\" />"
      "<script src=\"http://code.jquery.com/jquery-1.6.4.min.js\"></script>"
      "<script src=\"http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js\"></script>"
      "</head>"
      "<body>"
      "<center>"

      "<h1>Lights</h1>"
      "<form action='/index.html' method='POST'><p><button value='0'>Index</button></p></form>"
      "<h3>Deckenlichter</h3>" 
      "<form action='/lights.html' method='POST'><p><button name='max' value='0'>Max On/Off</button></p>"


      "<h3>Steckdosen</h3>"      
      "<table border='0'>"
      "<tr>"
      "<td><font>A</font></p></td>"
      "<td><form action='/lights.html' method='POST'><button name='Aon' value='0'>On</button></form></p></td>"
      "<td><form action='/lights.html' method='POST'><button name='Aoff' value='0'>OFF</button></form></p></td>"
      "<td><font>Beschreibung A</font></p></td>"
      "</tr>"

      "<tr>"
      "<td><font>B</font></p></td>"
      "<td><form action='/lights.html' method='POST'><button name='Bon' value='0'>On</button></form></p></td>"
      "<td><form action='/lights.html' method='POST'><button name='Boff' value='0'>OFF</button></form></p></td>"
      "<td><font>Standlampe </font></p></td>"
      "</tr>"

      "<tr>"
      "<td>C</p></td>"
      "<td><form action='/lights.html' method='POST'><button name='Con' value='0'>On</button></form></p></td>"
      "<td><form action='/lights.html' method='POST'><button name='Coff' value='0'>OFF</button></form></p></td>"
      "<td>Werkbank</p></td>"
      "</tr>"

      "<tr>"
      "<td>D</p></td>"
      "<td><form action='/lights.html' method='POST'><button name='Don' value='0'>On</button></form></p></td>"
      "<td><form action='/lights.html' method='POST'><button name='Doff' value='0'>OFF</button></form></p></td>"
      "<td>Beschreibung D</p></td>"      
      "</tr>"
      "</table>"
      "</center></body></html>";
    server.printP(helloMsg);
  }
}
void tvprogCmd(WebServer &server, WebServer::ConnectionType type, char *, bool)
{
  server.httpSuccess();
  if (type != WebServer::HEAD)
  {
    P(helloMsg) =    
      "<!DOCTYPE html><html><head><title>TV Remote</title>"
      "<body>"
      "<center>"
      "<h1>Programme</h1>"
      "<form action='/index.html' method='POST'>"
      "<p><button value='0'>Index</button></p></form>"
      "<form action='/tv.html' method='POST'>"
      "<p><button value='0'>Back</button></p></form>"
      "</center></body></html>";
    server.printP(helloMsg);
  }
}



void setup()
{
  /* initialize the Ethernet adapter */
  
  vw_set_tx_pin(RF_TX_PIN); // Setup transmit pin
  vw_setup(2000);

  Ethernet.begin(mac, ip, gateway);
  webserver.begin();
  webserver.setDefaultCommand(&indexCmd);
  webserver.addCommand("index.html", &indexCmd);
  webserver.addCommand("tv.html", &tvCmd);
  webserver.addCommand("bar.html", &barCmd);
  webserver.addCommand("lights.html", &lightsCmd);
  webserver.addCommand("tvprog.html", &tvprogCmd);
  mySwitch.enableTransmit(9);
  Serial.begin(9600);

}

void loop()
{
  char buff[64];
  int len = 64;
  analogWrite(5, red);

  webserver.processConnection(buff, &len);
}

When im turning it off an on a lot of times sometimes i can connect and see the page and its just driving me crazy.

Whenever I hear the sparrow chirping, watch the woodpecker chirp, catch a chirping trout, or listen to the sad howl of the chirp rat, I think: Oh boy! I'm going insane again. - Deep Thoughts by Jack Handy

not very helpful but a great quote :smiley:

Jesusismybrother:
not very helpful but a great quote :smiley:

As "i can connect and see the page and its just driving me crazy" is the only problem discription given, not much more can be said.

oh yeah, maybe i didn't pointet my problem out well enough.
I have no idea why it works sometime and why not.
I was hoping it had something to do with the code and maybe the initialising of the ethernet shield or something like that.

What ethernet shield are you using? Is it a w5100 based shield?
What IDE version are you using?
Where did you get that ethernet library?

You will get a lot more help if you are using IDE v1.0.1, a w5100 ethernet shield, and the IDE ethernet library.

Very interesting code!
If you already have a card into the SD card slot, reset and try whithout the card.