program freezing

Hi,

I am a beginner with Arduino but have experience programming for the PC. I am trying to build a simple data logger over Ethernet.
I am using the Arduino Ethernet shield with Arduino Uno SMD Edition.

The program setups a server waiting for a client to connect. The client is Hyperterminal on Windows XP machine. I am using Hyperterminal TCP/IP connection.

The program sends a NTP request to get synchronized to our network clock. Then every minute it sends data to Hyperterminal.
It works fine for about 20 minutes and then it freezes. The connection from Hyperterminal to the Ethernet shield is not lost but program stops sending data. I have to reset the Arduino to start again.

I plan to use this to log data from various sensors and I want to leave it running at least 24 hours. If the Arduino is freezing for no reason, I would not be able to use it.

The sketch file is attached to this message.

Could any one more experienced with Arduino provide advise?

datalogger3.ino (5.56 KB)

Hi,

Just to update my posting, I have found a solution. It is the WatchDog Timer of the ATMega.

I found an explanation of this feature at this link:
http://tushev.org/articles/electronics/48-arduino-and-watchdog-timer

I have managed to use it and it works.

Although the watchdog reset will mask your problem, it doesn't solve it. My guess is that this is the cause:

String getTimeString() {
  time_t t = now();  
  String s = "";  
  if (hour(t) <10) s = s + "0";  
  s = s + hour(t) + ":";  
  if (minute(t) <10) s = s + "0";  
  s = s + minute(t) + ":";  
  if (second(t) <10) s = s + "0";  
  s = s + second(t);  
  return(s);  
}  
  
// gives back dd/mm/yyyy   
String getDateString() {  
  time_t t = now();  
  String s = "";  
  if (day(t) <10) s = s + "0";  
  s = s + day(t) + "/";  
  if (month(t) <10) s = s + "0";  
  s = s + month(t) + "/";  
  s = s + year(t);  
  return(s);    
}

Using the String class, particularly in that way, will cause memory fragmentation problems, and you will eventually run out of free memory, overwrite the stack, and crash.