arduino uno web server stops responding after a week or so


hello there im new arduino world, have taken web server sketch , heavily modified can power on/off computer using 2 relays web after entering password.

the sketch works ok week or , arduino stops serving website.
the strange thing while website isnt served anymore, if open arduino ide , enable serial output arduino starts serving page again!

im trying best cant figure out why stops responding.

the correct password operate relays 8452 or 8425 both passwords produce same value on pin variable math operations selected both of them work.

the code following
can please me figure out why arduino stops responding?


code: [select]
/*

#include <spi.h>

#include <ethernet.h>


ethernetserver server(80);// server port



const byte reset = 5;// select pin reset

const byte power = 6;// select pin power
int pin =0;          // password value


byte mac[] = { 0xde, 0xad, 0xbe, 0xef, 0xfe, 0xed };// physical mac address

byte ip[] = { 192, 168, 1, 178 };// fixed ip address

byte gateway[] = { 192, 168, 1, 1 };// router gateway internet access

byte subnet[] = { 255, 255, 255, 0 };// subnet mask

string readstring;


void setup()

{

delay(300);// delay ethernet shield initialization (arduino has 65ms power delay , w5100 reset logic has 280ms)

pinmode(reset, output);// define pin reset output

pinmode(power, output);// define pin power output



serial.begin(9600);// initialize serial communications @ 9600 bps

serial.println(f("arduino uno r3 ethernet shiled w5100 - vu3gao"));// display arduino title

ethernet.begin(mac, ip, gateway, subnet);// start ethernet

server.begin();

serial.print(f("ethernet shield initialized. local ip address is:"));

serial.println(ethernet.localip());// print server ip address

}


void loop()

{

ethernetclient client = server.available();// create client connection

if (client == true)

{

while (client.connected())

{

if (client.available())

{

char c = client.read();// read char char http request

if (readstring.length() < 100)

{

readstring = readstring + c;// store characters string

}

if (c == '\n')

{

serial.println(readstring);

client.println(f("http/1.1 200 ok"));// send standard http headers

client.println(f("content-type: text/html"));

client.println();

client.println(f("<!doctype html><html>"));

client.println(f("<body bgcolor='9ec3c3'>"));

client.println(f("<center><head><title>home web control</title></head>"));

client.println(f("<h2>arduino uno r3 ethernet shield web server(v2.16)</h2>"));

client.println(f("<h4>home automation arduino</h4>"));

client.println(f("<br><br><hr/><p> enter correct password turn on , off <p/><hr/><br><br><br>"));

client.print(f("<br><br><br><br><br><br>"));

client.print(f("<input type=button value='&nbsp;1&nbsp;' onmousedown=location.href='/?1_on'>"));
client.print(f("&nbsp;"));
client.print(f("<input type=button value='&nbsp;2&nbsp;' onmousedown=location.href='/?2_on'>"));
client.print(f("&nbsp;"));
client.print(f("<input type=button value='&nbsp;3&nbsp;' onmousedown=location.href='/?3_on'>"));
client.print(f("<br>"));
client.print(f("<input type=button value='&nbsp;4&nbsp;' onmousedown=location.href='/?4_on'>"));
client.print(f("&nbsp;"));
client.print(f("<input type=button value='&nbsp;5&nbsp;' onmousedown=location.href='/?5_on'>"));
client.print(f("&nbsp;"));
client.print(f("<input type=button value='&nbsp;6&nbsp;' onmousedown=location.href='/?6_on'>"));
client.print(f("<br>"));
client.print(f("<input type=button value='&nbsp;7&nbsp;' onmousedown=location.href='/?7_on'>"));
client.print(f("&nbsp;"));
client.print(f("<input type=button value='&nbsp;8&nbsp;' onmousedown=location.href='/?8_on'>"));
client.print(f("&nbsp;"));
client.print(f("<input type=button value='&nbsp;9&nbsp;' onmousedown=location.href='/?9_on'>"));
client.print(f("<br>"));
client.print(f("<input type=button value='&nbsp;*&nbsp;' onmousedown=location.href='/?ak_on'>"));
client.print(f("&nbsp;"));
client.print(f("<input type=button value='&nbsp;0&nbsp;' onmousedown=location.href='/?0_on'>"));
client.print(f("&nbsp;"));
client.print(f("<input type=button value='&nbsp;#&nbsp;' onmousedown=location.href='/?hs_on'>"));
client.print(f("<br><br>"));

client.print(f("<input type=button value='reset' onmousedown=location.href='/?rs_on'>"));

client.print(f("&nbsp;"));

client.print(f("<input type=button value='power' onmousedown=location.href='/?pw_on'>"));
client.print(f("<br><br><br><br><br><br><br><br><br>"));
client.println(f("<br><br><br><br><hr/><p> home automation arduino <p/>"));

client.println(f("</body></html>"));

delay(1);// page loading delay

client.stop();// stopping client


//numbers 8,4,5,2 make math operation in order have pin variable number 25


          if (readstring.indexof("/?1_on") >0) //set pin value of button 1
           {
               pin = 0;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }
          
           if (readstring.indexof("/?2_on") >0)  //set pin value of button 2
           {
               pin = pin - 2;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }
          
           if (readstring.indexof("/?3_on") >0)  //set pin value of button 3
           {
               pin = 0;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }
          
           if (readstring.indexof("/?4_on") >0)  //set pin value of button 4
           {
               pin = pin * 4;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }
          
           if (readstring.indexof("/?5_on") >0)  //set pin value of button 5
           {
               pin = pin - 5;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }
          
           if (readstring.indexof("/?6_on") >0)  //set pin value of button 6
           {
               pin = 0;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }
          
           if (readstring.indexof("/?7_on") >0)  //set pin value of button 7
           {
               pin = 0;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }
          
           if (readstring.indexof("/?8_on") >0)  //set pin value of button 8
           {
               pin = pin + 8;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }
          
           if (readstring.indexof("/?9_on") >0)  //set pin value of button 9
           {
               pin = 0;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }
          
           if (readstring.indexof("/?as_on") >0)//set pin value of button *
           {
               pin = 0;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }
          
           if (readstring.indexof("/?0_on") >0)  //set pin value of button 0
           {
               pin = 0;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }
          
           if (readstring.indexof("/?hs_on") >0)  //set pin value of button #
           {
               pin = 0;
               serial.print("pin= ");
               serial.println(pin);
  delay(1);
           }


if(readstring.indexof("/?rs_on") > 0 && pin == 25) //if reset button pressed , password correct enable relay
              {
               digitalwrite(reset, high);
               delay(1000);
               digitalwrite (reset, low);
              pin = 0;
               serial.print("pin= ");
               serial.println(pin);
              
          
  delay(1);
              }

if(readstring.indexof("/?pw_on") > 0 && pin == 25) //if power button pressed , password correct enable relay
              {
               digitalwrite(power, high);
               delay(1000);
               digitalwrite (power, low);
               pin = 0;
               serial.print("pin= ");
               serial.println(pin);
          
  delay(1);
              }



readstring = "";// clearing string next read

}// end of line reached

}// end of client available

}// end of client connected

}// end of client connection

}// end of loop

quote
if open arduino ide , enable serial output arduino starts serving page again!
opening ide serial monitor reboots arduino.


Arduino Forum > Using Arduino > Project Guidance > arduino uno web server stops responding after a week or so


arduino

Comments