Go Down

Topic: Ethernet Shield Disconnecting after a while (Read 58 times) previous topic - next topic

mholguin

Here's the deal: I have an age old projecto of setting a PWS (personal weather station). I've decided for an Arduino with an array of sensors. No big deal as far as the sensors goes.

The thing is that, whilst waiting for the other sensors to arrive, I wanted to start working on the web side of the PWS, monitoring temperature and humidity.

The problem: After some random amount of time (it varies from half an hour up to 24+hours). the Arduino becomes unreachable via web (still responds to pings). Sometimes, you can see on the web browser something like this:

Code: [Select]

/b>resh: 5 Temperatura: 30.91C / Heat Index: 36.85C / Humedad: 68.27% Uptime: 165 seconds.
b> 30.91C / Heat Index: 36.85C / Humedad: 68.30% Uptime: 122 seconds.
7‹ÑB_ ™8>9' õ½Ïh-)âPá)¡Ò"œ¹92Æ6ÚiBªDù¯ã62ø m¨YÅ…ŒÔÈK¿d%1'¬}AD™•á†5@`:e"¼Z`«Rdá͐7×ÊìX¼ÃbÅ"Îҁ µæÌ6»ƒñAS͵#hž,§LžÇ&ïWãƒ(cÛѾ7ì@G˜üè¥:„Kit‰"'¦®Ìª›HµôôFˆtÇ30.86C / Heat Index: /b>36.75C / Hume seconds.
ecoC / Heat Index: 36.72C / Hum onds. ™¸¡¶V:˜†`FVf7娎*á¦§©Ó‡TE{<7 ]z"¹&WÐa‹ÏÐ+.ØÓúŒÍ'øºÒ1xŽ§‰UßÌ|,(°ÜÃ`p5?Â--‰¡JSCB›‹JH• ÙmHTTP/1.1 200 OK Content-Type: text/html Connection: close Refresh: 5 Temperatura: 30.98C / Heat Index: 37.02C / Humedad: 68.19% Uptime: 32 seconds.


I have to reboot to gain access to it again.

I don't feel is a hardware issue. I Updated the Ethernet library to this one: https://github.com/embeddist/WIZ_Ethernet_Library-IDE1.6.x

I've done programming way a long time ago. I've been working over the WebServer sample file. Not a designer either so the web page I'm producing is plain and ugly (mayb that's why is failing). Here´s the code:

Code: [Select]
/*
  Web Server

 A simple web server that shows the value of the analog input pins.
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe
 modified 15 Jul 2014
 by Soohwan Kim

 */

#include <SPI.h>
#include <Ethernet.h>
#include <Wire.h>
#include "Adafruit_HTU21DF.h"

Adafruit_HTU21DF htu = Adafruit_HTU21DF();
float Tc,Tf,Hm,HI = 0;

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
#if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io
;
#else
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
#endif

//#define __USE_DHCP__

IPAddress ip(10, 0, 0, 5);
IPAddress gateway(10, 0, 0, 2);
IPAddress subnet(255, 255, 255, 0);
// fill in your Domain Name Server address here:
IPAddress myDns(8, 8, 8, 8); // google puble dns

// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

if (!htu.begin()) {
 Serial.println("Couldn't find sensor!");
while (1);   }

  // initialize the ethernet device
#if defined __USE_DHCP__
#if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io
  Ethernet.begin();
#else
  Ethernet.begin(mac);
#endif  
#else
#if defined(WIZ550io_WITH_MACADDRESS) // Use assigned MAC address of WIZ550io
  Ethernet.begin(ip, myDns, gateway, subnet);
#else
  Ethernet.begin(mac, ip, myDns, gateway, subnet);
#endif  
#endif

  // start the Ethernet connection and the server:
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void loop() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          /*/ output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("<br />");
          }*/
            Tc = htu.readTemperature();
            Tf = (Tc*9/5)+32; //convertir la temperatura a F
            Hm = htu.readHumidity();
            HI = -42.379 + 2.04901523*Tf  
               + 10.14333127*Hm - 0.22475541*Tf*Hm
               - 0.00683783*Tf*Tf - 0.05481717*Hm*Hm
               + 0.00122874*Tf*Tf*Hm + 0.00085282*Tf*Hm*Hm
               - 0.00000199*Tf*Tf*Hm*Hm; // Calcular el HI en F
            HI = (HI-32)*5/9;            //Convertir el HI a C
            client.print("<b>");
            client.print("Temperatura: ");
            client.print("</b>");
            client.print(Tc);
            client.print("<b>");
            client.print("C / Heat Index: ");
            client.print("</b>");
            client.print(HI);
            client.print("<b>");
            client.print("C / Humedad: ");
            client.print("</b>");
            client.print(Hm);
            client.print("<b>");
            client.println("%");
            client.print("Uptime: ");
            client.print("</b>");
            client.print(millis()/1000);
            client.print("<b>");
            client.println(" seconds.");
            client.println("<br />");
            client.print("</b>");          
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}

mholguin

I just remembered something I read a while back, and after some searching was able to find it here: https://startingelectronics.org/tutorials/arduino/ethernet-shield-web-server-tutorial/basic-web-server/

As per the warning note, you should never leave an unused SD card on the slot. It will cause odd behavior from the ethernet shield. I removed the card, and it have been working flawlessly for over half an ahour now...

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy