Timeout and overflow of arduino

Unfortunately, it's been a while since I have a problem: my program works well but after sometimes 7 8 hours or another day 14 15 hours of operation it stops working and I don't receive datas. (I use Arduino TIAN).

So I think the problem comes from the communication between Linux and microcontroller. I think it is something like overflow. I tested by using cstrings - char arrays (with /0 terminat) but it doesn't resolve the problem.

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 receive datas on Laview).

Is the old data remained in the memory (or archived) and therefore eat the memory? A purge problem?
How can I erase old datas of memory ?

Thanks.

Dynamic memory problem?

Arduinos memory handling is far from perfect.
I'd rewrite to use all global , fixed size, variables

Do you think that it might help if you posted the code that you have a problem with ?

Here is the first part of my program:

#include <Ciao.h>
#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme;

//Variablen Tian nach Labview

String TtL[48];

float baroAlti     =0; // 0, Stelle,
float baroHumi     =0; // 1, Stelle,     
float baroPres     =0; // 2, Stelle,
float baroTemp     =0; // 3, Stelle,
int beepFB         =0; // 4, Stelle,
int beltStat1      =0; // 5, Stelle,
int beltStat2      =0; // 6, Stelle,
int beltStat3      =0; // 7, Stelle,
int beltStat4      =0; // 8, Stelle,
int charIMeas      =0; // 9, Stelle,
int charTimeEl     =0; // 10, Stelle,
int charUfin1      =0; // 11, Stelle,
int charUMeas      =0; // 12, Stelle,
int charUZero1     =0; // 13, Stelle,
int charUZero2     =0; // 14, Stelle,
int fsMeas         =0; // 15, Stelle,
int genReadyFB     =0; // 16, Stelle,
int gndSwGnd       =0; // 17, Stelle,
int gndSwUGnd      =0; // 18, Stelle,
long heart2        =0; // 19, Stelle,
int hs1Stat        =0; // 20, Stelle,
int hs2Stat        =0; // 21, Stelle,
int hs3Stat        =0; // 22, Stelle,
int hvOnOffFB      =0; // 23, Stelle,
int mafsMeas       =0; // 24, Stelle,
int polFbMed       =0; // 25, Stelle,
int polFbNeg       =0; // 26, Stelle,
int polFbPos       =0; // 27, Stelle,
int secCust1       =0; // 28, Stelle,
int secCust2       =0; // 29, Stelle,
int secEmrgSW      =0; // 30, Stelle,
int secloop        =0; // 31, Stelle,
int secLoop1       =0; // 32, Stelle,   
int secLoop2       =0; // 33, Stelle,
int statusA1       =0; // 34, Stelle,
int statusA2       =0; // 35, Stelle,
int statusA3       =0; // 36, Stelle,   
int timehours      =0; // 37, Stelle,
int timetemp       =0; // 38, Stelle,
int trigFB         =0; // 39, Stelle,
int trigDone       =0; // 40, Stelle,
int voltMeasM      =0; // 41, Stelle,
int voltMeasT      =0; // 42, Stelle,
int msg            =0; // 43, Stelle,
int lockwarn       =0; // 44, Stelle,
int debug          =0; // 45, Stelle,
long timeDS        =0; // 46, Stelle,

//Variablen Labview nach Tian

String LtT[62];

int beep           =0; // 0, Stelle,
int beepvolt       =0; // 1, Stelle,     
int belt           =0; // 2, Stelle,
int charIRamp1     =0; // 3, Stelle,
int charIRamp2     =0; // 4, Stelle,
int charISet       =0; // 5, Stelle,
int charTime       =0; // 6, Stelle,
int charURamp1     =0; // 7, Stelle,
int charURamp2     =0; // 8, Stelle,
int charUSet       =0; // 9, Stelle,
int fs             =0; // 10, Stelle,
int fsAuto         =0; // 11, Stelle,
int fsHyst         =0; // 12, Stelle,
int fsIncMax       =0; // 13, Stelle,
int fsIncMin       =0; // 14, Stelle,
int fsMin          =0; // 15, Stelle,
int fsPlus         =0; // 16, Stelle,
int fsSet          =0; // 17, Stelle,
int gen            =0; // 18, Stelle,
int genConf        =0; // 19, Stelle,
int genReady       =0; // 20, Stelle,
int heart1         =0; // 21, Stelle,
int hvOnOff        =0; // 22, Stelle,
int lockAct1       =0; // 23, Stelle,
int lockAct2       =0; // 24, Stelle,
int lockAct3       =0; // 25, Stelle,
int lockAct4       =0; // 26, Stelle,
int lockAct5       =0; // 27, Stelle,
int lockAct6       =0; // 28, Stelle,
int lockDate1      =0; // 29, Stelle,
int lockDate2      =0; // 30, Stelle,
int lockDate3      =0; // 31, Stelle,   
int lockDate4      =0; // 32, Stelle,
int lockDate5      =0; // 33, Stelle,
int lockDate6      =0; // 34, Stelle,
int lockImp        =0; // 35, Stelle,   
int lockImpA       =0; // 36, Stelle,
int lockTime       =0; // 37, Stelle,
int lockTimA       =0; // 38, Stelle,
int mafs           =0; // 39, Stelle,
int mafsAuto       =0; // 40, Stelle,
int mafsHyst       =0; // 41, Stelle,
int mafsIncMax     =0; // 42, Stelle,
int mafsIncMin     =0; // 43, Stelle,
int mafsMin        =0; // 44, Stelle,
int mafsPlus       =0; // 45, Stelle,
int mafsSet        =0; // 46, Stelle,
int mafsTime       =0; // 47, Stelle,
int pol            =0; // 48, Stelle,
int shunt          =0; // 49, Stelle,
int trig           =0; // 50, Stelle,
int trigPhaOn      =0; // 51, Stelle,
int trigPhase      =0; // 52, Stelle,
int voltOver       =0; // 53, Stelle,
int voltOver1      =0; // 54, Stelle,
int voltOverEx     =0; // 55, Stelle,
int trigAuto       =0; // 56, Stelle,
int timeInst       =0; // 57, Stelle,
int trigtemp       =0; // 58, Stelle,
int timegnd        =0; // 59, Stelle,
int DcImp          =0; // 60, Stelle,

//another

int beltUGnd=0;
long previousMillis05     =0;
long previousMillis1      =0;
long previousMillis2      =0;
long previousMillis1800   =0;

void setup()
{
  Wire.begin();
  Ciao.begin();
  bme.begin();
  PinSetup();
 
  baroAlti =  bme.readAltitude(SEALEVELPRESSURE_HPA);
  baroHumi =  bme.readHumidity();
  baroPres =  bme.readPressure();
  baroTemp =  bme.readTemperature();
   
  digitalWrite(13, HIGH);
 
}

void loop()
{
    if (millis() - previousMillis05 > 500)
    {
      previousMillis05 = millis();
    }
   
    if (millis() - previousMillis1 > 1000)
    {
      previousMillis1 = millis();
      digitalWrite(13, LOW);
    }
   
    if (millis() - previousMillis2 > 2000)
    {
      previousMillis2 = millis();
   
      baroAlti =  bme.readAltitude(SEALEVELPRESSURE_HPA);
      baroHumi =  bme.readHumidity();
      baroPres =  bme.readPressure();
      baroTemp =  bme.readTemperature();
      digitalWrite(13, HIGH);
     
      CiaoReadWrite();
    }
   
    if (millis() - previousMillis1800 > 10000)
    {
      previousMillis1800 = millis();
    }
   
    if (beep==1) digitalWrite(11, HIGH);
    if (beep==0) digitalWrite(11, LOW);
   
   
}

And finally the second part:

void CiaoReadWrite()
{
   CiaoData data = Ciao.read("restserver");
   if(!data.isEmpty())
   {
       String id = data.get(0);
       String sender = data.get(1);
       String message = data.get(2);
       //message.toUpperCase();
       
       String LtT[62];
       splitString(message,"=",LtT,62);
       
       beep         =LtT[0].toInt();
       beepvolt     =LtT[1].toInt();
       heart1       =LtT[5].toInt();
       heart2       =heart1;
       
       
       TtL[0]=String(baroAlti*100);
       TtL[1]=String(baroHumi*10);
       TtL[2]=String(baroPres);
       TtL[3]=String(baroTemp*10);
       
       TtL[5]=String(heart2);
       TtL[6]=id;
       TtL[7]=String(beepvolt);        
       
       Ciao.writeResponse("restserver",id, TtL[0]+"="+TtL[1]+"="+TtL[2]+"="+TtL[3]+"="+TtL[4]+"="+TtL[5]+"="+TtL[6]+"="+TtL[7]+"=");
    }
}

void PinSetup()
{
 // Pind als digital Output
 
 pinMode(0, OUTPUT);
 pinMode(1, OUTPUT);
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);
 pinMode(12, OUTPUT);
 pinMode(13, OUTPUT);
 
 // Pins als digital Input
 
 pinMode(5, INPUT);
 pinMode(6, INPUT);
 
 // Pins als Analog Output
 
 //keine/ none
 
 //Pins als Analog Input

 // A00
 // A01
 // A02
 // A03
 // A04
 // A05

}

Try more Use of String class!

Don’t they have arrays where you’re from?

If you post your entire code, we may see something obvious.
(Like using Strings)

Oops - missed those while typing!

Use </> code tags!

BulldogLowell:
Try more Use of String class!

Don’t they have arrays where you’re from?

They do use array of String though.

arduino_new:
They do use array of String though.

It depends on your definition of “use”.

Like many of all those global...

Find a freeMemory() function. There are many available online.

Make it print the free memory once a minute or something. If you're running out of memory, you will see this easily. Then try cutting out functions until the memory stops disappearing - the last one you cut is the one with the problem.

It's never necessary to use big-S Strings, although they do make certain functions easier.

What everyone else said. Don't use the C++ String class, use c-strings ('\0' terminated arrays of char).

Can I have an example of the use of cstring - char arrays (with '\0' terminated). I will change string into cstring - char arrays but I don't know how to do it. It will be very helpful if i can have several examples.

(I use Arduino TIAN)

A string (note small s) is a cstring or null terminated character array. To convert a String (big S) to a cstring you can use the toCharArray() function.

hakan24:
Can I have an example of the use of cstring - char arrays (with '\0' terminated). I will change string into cstring - char arrays but I don't know how to do it. It will be very helpful if i can have several examples.

(I use Arduino TIAN)

Are you asking about converting a String to a string? You go first. You post the code that wastes resources using a String. and we'll help you understand how not to do that.

Here is the first part of my program:

#include <Ciao.h>
#include <Arduino.h>
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BME280 bme;

//Variablen Tian nach Labview

String TtL[48];

float baroAlti     =0; // 0, Stelle,
float baroHumi     =0; // 1, Stelle,    
float baroPres     =0; // 2, Stelle,
float baroTemp     =0; // 3, Stelle,
int beepFB         =0; // 4, Stelle,
int beltStat1      =0; // 5, Stelle,
int beltStat2      =0; // 6, Stelle,
int beltStat3      =0; // 7, Stelle,
int beltStat4      =0; // 8, Stelle,
int charIMeas      =0; // 9, Stelle,
int charTimeEl     =0; // 10, Stelle,
int charUfin1      =0; // 11, Stelle,
int charUMeas      =0; // 12, Stelle,
int charUZero1     =0; // 13, Stelle,
int charUZero2     =0; // 14, Stelle,
int fsMeas         =0; // 15, Stelle,
int genReadyFB     =0; // 16, Stelle,
int gndSwGnd       =0; // 17, Stelle,
int gndSwUGnd      =0; // 18, Stelle,
long heart2        =0; // 19, Stelle,
int hs1Stat        =0; // 20, Stelle,
int hs2Stat        =0; // 21, Stelle,
int hs3Stat        =0; // 22, Stelle,
int hvOnOffFB      =0; // 23, Stelle,
int mafsMeas       =0; // 24, Stelle,
int polFbMed       =0; // 25, Stelle,
int polFbNeg       =0; // 26, Stelle,
int polFbPos       =0; // 27, Stelle,
int secCust1       =0; // 28, Stelle,
int secCust2       =0; // 29, Stelle,
int secEmrgSW      =0; // 30, Stelle,
int secloop        =0; // 31, Stelle,
int secLoop1       =0; // 32, Stelle,  
int secLoop2       =0; // 33, Stelle,
int statusA1       =0; // 34, Stelle,
int statusA2       =0; // 35, Stelle,
int statusA3       =0; // 36, Stelle,  
int timehours      =0; // 37, Stelle,
int timetemp       =0; // 38, Stelle,
int trigFB         =0; // 39, Stelle,
int trigDone       =0; // 40, Stelle,
int voltMeasM      =0; // 41, Stelle,
int voltMeasT      =0; // 42, Stelle,
int msg            =0; // 43, Stelle,
int lockwarn       =0; // 44, Stelle,
int debug          =0; // 45, Stelle,
long timeDS        =0; // 46, Stelle,

//Variablen Labview nach Tian

String LtT[62];

int beep           =0; // 0, Stelle,
int beepvolt       =0; // 1, Stelle,    
int belt           =0; // 2, Stelle,
int charIRamp1     =0; // 3, Stelle,
int charIRamp2     =0; // 4, Stelle,
int charISet       =0; // 5, Stelle,
int charTime       =0; // 6, Stelle,
int charURamp1     =0; // 7, Stelle,
int charURamp2     =0; // 8, Stelle,
int charUSet       =0; // 9, Stelle,
int fs             =0; // 10, Stelle,
int fsAuto         =0; // 11, Stelle,
int fsHyst         =0; // 12, Stelle,
int fsIncMax       =0; // 13, Stelle,
int fsIncMin       =0; // 14, Stelle,
int fsMin          =0; // 15, Stelle,
int fsPlus         =0; // 16, Stelle,
int fsSet          =0; // 17, Stelle,
int gen            =0; // 18, Stelle,
int genConf        =0; // 19, Stelle,
int genReady       =0; // 20, Stelle,
int heart1         =0; // 21, Stelle,
int hvOnOff        =0; // 22, Stelle,
int lockAct1       =0; // 23, Stelle,
int lockAct2       =0; // 24, Stelle,
int lockAct3       =0; // 25, Stelle,
int lockAct4       =0; // 26, Stelle,
int lockAct5       =0; // 27, Stelle,
int lockAct6       =0; // 28, Stelle,
int lockDate1      =0; // 29, Stelle,
int lockDate2      =0; // 30, Stelle,
int lockDate3      =0; // 31, Stelle,  
int lockDate4      =0; // 32, Stelle,
int lockDate5      =0; // 33, Stelle,
int lockDate6      =0; // 34, Stelle,
int lockImp        =0; // 35, Stelle,  
int lockImpA       =0; // 36, Stelle,
int lockTime       =0; // 37, Stelle,
int lockTimA       =0; // 38, Stelle,
int mafs           =0; // 39, Stelle,
int mafsAuto       =0; // 40, Stelle,
int mafsHyst       =0; // 41, Stelle,
int mafsIncMax     =0; // 42, Stelle,
int mafsIncMin     =0; // 43, Stelle,
int mafsMin        =0; // 44, Stelle,
int mafsPlus       =0; // 45, Stelle,
int mafsSet        =0; // 46, Stelle,
int mafsTime       =0; // 47, Stelle,
int pol            =0; // 48, Stelle,
int shunt          =0; // 49, Stelle,
int trig           =0; // 50, Stelle,
int trigPhaOn      =0; // 51, Stelle,
int trigPhase      =0; // 52, Stelle,
int voltOver       =0; // 53, Stelle,
int voltOver1      =0; // 54, Stelle,
int voltOverEx     =0; // 55, Stelle,
int trigAuto       =0; // 56, Stelle,
int timeInst       =0; // 57, Stelle,
int trigtemp       =0; // 58, Stelle,
int timegnd        =0; // 59, Stelle,
int DcImp          =0; // 60, Stelle,

//another

int beltUGnd=0;
long previousMillis05     =0;
long previousMillis1      =0;
long previousMillis2      =0;
long previousMillis1800   =0;

void setup()
{
  Wire.begin();
  Ciao.begin();
  bme.begin();
  PinSetup();
 
  baroAlti =  bme.readAltitude(SEALEVELPRESSURE_HPA);
  baroHumi =  bme.readHumidity();
  baroPres =  bme.readPressure();
  baroTemp =  bme.readTemperature();
  
  digitalWrite(13, HIGH);
 
}

void loop()
{
    if (millis() - previousMillis05 > 500)
    {
      previousMillis05 = millis();
    }
  
    if (millis() - previousMillis1 > 1000)
    {
      previousMillis1 = millis();
      digitalWrite(13, LOW);
    }
  
    if (millis() - previousMillis2 > 2000)
    {
      previousMillis2 = millis();
  
      baroAlti =  bme.readAltitude(SEALEVELPRESSURE_HPA);
      baroHumi =  bme.readHumidity();
      baroPres =  bme.readPressure();
      baroTemp =  bme.readTemperature();
      digitalWrite(13, HIGH);
    
      CiaoReadWrite();
    }
  
    if (millis() - previousMillis1800 > 10000)
    {
      previousMillis1800 = millis();
    }
  
    if (beep==1) digitalWrite(11, HIGH);
    if (beep==0) digitalWrite(11, LOW);
  
  
}

You don't have A String. You have 48 of them. Plus 62 of them.

In the code you posted, you don't need ANY of them.

And the second part of the program:

void CiaoReadWrite()
{
   CiaoData data = Ciao.read("restserver");
   if(!data.isEmpty())
   {
       String id = data.get(0);
       String sender = data.get(1);
       String message = data.get(2);
       //message.toUpperCase();
       
       String LtT[62];
       splitString(message,"=",LtT,62);
       
       beep         =LtT[0].toInt();
       beepvolt     =LtT[1].toInt();
       heart1       =LtT[5].toInt();
       heart2       =heart1;
       
       
       TtL[0]=String(baroAlti*100);
       TtL[1]=String(baroHumi*10);
       TtL[2]=String(baroPres);
       TtL[3]=String(baroTemp*10);
       
       TtL[5]=String(heart2);
       TtL[6]=id;
       TtL[7]=String(beepvolt);       
       
       Ciao.writeResponse("restserver",id, TtL[0]+"="+TtL[1]+"="+TtL[2]+"="+TtL[3]+"="+TtL[4]+"="+TtL[5]+"="+TtL[6]+"="+TtL[7]+"=");
    }
}

void PinSetup()
{
 // Pind als digital Output
 
 pinMode(0, OUTPUT);
 pinMode(1, OUTPUT);
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(10, OUTPUT);
 pinMode(11, OUTPUT);
 pinMode(12, OUTPUT);
 pinMode(13, OUTPUT);
 
 // Pins als digital Input
 
 pinMode(5, INPUT);
 pinMode(6, INPUT);
 
 // Pins als Analog Output
 
 //keine/ none
 
 //Pins als Analog Input

 // A00
 // A01
 // A02
 // A03
 // A04
 // A05

}

STOP posting snippets. Use the Reply button and the Additional Options link that appears below the text field, and attach your code AS ONE FILE.

There is NOTHING in the code that NEEDS to use Strings. You have embedded all the dependencies on the String class. You can get rid of them, but it is NOT going to be a matter of waving a magic wand and making them go away.

You have some undefined splitString() method that populates an array of Strings. It could just as easily populate an array of strings.

PaulS:
STOP posting snippets. Use the Reply button and the Additional Options link that appears below the text field, and attach your code AS ONE FILE.

There is NOTHING in the code that NEEDS to use Strings. You have embedded all the dependencies on the String class. You can get rid of them, but it is NOT going to be a matter of waving a magic wand and making them go away.

You have some undefined splitString() method that populates an array of Strings. It could just as easily populate an array of strings.

I have a problem: my program works well but after sometimes 7 8 hours or another day 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 receive datas on Laview).

How can I resolve this ? I thinked that the problem comes from the use of String..