Ethernet lockups/freezes/non responsive


i having trouble ethernet becoming non responsive after period of time ranging few hours day or more.  the hardware arduino mega 2560 r3 ethernet shield.  i using previous generation of ethernet shield , bought new shield resolve issue problem remains. using windows 7 ide = 1.0.5 .  i have searched  the forum many hours cant seem find solution.  ive found many people seemingly same problem no concrete solution. posting complete code sketch in hope see cause issue.  the sketch rather long , gives me exact info need when not locked up. ethernet stuff near end of sketch.  i have no formal training in c programming see code works. if more info needed please let me know. oh...the url http://67.231.227.82:8250/  i have post code in 2 posts exceeds 9500 character count.
code: [select]
#include <onewire.h>
#include <dallastemperature.h>
#include <spi.h>
#include <ethernet.h>
#include <sensirion.h>
#include <wire.h>
#include "rtclib.h"  // date , time functions using chronodot rtc connected via i2c , wire lib
#include "arduino.h"
#include <xbee.h>

long lasttime ;  //for calculating xbee packet times
long elapsedtime;  //for calculating xbee packet times

xbee xbee = xbee();
xbeeresponse response = xbeeresponse();
// create reusable response objects responses expect handle
zbrxresponse rx = zbrxresponse();
modemstatusresponse msr = modemstatusresponse();
int modemstatus = 0;
uint8_t point_identifier = 0;

byte mac[] = {
 0x90, 0xa2, 0xda, 0x0e, 0x93, 0xb1 };
byte ip[] = {
 192, 168, 1, 125 };
byte gateway[] = {
 192, 168, 1, 1 };
byte subnet[] = {
 255, 255, 255, 0 };

ethernetclient client;

ethernetserver monserver(8250);  
rtc_ds1307 rtc;

onewire outside_air_temp_bus (2) ; // data wire plugged pin 2  on arduino
onewire entering_water_temp_bus (3) ; // data wire plugged pin 3 on arduino
onewire discharge_air_temp_bus (9) ;
onewire dx_suction_temp_bus (a3) ;

deviceaddress tempdeviceaddress;

dallastemperature outside_air_temp (&outside_air_temp_bus) ;
dallastemperature entering_water_temp (&entering_water_temp_bus) ;
dallastemperature discharge_air_temp (&discharge_air_temp_bus) ;
dallastemperature dx_suction_temp (&dx_suction_temp_bus) ;

unsigned long lasttemprequest = 0;
int  delayinmillis = 0;
int  idle = 0;

float oat = 0.00 ; //outside air temp temperature
float ewt = 0.00; //boiler water temp entering house
float hwt = 0.00 ; //highest water temperature
float lwt = 0.00 ; //lowest water temperature
float dat = 0.00 ; //discharge air temperature
float dslt = 0.00 ; //dx suction line temperature
float lastewt = 0.00;  //variable ewt sanity check
int ec ; //sensor error count
long numreadings ; //number of time ewt sensor read
float temp_f = 0.00; //sht15 temp
float temp_c = 0.00;
float humidity = 0.00; //sht15 humidity
unsigned long last_read_sht = millis();
unsigned long max_sht_time = 5000;
unsigned long num_sht_reads = 0;
float max_dat = 0.00;  //maximum discharge air temperature
float owb_oat = 0.00;   //outside aie temp @ owb
float owb_dwt = 0.00;  // discharge water temp @ owb
float owb_temp_house_difference = 0.00; // difference in water temp between owb , temp in house

//variables pool controller via xbee
float owb_supply_temp = 0.0;
float owb_return_temp = 0.0;
float pool_unheated_temp = 0.0;
float pool_heated_temp = 0.0;

int sd_deselect = 4;

const int rtstatpin = 5; //r (power) tstat
const int ytstatpin = 6; //y (cooling) tstat
const int wtstatpin = 7; //w (heating) tstat
const int gtstatpin = 8; //g (fan) tstat
const int blowerrunning = a2; //blower running

const byte datapin =  16;                 // shtxx serial data
const byte sclkpin =  17;                 // shtxx serial clock
const unsigned long trhstep   = 5000ul;  // sensor query period

sensirion sht = sensirion(datapin, sclkpin);
unsigned int rawdata;
byte measactive = false;
byte meastype = temp;
unsigned long trhmillis = 0;             // time interval tracking

void setup()
{
 // start serial port
 serial.begin(9600);
 serial1.begin(9600);  // start xbee serial port

 xbee.setserial(serial1);     // hook xbee serial1 serial port
 serial.println(" home  monitor");

 pinmode(sd_deselect, output);
 digitalwrite(sd_deselect, high); //initialize pool relay 'not heating'

 pinmode(rtstatpin, input);
 pinmode(ytstatpin, input);
 pinmode(wtstatpin, input);
 pinmode(gtstatpin, input);
 pinmode(blowerrunning, input);
 pinmode(a3, input);

 // turn on internal pullup resistors fot tstat inputs
 digitalwrite(rtstatpin, high);
 digitalwrite(ytstatpin, high);
 digitalwrite(wtstatpin, high);
 digitalwrite(gtstatpin, high);
 digitalwrite(blowerrunning, high);

 // start librarys
 //set ds18b20 resolution 12 bit
 outside_air_temp.begin();
 outside_air_temp.getaddress(tempdeviceaddress, 0);
 outside_air_temp.setresolution(tempdeviceaddress, 12);
 entering_water_temp.begin();
 entering_water_temp.getaddress(tempdeviceaddress, 0);
 entering_water_temp.setresolution(tempdeviceaddress, 12);
 discharge_air_temp.begin();
 discharge_air_temp.getaddress(tempdeviceaddress, 0);
 discharge_air_temp.setresolution(tempdeviceaddress, 12);
 dx_suction_temp.begin();
 dx_suction_temp.getaddress(tempdeviceaddress, 0);
 dx_suction_temp.setresolution(tempdeviceaddress, 12);

 outside_air_temp.setwaitforconversion(false);
 outside_air_temp.requesttemperatures();
 entering_water_temp.setwaitforconversion(false);
 entering_water_temp.requesttemperatures();
 discharge_air_temp.setwaitforconversion(false);
 discharge_air_temp.requesttemperatures();
 dx_suction_temp.setwaitforconversion(false);
 dx_suction_temp.requesttemperatures();

 delayinmillis = 5000 ;
 lasttemprequest = millis();
 delay(750);

 ethernet.begin(mac, ip, gateway, subnet);
 monserver.begin();


 wire.begin();
 rtc.begin();

 //initalize hwt , lwt current entering water pemperature
 ewt = entering_water_temp.gettempfbyindex(0);
 dat = discharge_air_temp.gettempfbyindex(0);
 dslt = dx_suction_temp.gettempfbyindex(0);

 //initalize hwt , lwt current entering water pemperature
 hwt = ewt;
 lwt = ewt;
 lastewt = ewt;

 ec = 0 ;
 numreadings = 0 ;
}



//see next post

more of code
code: [select]
void loop()
{

 // xbee stuff


 xbee.readpacket();
 // read above set available to
 // work when check it.
 if (xbee.getresponse().isavailable()) {
   if (xbee.getresponse().getapiid() == zb_rx_response) {
     // got zb rx packet, kind code looking for
     // know it's receive packet
     // fill in values
     xbee.getresponse().getzbrxresponse(rx);
     point_identifier = rx.getdata(0);
     serial.print("point indentifier = ");
     serial.println(point_identifier);

     switch(point_identifier)
     {
     case 2:     //outdoor wood boiler (owb) xbee

       union {
         float f;
         byte b[4];
       }
       oat;

       union {
         float h;
         byte b[4];
       }
       dwt;


       serial.print("point identifier = ");
       serial.println(rx.getdata(0));

       oat.b[0] = rx.getdata(1);
       oat.b[1] = rx.getdata(2);
       oat.b[2] = rx.getdata(3);
       oat.b[3] = rx.getdata(4);
       serial.print("outside_air_temp = ");
       serial.println(oat.f);
       owb_oat = oat.f;

       dwt.b[0] = rx.getdata(5);
       dwt.b[1] = rx.getdata(6);
       dwt.b[2] = rx.getdata(7);
       dwt.b[3] = rx.getdata(8);

       serial.print("discharge_water_temp = ");
       serial.println(dwt.h);
       owb_dwt = dwt.h;
       lasttime = millis();
       break;

     case 3:    //pool xbee
       union {
         float f;
         byte b[4];
       }
       owb_supply_t;
       owb_supply_t.b[0] = rx.getdata(1);
       owb_supply_t.b[1] = rx.getdata(2);
       owb_supply_t.b[2] = rx.getdata(3);
       owb_supply_t.b[3] = rx.getdata(4);
       serial.print("owb supply temp = ");
       serial.println(owb_supply_t.f);
       owb_supply_temp = owb_supply_t.f;

       union {
         float f;
         byte b[4];
       }
       owb_return_t;
       owb_return_t.b[0] = rx.getdata(5);
       owb_return_t.b[1] = rx.getdata(6);
       owb_return_t.b[2] = rx.getdata(7);
       owb_return_t.b[3] = rx.getdata(8);
       serial.print("owb return temp = ");
       serial.println(owb_return_t.f);
       owb_return_temp = owb_return_t.f;

       union {
         float f;
         byte b[4];
       }
       pool_unheated_t;
       pool_unheated_t.b[0] = rx.getdata(9);
       pool_unheated_t.b[1] = rx.getdata(10);
       pool_unheated_t.b[2] = rx.getdata(11);
       pool_unheated_t.b[3] = rx.getdata(12);
       serial.print("pool unheated temp = ");
       serial.println(pool_unheated_t.f);
       pool_unheated_temp = pool_unheated_t.f;

       union {
         float f;
         byte b[4];
       }
       pool_heated_t;
       pool_heated_t.b[0] = rx.getdata(13);
       pool_heated_t.b[1] = rx.getdata(14);
       pool_heated_t.b[2] = rx.getdata(15);
       pool_heated_t.b[3] = rx.getdata(16);
       serial.print("pool heated temp = ");
       serial.println(pool_heated_t.f);
       pool_heated_temp = pool_heated_t.f;
       break;

     default :
       serial.print(point_identifier);
       serial.println("was received not expected");
       break;
     }
   }
   else if (xbee.getresponse().getapiid() == modem_status_response) {
     modemstatus = modemstatus + 1;  //increment modemstatus counter
     xbee.getresponse().getmodemstatusresponse(msr);
     // local xbee sends response on events, association/dissociation
     //main thing msg out of serial buffer..i think.. fr
     if (msr.getstatus() == associated) {
       // yay great.  
       //do nothing
     }
     else if (msr.getstatus() == disassociated) {
       // awful..
       //do nothing
     }
     else {
       // status
       //do nothing
     }
   }
 }
 // end xbee stuff

 if (millis() - lasttemprequest >= delayinmillis) // waited long enough??
 {
   oat = outside_air_temp.gettempfbyindex(0);
   ewt = entering_water_temp.gettempfbyindex(0);
   dat = discharge_air_temp.gettempfbyindex(0);
   dslt = dx_suction_temp.gettempfbyindex(0);
   numreadings = numreadings + 1 ;

   // after fetching temperature request new sample
   // in async modus

   outside_air_temp.requesttemperatures();
   entering_water_temp.requesttemperatures();
   discharge_air_temp.requesttemperatures();
   dx_suction_temp.requesttemperatures();

   lasttemprequest = millis();
 }

 // begin sht non-blocking
 unsigned long curmillis = millis();          // current time
 if (curmillis - trhmillis >= trhstep) {      // time new measurements?
   measactive = true;
   meastype = temp;
   sht.meas(temp, &rawdata, nonblock);        // start temp measurement
   trhmillis = curmillis;
 }
 if (measactive && sht.measrdy()) {           // check measurement status
   if (meastype == temp) {                    // process temp or humi?
     meastype = humi;
     temp_c = sht.calctemp(rawdata);     // convert raw sensor data
     temp_f = (temp_c * 9.0)/5.0 + 32.0;
     sht.meas(humi, &rawdata, nonblock);      // start humi measurement
   }
   else {
     measactive = false;
     humidity = sht.calchumi(rawdata, temp_f); // convert raw sensor data
     // dewpoint = sht.calcdewpoint(humidity, temperature);
   }
 }

 //set high (hwt) , low (lwt) water temperatures
 if ((ewt > lastewt + 1.0) || (ewt < lastewt - 1.0))  //ewt sanity check
 {
   ec = ec + 1;
 }  //increment error counter
 else {
   if (ewt > hwt)
   {
     hwt = ewt;
   }
   if (ewt < lwt)
   {
     lwt = ewt;
   }
   lastewt = ewt;
 }
 if (dat > max_dat) {
   max_dat = dat;
 }



Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > Ethernet lockups/freezes/non responsive


arduino

Comments

Popular posts from this blog

Rasperry Wifi LAN Controller - Raspberry Pi Forums

Convierte tu Raspberry en un NAS. Firmware fvdw-sl 15.3 - Raspberry Pi Forums

Unlock car with bluetooth and car key