I'm having a very strange problem. I have a Tian that is programmed to send out sensor data to a server every x seconds. My program run well but after 14,15 hours of operation it stops working and I don't receive datas. The program is fast at the beginning, then after 2 to 3 hours before stopping, it becomes more and more slow with the message "timeout".

I think maybe a misuse of the Ciao library on my part could be at the root of the problem. Or maybe a modification at the program level could correct the problem. So if I can have some help about this.. (the problem doesn't come from the use of String, I have already tested use of array with cstrings and it doesn't work).

Here is the part of the program that I think is problematic (there is another CiaoReadWrite nearly similar to the first) :

void CiaoReadWrite1() { CiaoData data = Ciao.read("restserver");
if (!data.isEmpty())
  String id = data.get(0);
  String sender = data.get(1);
  String message = data.get(2);


  gen            =LtT2[0].toInt(); LtT2[0]="";
  belt           =LtT2[1].toInt(); LtT2[1]="";
  genReady       =LtT2[2].toInt(); LtT2[2]="";
  hvOnOff        =LtT2[3].toInt(); LtT2[3]="";
  beep           =LtT2[4].toInt(); LtT2[4]="";
  heart1         =LtT2[5].toInt(); LtT2[5]="";
  sendConf       =LtT2[6].toInt(); LtT2[6]="";
  heart2FB       =LtT2[7].toInt(); LtT2[7]="";

  beepFB         =beep;
  heart1FB       =heart1;
  sendConfFB     =sendConf;

  Ciao.writeResponse("restserver",id, String(baroAlti*100)+"="+baroHumi*10+"="+baroPres+"="+baroTemp*10+"="+beepFB+"="+heart1FB+"="+heart2+"="+sendConfFB+"="+



You're using the String (upper-case 'S') functions, which allocate and de-allocate memory, a limited commodity, even with 64K. The standard heap management functions will tend to fragment the heap into pieces too small for further use. That can make new allocations slower because the heap has to be searched for a big-enough piece, and can eventually make it the heap grow toward the stack, until a collision (something gets overwritten) inevitable. We can't say for sure that this is your problem; we don't have enough information.

But try allocating one or a few buffers large enough for the worst case requirement, and use the C string functions instead (lower-case 's'), sprintf(), strcpy(), strcat(), etc. instead.


Well, if your program works some time and stops, the first thing you have to check is if there's some variable entering in overflow. Maybe some variable is concatenating and after some time it goes overflow. I haven't check your code or the lib, because that is a common problem and already happened with me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.