Page 3 of 7

Re: Ethernet fails connecting after a while

Posted: Wed Apr 04, 2012 10:55 am
by cjdelphi
ok then, so what do we have just before it crashes..

Code: Select all

void loop()
{

  char c;
  int buttonState;
  currentmillis= millis();
  secs = currentmillis/1000; //convect milliseconds to seconds
  mins=secs/60; //convert seconds to minutes
  hours=mins/60; //convert minutes to hours
  days=hours/24; //convert hours to days
  secs=secs-(mins*60); //subtract the coverted seconds to minutes in order to display 59 secs max
  mins=mins-(hours*60); //subtract the coverted minutes to hours in order to display 59 minutes max
  hours=hours-(days*24); //subtract the coverted hours to days in order to display 23 hours max
  //Display results
 
 buttonState = digitalRead(USBPowerPin);
 if (buttonState == LOW) {     
   delay(1);
   if ((override==false) && (ledon==false))
    {
      digitalWrite(SBLEDPin, HIGH);  
      ledon=true;
    }
  }
  
 

  
//   sensorvalue = analogRead(sensorpin);    
//Serial.print("Sensor Voltage Reading: ");
//    Serial.println(sensorvalue,DEC);
//    delay(150); 

  //if (pressure!=0) delay(1);

  Client client = server.available();
  if (client) {
    visitors++;
    if (client.connected()) {
      {

 
        //    char c = client.read();     
        client.println("HTTP/1.1 200 OK");
        client.println("Content-Type: text/html");
        client.println();
        client.println("Hello from my <u><b><i>Arduino!</u></b></i><br>");
        client.print("Main Power: ");
          if (buttonState == LOW) 
          client.println("<B><I>Main 240 volts OFF</B></I>");
         if (buttonState == HIGH)
           client.println("Main 240 volts OK<BR>");
        
          client.println("Bedroom Lighting: <B><I>");
          if (ledon==true) 
            client.println("ON!");
             else
            client.println("OFF!"); 
         client.println("</B></I><BR>");
   
        client.println("Local IP: http://192.168.1.253:1234/WAN IP: http://110.175.97.110:1234 <br>");

        client.print("Hello Visitor Number: <b>");
        client.println(visitors);

        client.print("<br></b>New Pressure: <b>");
        p = bmp.readPressure(); // (offset for Adelaide);
        p = p/100;
        p = p + 8.31;     //offset          
        client.print(p);
        client.print("</b>Millibars<br>");
        if (oldp!=0) {
          client.print("Old Pressure: <b>");
          client.print(oldp);
          client.print("</b>Millibars"); 
        }
        client.print("<br>Temprature: <b>");
        client.print(bmp.readTemperature());
        client.println("</b>c<br>Altitude");
        client.print(bmp.readAltitude(101500));
        client.println(" meters above sea level<br>");
        client.println("<br>");
        oldp = p;
     if (days>0) // days will displayed only if value is greater than zero
      {
       client.print(days);
       client.print(" days and :");
      }
      client.print(hours);
     client.print("h:");
     client.print(mins);
     client.print("m:");
     client.print(secs);
     client.print("s<br> <BR><BR> - Written By Craig C. (2012)");
      client.stop(); 
      }
    }
  }
So then, the last line that should be spewed out from wiznet via atmega is "written by" and then client.stop..

but here's exactly what happens at the crash, client.stop no longer appears to work and here's what gets posted

[quote]
Hello from my <u><b><i>Arduino!</u></b></i><br>
Main Power: Main 240 volts OK<BR>
Bedroom Lighting: <B><I>
OFF!
</B></I><BR>
Local IP: http://192.168.1.253:1234/WAN IP: http://110.175.97.110:1234 <br>
Hello Visitor Number: <b>107
<br></b>New Pressure: <b>1016.94</b>Millibars<br>Old Pressure: <b>1017.00</b>Millibars<br>Temprature: <b>26.30</b>c<br>Altitude
53.00 meters above sea level<br>
<br>
0h:0m:56s<br> <BR><BR> - Written By Craig C. (2012)1234/WAN IP: http://110.175.97.110:1234 <br>
Hello Visitor Number: <b>83
<br></b>New Pressure: <b>1HTTP/1.1 200 OK
Content-Type: text/html

Hello from my <u><b><i>Arduino!</u></b></i><br>
Main Power: Main 240 volts OK<BR>
HTTP/1.1 200 OK
Content-Type: text/html

Hello from my <u><b><i>Arduino!</u></b></i><br>
Main Power: Main 240 volts OK<BR>
Bedroom Lighting: <B><I>
OFF!
</B></I><BR>
Local IP: http://192.168.1.253:1234/WAN IP: http://110.175.97.110:HTTP/1.1 200 OK
Content-Type: text/html
[/qupte]

Re: Ethernet fails connecting after a while

Posted: Wed Apr 04, 2012 10:59 am
by cjdelphi
it's almost as though it's sending 2 streams of data down the same open socket... and then crashing (and or, not terminating the socket like it's meant to)

Re: Ethernet fails connecting after a while

Posted: Wed Apr 04, 2012 11:01 am
by cjdelphi
infact the sequential 'visitor' number should go in sequence, but you'll see it huge jump

Hello Visitor Number: <b>107
<br></b>New Pressure: <b>1016.94</b>Millibars<br>Old Pressure: <b>1017.00</b>Millibars<br>Temprature: <b>26.30</b>c<br>Altitude
53.00 meters above sea level<br>
<br>
0h:0m:56s<br> <BR><BR> - Written By Craig C. (2012)1234/WAN IP: http://110.175.97.110:1234 <br>
Hello Visitor Number: <b>83
<br></b>New Pressure: <b>1HTTP/1.1 200 OK
Content-Type: text/html


it should be sequential... but it's not, so is it simply not terminating the socket?

Re: Ethernet fails connecting after a while

Posted: Wed Apr 04, 2012 12:01 pm
by Sleurhutje
cjdelphi wrote:it's almost as though it's sending 2 streams of data down the same open socket... and then crashing (and or, not terminating the socket like it's meant to)
Perhaps this is true. Try the client.flush() command before client.stop() to clear the buffer.

Re: Ethernet fails connecting after a while

Posted: Wed Apr 04, 2012 11:32 pm
by cjdelphi
I noticed the official example from the ethernet shield has a small delay in just before it terminates the client's connection so just to be safe..

delay(1);
client.flush();
delay(1);
client.stop();

I'll let you know how it goes using this method, seems overkill and not needed, but meh...


Cheers for the input.

Re: Ethernet fails connecting after a while

Posted: Thu Apr 05, 2012 2:02 pm
by cjdelphi
http://arduino.cc/forum/index.php/topic,99926.0.html

they seem to think the SD causes the issue?.... (i've pulled my 4gig card out (which reads just fine with the example)..... popped the card out and let's see how it goes if this makes any difference. (then i'll try software disable)

Re: Ethernet fails connecting after a while

Posted: Thu Apr 05, 2012 2:13 pm
by Sleurhutje
Do not access the SD-card while the ethernet client is active. It might interfere the SPI clock signal somewhere. That will certainly cause a crash of the ethernet functions (or SD-card). If you do, make sure to check and set the SS signals (chip select) for the WIZnet and SD-card in the correct way.


Meanwhile testing my project. I've removed all interrupt routines and rewritten the sketch to read each pin over and over and toggle booleans to determine the state and check if a specific function should be called as the interrupt did. Also removed a hardware timer (which also uses the interrupt). It renders the sketch useless for my project but ever since the module never crashed, even with (artificial) delays/latencies on the network connection. :roll:

Re: Ethernet fails connecting after a while

Posted: Thu Apr 05, 2012 2:34 pm
by cjdelphi
I was not accessing the SD library at all (still don't) it's unused, just happens to be a card in because i could not be bothered taking it out...

so you're saying i still have to disable it even though i'm not importing the library?

Re: Ethernet fails connecting after a while

Posted: Thu Apr 05, 2012 4:45 pm
by Sleurhutje
By default the SS for both ethernet and SD are disabled. In my board a SD-card is inserted as well. Works fine since it's not accessed. Even when the library is not loaded or included.

Re: Ethernet fails connecting after a while

Posted: Fri Apr 06, 2012 5:33 am
by cjdelphi
Well, even though i did not call the library to use the SD functionality... even though i have bluetooth on D pin 3/4 it all works wonderful NOW i've removed the SD card, not a single crash yet... is it possible the circuitry is still reading or doing something with the SD card to cause a conflict?..

removed the card, server has yet to crash... co-incidence? I don't see how.