Page 1 of 1

Ethermega stops

Posted: Tue Mar 08, 2016 4:17 pm
by regis
I have a simple web server programmed. The Ethermega runs for several hours and then simply locks up. I can no longer get a response from the server.
What when wrong?

Code: Select all

#include <SPI.h>
#include <Ethernet.h>
#include "IRTemp.h"
#include <Dhcp.h>
#include <Dns.h>
#include <EthernetClient.h>

//ethernet items
byte mac [] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; // arduino mac address
byte ip [] = {192, 168, 1, 30}; // arduino ip address
byte vbip[] = {192, 168, 1, 116}; // vera ip address
int vbport = 3480; //vera port

//IR module setup
static const byte PIN_DATA    = 2; // Choose any pins you like for these
static const byte PIN_CLOCK   = 3;
static const byte PIN_ACQUIRE = 4;
static const TempUnit SCALE = FAHRENHEIT; // Options are CELSIUS, FAHRENHEIT
IRTemp irTemp(PIN_ACQUIRE, PIN_CLOCK, PIN_DATA);


int lowTemp = 50;
int highTemp = 90;
String rangeMsg;
float ambientTemperature;
float irTemperature;
int ambientoffset = 3;
int iroffset = 0;
char line1[100];

int okCount = 0;
int lowCount = 0;
int highCount = 0;
int everhl = 0; // only send OK get one time after a hi or lo situation
int alert = 0; // default alert on/off status = OFF    1=ON   0=OFF
String veramsg;


EthernetServer server(80);

void setup() {

  //ethernet and com port items
  Serial.begin(9600);  //start Serial Port
  Ethernet.begin(mac, ip);  //start ethernet
  server.begin();  //start server
  EthernetServer Server = EthernetServer(80);
  delay(50); //give everyone time to get up to speed
 
}

void loop() {
 delay(2000);
 EthernetClient client = server.available();  // try to get client
   
    if (client) {  // got client?
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                readHeader(client);

                    if (! pageNameIs("/"))  //if this is not the root page stop
                        {client.stop();     //make sure 4th character is a "/"
                         return;}
                

                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    client.println("Content-Type: text/html");
                    client.println("Connection: close");
                    client.println();
                    
                    //send html website info
                    client.print("<!doctype html>");
                    client.print("<html>");
                    client.print("<head>");
                    client.print("<title>KJN IR Temperature</title>");
                    client.print("</head>");
                    client.print("<body>");
                    client.print("<body style='background-color:white'>");
                    client.println("<form method='GET'>");
      
                    // auto refresh page every 10 seconds
                    client.print("<meta http-equiv='refresh' content='30'>");

                    client.print("KJN IR TEMPERATURE MONITOR");
                    client.println("<br />");
                    client.print("(IR = IfraRed sensor)");
                    client.println("<br><br><br>");

                    float ambientTemperature = irTemp.getAmbientTemperature(SCALE);
                    float irTemperature = irTemp.getIRTemperature(SCALE);
 
                    //print current ambient temp to client
                    client.print("Ambient Temperature = ");
                    client.print(ambientTemperature - ambientoffset);
                    client.println(" F ");
                    client.println("<br />");

                    //print current IR temp to client
                    client.print("IR Temperature = ");
                    client.print(irTemperature - iroffset);
                    client.print(" F ");
                    client.println("<br>");
                    client.println(" (page auto refreshs every 30 seconds)");
                    client.println("<br><br><br>");

                    //get GET command info
                    //headerinfo();
              
                    //print low IR alarm setting to client
                    client.print("Low IR Temp Alarm Value = ");
                    client.print(lowTemp);
                    client.print(".00 F  ");
                    client.print("<br>");
              
                    //print high IR alarm setting to client
                    client.print("High IR Temp Alarm Value = ");
                    client.print(highTemp);
                    client.print(".00 F  ");
                    client.print("<br>");
                    client.print("<br><br><br>");
              
                    //client temp change input
                    client.print("Enter New Low IR Temp Alarm Value --------");
                    client.print("<input type='number' name='Lo' min='10' max='300'>");
                    client.println("<br>");
                    client.print("(range 10-300)");
                    client.println("<br><br>");
                    client.print("Enter New High IR Temp Alarm Value -------");
                    client.print("<input type='number' name='Hi' min='10' max='300'>");
                    client.println("<br>");
                    client.print("(range 10-300)");
                    client.println("<br>");
              
              
                    //client alert on/off input
                    client.println("<br>");
                    client.print("Current alert status = ");
                    client.println(alert);
                    client.println("<br>");
                    client.print("Enter desired Alert Status  1 = ON -- 0 = OFF ");
                    client.print("<input type='number' name='Al' min='0' max='1'>");
                    client.println("<br>");
                    client.print("<input type='submit' value='Submit Change(s)'/>");
                    
               
            } // end if (client.available())
        } // end while (client.connected())
        delay(1000);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}


//read header
void readHeader(EthernetClient client)
{
  char ch;
  int i = 0;
  while (ch != '\n')
  {
    if (client.available())
      {ch = client.read();
      line1[i] = ch;
      i ++;}
  } //end while (ch != '\n')
  line1[i] = '\0';

}


boolean pageNameIs(char* name)
{
  // page name starts at char pos 4
  // ends with space
  int i = 4;
  char ch = line1[i];
  
  while (ch != ' ' && ch != '\n' && ch != '?')
  {
    if (name[i - 4] != line1[i])
    {
      return false;
    }
    i ++;
    ch = line1[i];
  }
  return true;
}


Re: Ethermega stops

Posted: Mon Mar 14, 2016 9:54 pm
by andrew
How are you powering the EtherMega? What voltage/current?

Re: Ethermega stops

Posted: Tue Mar 15, 2016 12:54 am
by regis
9volts @ 1A

Re: Ethermega stops

Posted: Tue Mar 15, 2016 8:26 am
by andrew
An option would be to have an external watchdog circuit, which can reset the board if it locks up after say one minute or five.
This can be done with a 555-timer based circuit such as that used on the Watchdog module:
http://www.freetronics.com.au/collectio ... mer-module

Re: Ethermega stops

Posted: Tue Mar 15, 2016 4:23 pm
by regis
Is this board that unstable that it requires a watchdog timer to keep it running?
My Ethermega runs for several hours or even several days and then it freezes. When it freezes I can ping it OK, a depression of the reset button does no good, the only remedies are (1) a power cycle or (2) reloading of the same program.
I’ve tried several solution and then out of desperation I changed the IP address from 192.168.1.30 to 192.168.1.177 and it has been running now for two days. Prior to this change I couldn’t get more than 20 hours of run time. Won’t know the real results for several more days.
I looked at the IP client list in my router and couldn’t find any reason that 192.168.1.30 should fail.
Frankly I’m lost
Can you help???

Re: Ethermega stops

Posted: Wed Mar 16, 2016 10:40 pm
by andrew
If the different IP is working then go with that, I can't see why .30 would give you problems.

Re: Ethermega stops

Posted: Sun Sep 11, 2016 1:26 am
by bigd003
Just a random thought, but what would happen if another device, like a mobile tried to access with an IP that matched .30, could that disrupt anything?

Re: Ethermega stops

Posted: Mon May 01, 2017 1:51 am
by sky
^^ DHCP would assign a different IP to a connecting mobile device.

I am having similar issues with my sketch and my EM. My EM is connected to the web through an app called Blynk. Every 2 seconds the EM samples an RTC and sends the time as a String to the Blynk server and subsequently to my smart phone. After about 3 days or less, the time transmissions either freeze, or the data is corrupted and the readings are numerical giberish. Someone on the Arduino forum pointed out to me that String is likely causing the MCU to lock up. I adjusted my sketch to convert the time data to "strings" and hopefully this holds up. I'll repost if I experience another failure.