Photon Repetitive Connecting to the Cloud

I have a Photon running in automatic system mode (default mode), no system threading.
The application requires the system to frequently (once per hour) disconnect from the cloud and re-connect again.
That all works well, except that sometimes it looks like the connection is not very stable:
after breathing cyan all of a sudden the status LED starts to blink cyan again (as if it is re-establishing connection to the cloud) after which it starts breathing cyan again. This can happen repetitively once every 10-20 seconds, but it also happens that the connection looks stable (continuously breathing cyan).
Has anyone any idea what could be the cause of this behaviour???

Which Device OS are you using?
Can you describe how you are disconnecting and reconnecting to the Cloud?

This sounds like your code is blocking for some reason and hence causing the cloud connection to fall apart.
We’d need to see some code to be sure tho’

My Device OS is 1.5.2.
Here is my code:
(some parts I skipped, as indicated below)

STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));

retained boolean set0 = false;
retained boolean set1 = false;
retained boolean set2 = false;
retained boolean set3 = false;
retained boolean MONITOR = false;
retained boolean HOLDCONNECTIE = false;
retained int RT = 58;
retained int DP = 80;
retained int tijdMAXMNL = 300000;
retained int tijd0A = 3000;
retained int tijd1A = 3000;
retained int tijd2A = 3000;
retained int tijd3A = 3000;
retained int hr=5;
retained int mr=0;
retained int hr2=11;
retained int mr2=0;
retained int hs=17;
retained int ms=0;
retained int hs2=23;
retained int ms2=0;
retained int tKLEP0AAN = Time.now();
retained int DUURKLEP0 = 0;
retained int tKLEP1AAN = Time.now();
retained int DUURKLEP1 = 0;
retained int tKLEP2AAN = Time.now();
retained int DUURKLEP2 = 0;
retained int tKLEP3AAN = Time.now();
retained int DUURKLEP3 = 0;
retained char TempTrack[25];//grootte van character array is 25, nl. 24 uur (0-23) plus een afsluitede '\0'
retained char AccuTrack[25];
retained char Klep0Track[25];
retained char Klep1Track[25];
retained char Klep2Track[25];
retained char Klep3Track[25];
retained char ARdefects[25];

boolean AAN = false;
boolean AUTO = false;
boolean NEXT = false;
boolean MONITORAANUIT = true;
boolean setTOUTMON = false;
boolean KLEP0AAN = false;
boolean KLEP1AAN = false;
boolean KLEP2AAN = false;
boolean KLEP3AAN = false;
boolean KLEP0AUTO = true;
boolean KLEP1AUTO = true;
boolean KLEP2AUTO = true;
boolean KLEP3AUTO = true;
boolean s = false;//flag; wordt na één pulsenreeks van klepsignalerings LED op s=1 gezet todat na verloop van 1 sec (timer Sign) weer s=0 wordt, waarmee de signaleringspuls reeks opnieuw start.
boolean setAlarm = false;

int TEMPPHOTON = 0;
int INDX = 4;
int VS0 = 0;
int VS1 = 0;
int VS2 = 0;
int VS3 = 0;
int TMP = 0;
int TEMPKAS = 0;
int VCC = 12000;
int NU = 0;
int tijd0 = 0;
int tijd1 = 0;
int tijd2 = 0;
int tijd3 = 0;
int SAMPLETIJDWLV = 0;
int WLV = 1;
int WLV0 = 1;
int WLV1 = 1;
int WLV2 = 1;
int WLV3 = 1;
int WLVAVG = 1;
int sDUURKLEP0 = 0;
int sDUURKLEP1 = 0;
int sDUURKLEP2 = 0;
int sDUURKLEP3 = 0;
int Alarm = 0;

char ACTUELEWAARDEN[24];//grootte van character array is 24, nl. 23 items (0-22) plus een afsluitede '\0'

String ESSENTIALS = (String(ACTUELEWAARDEN[0], DEC)+","+String(ACTUELEWAARDEN[1], DEC)+","+String(ACTUELEWAARDEN[2], DEC)+","+String(ACTUELEWAARDEN[3], DEC)+","+String(ACTUELEWAARDEN[4], DEC)+","+String(ACTUELEWAARDEN[5], DEC)+","+String(ACTUELEWAARDEN[6], DEC)+","+String(ACTUELEWAARDEN[7], DEC)+","+String(ACTUELEWAARDEN[8], DEC)+","+String(ACTUELEWAARDEN[9], DEC)+","+String(ACTUELEWAARDEN[10], DEC)+","+String(ACTUELEWAARDEN[11], DEC)+","+String(ACTUELEWAARDEN[12], DEC)+","+String(ACTUELEWAARDEN[13], DEC)+","+String(ACTUELEWAARDEN[14], DEC)+","+String(ACTUELEWAARDEN[15], DEC)+","+String(ACTUELEWAARDEN[16], DEC)+","+String(ACTUELEWAARDEN[17], DEC)+","+String(ACTUELEWAARDEN[18], DEC)+","+String(ACTUELEWAARDEN[19], DEC)+","+String(ACTUELEWAARDEN[20], DEC)+","+String(ACTUELEWAARDEN[21], DEC)+","+String(ACTUELEWAARDEN[22], DEC)+","+String(TempTrack[0], DEC)+","+String(TempTrack[1], DEC)+","+String(TempTrack[2], DEC)+","+String(TempTrack[3], DEC)+","+String(TempTrack[4], DEC)+","+String(TempTrack[5], DEC)+","+String(TempTrack[6], DEC)+","+String(TempTrack[7], DEC)+","+String(TempTrack[8], DEC)+","+String(TempTrack[9], DEC)+","+String(TempTrack[10], DEC)+","+String(TempTrack[11], DEC)+","+String(TempTrack[12], DEC)+","+String(TempTrack[13], DEC)+","+String(TempTrack[14], DEC)+","+String(TempTrack[15], DEC)+","+String(TempTrack[16], DEC)+","+String(TempTrack[17], DEC)+","+String(TempTrack[18], DEC)+","+String(TempTrack[19], DEC)+","+String(TempTrack[20], DEC)+","+String(TempTrack[21], DEC)+","+String(TempTrack[22], DEC)+","+String(TempTrack[23], DEC)+","+String(AccuTrack[0], DEC)+","+String(AccuTrack[1], DEC)+","+String(AccuTrack[2], DEC)+","+String(AccuTrack[3], DEC)+","+String(AccuTrack[4], DEC)+","+String(AccuTrack[5], DEC)+","+String(AccuTrack[6], DEC)+","+String(AccuTrack[7], DEC)+","+String(AccuTrack[8], DEC)+","+String(AccuTrack[9], DEC)+","+String(AccuTrack[10], DEC)+","+String(AccuTrack[11], DEC)+","+String(AccuTrack[12], DEC)+","+String(AccuTrack[13], DEC)+","+String(AccuTrack[14], DEC)+","+String(AccuTrack[15], DEC)+","+String(AccuTrack[16], DEC)+","+String(AccuTrack[17], DEC)+","+String(AccuTrack[18], DEC)+","+String(AccuTrack[19], DEC)+","+String(AccuTrack[20], DEC)+","+String(AccuTrack[21], DEC)+","+String(AccuTrack[22], DEC)+","+String(AccuTrack[23], DEC)+","+String(Klep0Track[0], DEC)+","+String(Klep0Track[1], DEC)+","+String(Klep0Track[2], DEC)+","+String(Klep0Track[3], DEC)+","+String(Klep0Track[4], DEC)+","+String(Klep0Track[5], DEC)+","+String(Klep0Track[6], DEC)+","+String(Klep0Track[7], DEC)+","+String(Klep0Track[8], DEC)+","+String(Klep0Track[9], DEC)+","+String(Klep0Track[10], DEC)+","+String(Klep0Track[11], DEC)+","+String(Klep0Track[12], DEC)+","+String(Klep0Track[13], DEC)+","+String(Klep0Track[14], DEC)+","+String(Klep0Track[15], DEC)+","+String(Klep0Track[16], DEC)+","+String(Klep0Track[17], DEC)+","+String(Klep0Track[18], DEC)+","+String(Klep0Track[19], DEC)+","+String(Klep0Track[20], DEC)+","+String(Klep0Track[21], DEC)+","+String(Klep0Track[22], DEC)+","+String(Klep0Track[23], DEC)+","+String(Klep1Track[0], DEC)+","+String(Klep1Track[1], DEC)+","+String(Klep1Track[2], DEC)+","+String(Klep1Track[3], DEC)+","+String(Klep1Track[4], DEC)+","+String(Klep1Track[5], DEC)+","+String(Klep1Track[6], DEC)+","+String(Klep1Track[7], DEC)+","+String(Klep1Track[8], DEC)+","+String(Klep1Track[9], DEC)+","+String(Klep1Track[10], DEC)+","+String(Klep1Track[11], DEC)+","+String(Klep1Track[12], DEC)+","+String(Klep1Track[13], DEC)+","+String(Klep1Track[14], DEC)+","+String(Klep1Track[15], DEC)+","+String(Klep1Track[16], DEC)+","+String(Klep1Track[17], DEC)+","+String(Klep1Track[18], DEC)+","+String(Klep1Track[19], DEC)+","+String(Klep1Track[20], DEC)+","+String(Klep1Track[21], DEC)+","+String(Klep1Track[22], DEC)+","+String(Klep1Track[23], DEC)+","+String(Klep2Track[0], DEC)+","+String(Klep2Track[1], DEC)+","+String(Klep2Track[2], DEC)+","+String(Klep2Track[3], DEC)+","+String(Klep2Track[4], DEC)+","+String(Klep2Track[5], DEC)+","+String(Klep2Track[6], DEC)+","+String(Klep2Track[7], DEC)+","+String(Klep2Track[8], DEC)+","+String(Klep2Track[9], DEC)+","+String(Klep2Track[10], DEC)+","+String(Klep2Track[11], DEC)+","+String(Klep2Track[12], DEC)+","+String(Klep2Track[13], DEC)+","+String(Klep2Track[14], DEC)+","+String(Klep2Track[15], DEC)+","+String(Klep2Track[16], DEC)+","+String(Klep2Track[17], DEC)+","+String(Klep2Track[18], DEC)+","+String(Klep2Track[19], DEC)+","+String(Klep2Track[20], DEC)+","+String(Klep2Track[21], DEC)+","+String(Klep2Track[22], DEC)+","+String(Klep2Track[23], DEC)+","+String(Klep3Track[0], DEC)+","+String(Klep3Track[1], DEC)+","+String(Klep3Track[2], DEC)+","+String(Klep3Track[3], DEC)+","+String(Klep3Track[4], DEC)+","+String(Klep3Track[5], DEC)+","+String(Klep3Track[6], DEC)+","+String(Klep3Track[7], DEC)+","+String(Klep3Track[8], DEC)+","+String(Klep3Track[9], DEC)+","+String(Klep3Track[10], DEC)+","+String(Klep3Track[11], DEC)+","+String(Klep3Track[12], DEC)+","+String(Klep3Track[13], DEC)+","+String(Klep3Track[14], DEC)+","+String(Klep3Track[15], DEC)+","+String(Klep3Track[16], DEC)+","+String(Klep3Track[17], DEC)+","+String(Klep3Track[18], DEC)+","+String(Klep3Track[19], DEC)+","+String(Klep3Track[20], DEC)+","+String(Klep3Track[21], DEC)+","+String(Klep3Track[22], DEC)+","+String(Klep3Track[23])+","+String(ARdefects[0])+","+String(ARdefects[1])+","+String(ARdefects[2])+","+String(ARdefects[3])+","+String(ARdefects[4])+","+String(ARdefects[5])+","+String(ARdefects[6])+","+String(ARdefects[7])+","+String(ARdefects[8])+","+String(ARdefects[9])+","+String(ARdefects[10])+","+String(ARdefects[11])+","+String(ARdefects[12])+","+String(ARdefects[13])+","+String(ARdefects[14])+","+String(ARdefects[15])+","+String(ARdefects[16])+","+String(ARdefects[17])+","+String(ARdefects[18])+","+String(ARdefects[19])+","+String(ARdefects[20])+","+String(ARdefects[21])+","+String(ARdefects[22])+","+String(ARdefects[23]));
String TIJD1 = "05";
String TIJD2 = "11";
String TIJD3 = "17";
String TIJD4 = "23";

Timer Sign(1000, SIGN);
Timer TIMEOUTMON(40000, TOUTMON, true);
Timer tMAX0(300000, KLEP0timeout, true);
Timer tMAX1(300000, KLEP1timeout, true);
Timer tMAX2(300000, KLEP2timeout, true);
Timer tMAX3(300000, KLEP3timeout, true);

void setup()
{
Particle.variable("ESSENTIALS", &ESSENTIALS, STRING);
Particle.function("HoldCN", HOLDCONN);
Particle.function("ReportTime", REPORT_TIME);
Particle.function("Disconnect", DISCONNECT);
Particle.function("Drempel", DREMPEL);
Particle.function("AutoRun_tijd_1", AutoRun1);//instelling van 1e AutoRun tijdstip HH:MM
Particle.function("AutoRun_tijd_2", AutoRun2);//instelling van 2e AutoRun tijdstip HH:MM
Particle.function("AutoRun_tijd_3", AutoRun3);//instelling van 3e AutoRun tijdstip HH:MM
Particle.function("AutoRun_tijd_4", AutoRun4);//instelling van 4e AutoRun tijdstip HH:MM
Particle.function("Set_t0", SETt0);//instelling van tijd Klep 0 in AUTO-mode
Particle.function("Set_t1", SETt1);//instelling van tijd Klep 1 in AUTO-mode
Particle.function("Set_t2", SETt2);//instelling van tijd Klep 2 in AUTO-mode
Particle.function("Set_t3", SETt3);//instelling van tijd Klep 3 in AUTO-mode

pinMode(D0, OUTPUT);//MANUAL_LED, wit
pinMode(D1, OUTPUT);//CONNECTIE_LED, blauw
pinMode(D2, OUTPUT);//ACCUSPANNING_LED, geel
pinMode(D3, OUTPUT);//WATERALARM, rood
pinMode(D4, OUTPUT);//KLEP1
pinMode(D5, OUTPUT);//KLEP0
pinMode(D6, OUTPUT);//KLEP2
pinMode(D7, OUTPUT);//KLEP3
pinMode(DAC, OUTPUT);//VSS VOEDING SENSORS
pinMode(WKP, OUTPUT);//POMP
pinMode(A0, INPUT); //temperatuursensor
pinMode(A1, INPUT);//Vochtsensor0
attachInterrupt(A1, KLEP0toggle, RISING);//
pinMode(A2, INPUT);//Vochtsensor3
attachInterrupt(A2, KLEP3toggle, RISING);//
pinMode(A3, INPUT);//Vochtsensor3
attachInterrupt(A3, KLEP1toggle, RISING);//
pinMode(A4, INPUT);//Vochtsensor2
attachInterrupt(A4, KLEP2toggle, RISING);//
pinMode(RX, INPUT);//WATERSENSOR
}

void loop()
{
Time.zone(+2);
TMP = analogRead(A0)*100/4096;
TEMPKAS = 0.0117 * TMP *TMP - 0.2357 * TMP - 1.4097;

if (TEMPKAS > 50)
    {
    Alarm = 1;
    }

VCC = (analogRead(A5) * 1.0015 * 17000 / 4096);
VCC = (VCC / 100);

if (VCC <= 117)//signalering lage accuspanning
    {
    Alarm = 3;
    digitalWrite(D2, HIGH);
    }
else
    {
    digitalWrite(D2, LOW);
    }

WLV = digitalRead(RX);
if ((Time.now() - SAMPLETIJDWLV) >= 3)
    {
    SAMPLETIJDWLV = Time.now();
    WLV3 = WLV2;
    WLV2 = WLV1;
    WLV1 = WLV0;
    WLV0 = WLV;
    if (WLV0 == 0 && WLV1 == 0 && WLV2 == 0 && WLV3 == 0)//als binnen 9 seconden viermaal achter elkaar  WLV = 0 wordt dit gezien als geen water (alarm)
        {
        WLVAVG = 0;
        digitalWrite(D3, HIGH);
        KLEP0AAN = false;
        KLEP0AANUIT();
        KLEP1AAN = false;
        KLEP1AANUIT();
        KLEP2AAN = false;
        KLEP2AANUIT();
        KLEP3AAN = false;
        KLEP3AANUIT();
        Alarm = 4;
        }
    else
        {
        WLVAVG = 1;
        digitalWrite(D3, LOW);
        }

    }

if (KLEP0AAN == true  && set0 == false)
    {
    set0 = true;
    tKLEP0AAN = millis();
    }
if (KLEP0AAN == false && set0 ==true)
    {
    set0 = false;
    DUURKLEP0 = DUURKLEP0 + millis() - tKLEP0AAN;
    }

if (KLEP1AAN == true  && set1 == false)
    {
    set1 = true;
    tKLEP1AAN = millis();
    }
if (KLEP1AAN == false && set1 ==true)
    {
    set1 = false;
    DUURKLEP1 = DUURKLEP1 + millis() - tKLEP1AAN;
    }

if (KLEP2AAN == true  && set2 == false)
    {
    set2 = true;
    tKLEP2AAN = millis();
    }
if (KLEP2AAN == false && set2 ==true)
    {
    set2 = false;
    DUURKLEP2 = DUURKLEP2 + millis() - tKLEP2AAN;
    }

if (KLEP3AAN == true  && set3 == false)
    {
    set3 = true;
    tKLEP3AAN = millis();
    }
if (KLEP3AAN == false && set3 ==true)
    {
    set3 = false;
    DUURKLEP3 = DUURKLEP3 + millis() - tKLEP3AAN;
    }

sDUURKLEP0 = DUURKLEP0 /1000 - 1;
if (sDUURKLEP0 < 0) {sDUURKLEP0 = 0;}
sDUURKLEP1 = DUURKLEP1 /1000 - 1;
if (sDUURKLEP1 < 0) {sDUURKLEP1 = 0;}
sDUURKLEP2 = DUURKLEP2 /1000 - 1;
if (sDUURKLEP2 < 0) {sDUURKLEP2 = 0;}
sDUURKLEP3 = DUURKLEP3 /1000 - 1;
if (sDUURKLEP3 < 0) {sDUURKLEP3 = 0;}

NU = Time.hour();


TempTrack[NU] = TEMPKAS;
AccuTrack[NU] = VCC;

if (Alarm > 0 && AUTO == true)
    {
    setAlarm = true;
    ARdefects[NU] = Alarm;
    }
else
    {
    if (setAlarm == false)
        {
        ARdefects[NU] = '_';
        }
    }
    
ACTUELEWAARDEN[0] = TEMPPHOTON;
ACTUELEWAARDEN[1] = TEMPKAS;
ACTUELEWAARDEN[2] = 127;//VCC;
ACTUELEWAARDEN[3] = WLVAVG;
ACTUELEWAARDEN[4] = NU;
ACTUELEWAARDEN[5] = tijd0A/1000;
ACTUELEWAARDEN[6] = tijd1A/1000;
ACTUELEWAARDEN[7] = tijd2A/1000;
ACTUELEWAARDEN[8] = tijd3A/1000;
ACTUELEWAARDEN[9] = tijdMAXMNL/2000;
ACTUELEWAARDEN[10] = hr;
ACTUELEWAARDEN[11] = hr2;
ACTUELEWAARDEN[12] = hs;
ACTUELEWAARDEN[13] = hs2;
ACTUELEWAARDEN[14] = RT;
ACTUELEWAARDEN[15] = HOLDCONNECTIE;
ACTUELEWAARDEN[16] = DP;
ACTUELEWAARDEN[17] = Alarm;
ACTUELEWAARDEN[18] = 0;//DATE
ACTUELEWAARDEN[19] = sDUURKLEP0/2;
ACTUELEWAARDEN[20] = sDUURKLEP1;
ACTUELEWAARDEN[21] = sDUURKLEP2;
ACTUELEWAARDEN[22] = sDUURKLEP3;


ESSENTIALS = (String(ACTUELEWAARDEN[0], DEC)+","+String(ACTUELEWAARDEN[1], DEC)+","+String(ACTUELEWAARDEN[2], DEC)+","+String(ACTUELEWAARDEN[3], DEC)+","+String(ACTUELEWAARDEN[4], DEC)+","+String(ACTUELEWAARDEN[5], DEC)+","+String(ACTUELEWAARDEN[6], DEC)+","+String(ACTUELEWAARDEN[7], DEC)+","+String(ACTUELEWAARDEN[8], DEC)+","+String(ACTUELEWAARDEN[9], DEC)+","+String(ACTUELEWAARDEN[10], DEC)+","+String(ACTUELEWAARDEN[11], DEC)+","+String(ACTUELEWAARDEN[12], DEC)+","+String(ACTUELEWAARDEN[13], DEC)+","+String(ACTUELEWAARDEN[14], DEC)+","+String(ACTUELEWAARDEN[15], DEC)+","+String(ACTUELEWAARDEN[16], DEC)+","+String(ACTUELEWAARDEN[17], DEC)+","+String(ACTUELEWAARDEN[18], DEC)+","+String(ACTUELEWAARDEN[19], DEC)+","+String(ACTUELEWAARDEN[20], DEC)+","+String(ACTUELEWAARDEN[21], DEC)+","+String(ACTUELEWAARDEN[22], DEC)+","+String(TempTrack[0], DEC)+","+String(TempTrack[1], DEC)+","+String(TempTrack[2], DEC)+","+String(TempTrack[3], DEC)+","+String(TempTrack[4], DEC)+","+String(TempTrack[5], DEC)+","+String(TempTrack[6], DEC)+","+String(TempTrack[7], DEC)+","+String(TempTrack[8], DEC)+","+String(TempTrack[9], DEC)+","+String(TempTrack[10], DEC)+","+String(TempTrack[11], DEC)+","+String(TempTrack[12], DEC)+","+String(TempTrack[13], DEC)+","+String(TempTrack[14], DEC)+","+String(TempTrack[15], DEC)+","+String(TempTrack[16], DEC)+","+String(TempTrack[17], DEC)+","+String(TempTrack[18], DEC)+","+String(TempTrack[19], DEC)+","+String(TempTrack[20], DEC)+","+String(TempTrack[21], DEC)+","+String(TempTrack[22], DEC)+","+String(TempTrack[23], DEC)+","+String(AccuTrack[0], DEC)+","+String(AccuTrack[1], DEC)+","+String(AccuTrack[2], DEC)+","+String(AccuTrack[3], DEC)+","+String(AccuTrack[4], DEC)+","+String(AccuTrack[5], DEC)+","+String(AccuTrack[6], DEC)+","+String(AccuTrack[7], DEC)+","+String(AccuTrack[8], DEC)+","+String(AccuTrack[9], DEC)+","+String(AccuTrack[10], DEC)+","+String(AccuTrack[11], DEC)+","+String(AccuTrack[12], DEC)+","+String(AccuTrack[13], DEC)+","+String(AccuTrack[14], DEC)+","+String(AccuTrack[15], DEC)+","+String(AccuTrack[16], DEC)+","+String(AccuTrack[17], DEC)+","+String(AccuTrack[18], DEC)+","+String(AccuTrack[19], DEC)+","+String(AccuTrack[20], DEC)+","+String(AccuTrack[21], DEC)+","+String(AccuTrack[22], DEC)+","+String(AccuTrack[23], DEC)+","+String(Klep0Track[0], DEC)+","+String(Klep0Track[1], DEC)+","+String(Klep0Track[2], DEC)+","+String(Klep0Track[3], DEC)+","+String(Klep0Track[4], DEC)+","+String(Klep0Track[5], DEC)+","+String(Klep0Track[6], DEC)+","+String(Klep0Track[7], DEC)+","+String(Klep0Track[8], DEC)+","+String(Klep0Track[9], DEC)+","+String(Klep0Track[10], DEC)+","+String(Klep0Track[11], DEC)+","+String(Klep0Track[12], DEC)+","+String(Klep0Track[13], DEC)+","+String(Klep0Track[14], DEC)+","+String(Klep0Track[15], DEC)+","+String(Klep0Track[16], DEC)+","+String(Klep0Track[17], DEC)+","+String(Klep0Track[18], DEC)+","+String(Klep0Track[19], DEC)+","+String(Klep0Track[20], DEC)+","+String(Klep0Track[21], DEC)+","+String(Klep0Track[22], DEC)+","+String(Klep0Track[23], DEC)+","+String(Klep1Track[0], DEC)+","+String(Klep1Track[1], DEC)+","+String(Klep1Track[2], DEC)+","+String(Klep1Track[3], DEC)+","+String(Klep1Track[4], DEC)+","+String(Klep1Track[5], DEC)+","+String(Klep1Track[6], DEC)+","+String(Klep1Track[7], DEC)+","+String(Klep1Track[8], DEC)+","+String(Klep1Track[9], DEC)+","+String(Klep1Track[10], DEC)+","+String(Klep1Track[11], DEC)+","+String(Klep1Track[12], DEC)+","+String(Klep1Track[13], DEC)+","+String(Klep1Track[14], DEC)+","+String(Klep1Track[15], DEC)+","+String(Klep1Track[16], DEC)+","+String(Klep1Track[17], DEC)+","+String(Klep1Track[18], DEC)+","+String(Klep1Track[19], DEC)+","+String(Klep1Track[20], DEC)+","+String(Klep1Track[21], DEC)+","+String(Klep1Track[22], DEC)+","+String(Klep1Track[23], DEC)+","+String(Klep2Track[0], DEC)+","+String(Klep2Track[1], DEC)+","+String(Klep2Track[2], DEC)+","+String(Klep2Track[3], DEC)+","+String(Klep2Track[4], DEC)+","+String(Klep2Track[5], DEC)+","+String(Klep2Track[6], DEC)+","+String(Klep2Track[7], DEC)+","+String(Klep2Track[8], DEC)+","+String(Klep2Track[9], DEC)+","+String(Klep2Track[10], DEC)+","+String(Klep2Track[11], DEC)+","+String(Klep2Track[12], DEC)+","+String(Klep2Track[13], DEC)+","+String(Klep2Track[14], DEC)+","+String(Klep2Track[15], DEC)+","+String(Klep2Track[16], DEC)+","+String(Klep2Track[17], DEC)+","+String(Klep2Track[18], DEC)+","+String(Klep2Track[19], DEC)+","+String(Klep2Track[20], DEC)+","+String(Klep2Track[21], DEC)+","+String(Klep2Track[22], DEC)+","+String(Klep2Track[23], DEC)+","+String(Klep3Track[0], DEC)+","+String(Klep3Track[1], DEC)+","+String(Klep3Track[2], DEC)+","+String(Klep3Track[3], DEC)+","+String(Klep3Track[4], DEC)+","+String(Klep3Track[5], DEC)+","+String(Klep3Track[6], DEC)+","+String(Klep3Track[7], DEC)+","+String(Klep3Track[8], DEC)+","+String(Klep3Track[9], DEC)+","+String(Klep3Track[10], DEC)+","+String(Klep3Track[11], DEC)+","+String(Klep3Track[12], DEC)+","+String(Klep3Track[13], DEC)+","+String(Klep3Track[14], DEC)+","+String(Klep3Track[15], DEC)+","+String(Klep3Track[16], DEC)+","+String(Klep3Track[17], DEC)+","+String(Klep3Track[18], DEC)+","+String(Klep3Track[19], DEC)+","+String(Klep3Track[20], DEC)+","+String(Klep3Track[21], DEC)+","+String(Klep3Track[22], DEC)+","+String(Klep3Track[23])+","+String(ARdefects[0])+","+String(ARdefects[1])+","+String(ARdefects[2])+","+String(ARdefects[3])+","+String(ARdefects[4])+","+String(ARdefects[5])+","+String(ARdefects[6])+","+String(ARdefects[7])+","+String(ARdefects[8])+","+String(ARdefects[9])+","+String(ARdefects[10])+","+String(ARdefects[11])+","+String(ARdefects[12])+","+String(ARdefects[13])+","+String(ARdefects[14])+","+String(ARdefects[15])+","+String(ARdefects[16])+","+String(ARdefects[17])+","+String(ARdefects[18])+","+String(ARdefects[19])+","+String(ARdefects[20])+","+String(ARdefects[21])+","+String(ARdefects[22])+","+String(ARdefects[23]));
  //Signalering van actieve klep via LED MAN (Wit):
    if (AAN == 1 && s == false && AUTO == false)
        {
        if (KLEP1AAN == true)//repeterend 1 korte flits per 2 sec
            {
            digitalWrite(D0, HIGH);
            delay(30);
            digitalWrite(D0, LOW);
            delay(870);
            }
        if (KLEP2AAN == true)//repeterend 2 korte flitsen per 2 sec
            {
            digitalWrite(D0, HIGH);
            delay(30);
            digitalWrite(D0, LOW);
            delay(420);
            digitalWrite(D0, HIGH);
            delay(30);
            digitalWrite(D0, LOW);
            delay(420);
            }
        if (KLEP3AAN == true)//repeterend 3 korte flitsen per 2 sec
            {
            digitalWrite(D0, HIGH);
            delay(30);
            digitalWrite(D0, LOW);
            delay(270);
            digitalWrite(D0, HIGH);
            delay(30);
            digitalWrite(D0, LOW);
            delay(270);
            digitalWrite(D0, HIGH);
            delay(30);
            digitalWrite(D0, LOW);
            delay(270);
            }
        if (KLEP0AAN == true)//repeterend 1sec aan / 1 sec uit
            {
            digitalWrite(D0, HIGH);
            delay(870);
            digitalWrite(D0, LOW);
            delay(10);
            }
        s = true;//zet flag die het opnieuw afglopen van de puls sequentie gedurende 1 sec voorkomt (door timer Sign)
        Sign.start();//start van timer die herhalingsfrekwentie van klep-signalerings LED
        }

    if (Time.minute() == RT && Time.second() < 1 && MONITOR == false && AAN == false && AUTO == false)
        {
        WiFi.on();
        WiFi.connect();
        if (waitFor(WiFi.ready, 15000))
            {
            MONITOR = true;
            Particle.connect();
            }
        else
            {
            Particle.disconnect();
            WiFi.off();
            }
        }

    if (Particle.connected())
        {
        digitalWrite(D1, HIGH);
        if (MONITOR == true && setTOUTMON == false)//5.
            {
            Klep0Track[NU] = sDUURKLEP0 / 2;
            Klep1Track[NU] = sDUURKLEP1;
            Klep2Track[NU] = sDUURKLEP2;
            Klep3Track[NU] = sDUURKLEP3;
            setTOUTMON = true;
            TIMEOUTMON.start();
            }
        if (MONITORAANUIT == false)
            {
            //delay(5000);
            MONITOR = false;
            setTOUTMON = false;
            MONITORAANUIT = true;
            setAlarm = false;
            DUURKLEP0 = 0;
            DUURKLEP1 = 0;
            DUURKLEP2 = 0;
            DUURKLEP3 = 0;
            Particle.disconnect();
            WiFi.off();
            HOLDCONNECTIE = false;
            digitalWrite(D1, LOW);
            Alarm = 0;
            }
       }
    else
        {
        digitalWrite(D1, LOW);
        }

if (Particle.connected() == false)//Automatisch programma werkt uitsuitend wanneer Internet niet actief is
    {
    if (((Time.hour() == hr && hr > 0 && Time.minute() == mr && mr >= 0 && Time.second() <= 5) || (Time.hour() == hr2 && hr2 > 0 && Time.minute() == mr2 && mr2 >= 0 && Time.second() <= 5) || (Time.hour() == hs && hs > 0 && Time.minute() == ms && ms >= 0 && Time.second() <= 5) || (Time.hour() == hs2 && hs2 > 0 && Time.minute() == ms2 && ms2 >= 0 && Time.second() <= 5)) && AUTO == false)// && NEXT == false)
        {
        AUTO = true;
        noInterrupts();
        INDX = 0;
        analogWrite(DAC, 4095);
        delay(500);
        VS0 =analogRead(A1)*100/4096;
        VS1 =analogRead(A3)*100/4096;
        VS2 =analogRead(A4)*100/4096;
        VS3 =analogRead(A2)*100/4096;
        analogWrite(DAC, 0000);
        if (tijd0A == 0 || VS0 >= DP || WLVAVG == 0)
            {
            KLEP0AUTO = false;
            tijd0 = 0;
            }
        else
            {
            KLEP0AUTO = true;
            tijd0 = tijd0A;
            }
        if (tijd1A == 0 || VS1 >= DP || WLVAVG == 0)
            {
            KLEP1AUTO = false;
            tijd1 = 0;
            }
        else
            {
            KLEP1AUTO = true;
            tijd1 = tijd1A;
            }
        if (tijd2A == 0 || VS2 >= DP || WLVAVG == 0)
            {
            KLEP2AUTO = false;
            tijd2 = 0;
            }
        else
            {
            KLEP2AUTO = true;
            tijd2 = tijd2A;
            }
        if (tijd3A == 0 || VS3 >= DP || WLVAVG == 0)
            {
            KLEP3AUTO = false;
            tijd3 = 0;
            }
        else
            {
            KLEP3AUTO = true;
            tijd3 = tijd3A;
            }

        tMAX0.changePeriod(tijd0);
        tMAX0.stop();
        tMAX1.changePeriod(tijd1);
        tMAX1.stop();
        tMAX2.changePeriod(tijd2);
        tMAX2.stop();
        tMAX3.changePeriod(tijd3);
        tMAX3.stop();

        KLEP0AAN = true;
        KLEP0AANUIT();
        }
    if (AUTO == true && AAN == false && INDX == 0)
        {
        INDX = 1;
        delay(1000);
        KLEP1AAN = true;
        KLEP1AANUIT();
        }
    if (AUTO == true && AAN == false && INDX == 1)
        {
        INDX = 2;
        delay(1000);
        KLEP2AAN = true;
        KLEP2AANUIT();
        }
    if (AUTO == true && AAN == false && INDX == 2)
        {
        INDX = 3;
        delay(1000);
        KLEP3AAN = true;
        KLEP3AANUIT();
        }
    if (AUTO == true && AAN == false && INDX == 3)
        {
        INDX = 4;
        delay(1000);
        tMAX0.changePeriod(tijdMAXMNL);
        tMAX0.stop();
        tMAX1.changePeriod(tijdMAXMNL);
        tMAX1.stop();
        tMAX2.changePeriod(tijdMAXMNL);
        tMAX2.stop();
        tMAX3.changePeriod(tijdMAXMNL);
        tMAX3.stop();
        KLEP0AUTO = true;
        KLEP1AUTO = true;
        KLEP2AUTO = true;
        KLEP3AUTO = true;
        AUTO = false;
        interrupts();
        }
}

}//EINDE LOOP*********************************************************************************************************************************************************************



int HOLDCONN(String hc)
    {
    if (hc == "1" && MONITOR == true)
        {
        HOLDCONNECTIE = true;
        }
    else
        {
        HOLDCONNECTIE = false;
        }
    }


void TOUTMON()
    {
    if (HOLDCONNECTIE == false)
        {
        MONITORAANUIT = false;
        }
    }


int DISCONNECT(String WF)
    {
    if (WF == "0")
        {
        if (MONITOR == true)
            {
            MONITORAANUIT = false;
            }
        else
            {
            Particle.disconnect();
            WiFi.off();
            HOLDCONNECTIE = false;
            digitalWrite(D1, LOW);
            Alarm = 0;
            }
        }
    }


int REPORT_TIME(String rt)//ontvangt Report tjdstip uit APP: tussen 0-59 minuten)
    {
    RT = rt.toInt();
    if (RT > 59) {RT = 59;}
    if (RT < 0) {RT = 00;}
    }

int DREMPEL(String dp)
    {
    DP = dp.toInt();
    if (DP > 95) {DP = 95;}
    if (DP < 20) {DP = 20;}
    }

void KLEP0toggle()
    {
    if (KLEP0AAN == true)
        {
        KLEP0AAN = false;
        }
    else
        {
        KLEP0AAN = true;
        }
    KLEP0AANUIT();
    }

void KLEP0timeout()
    {
    KLEP0AAN = false;
    KLEP0AANUIT();
    }

void KLEP0AANUIT()
    {
    if (KLEP0AAN == true )
        {
        AAN = true;
        if (KLEP0AUTO == true)
            {
            digitalWrite(D5, HIGH);//KLEP0
            digitalWrite(WKP, HIGH);//POMP
            }
        tMAX0.start();
        detachInterrupt(A2);//KLEP3
        detachInterrupt(A3);//KLEP1
        detachInterrupt(A4);//KLEP2
        }
    else
        {
        AAN = false;
        digitalWrite(D5, LOW);//KLEP0
        digitalWrite(WKP, LOW);//POMP
        pinMode(A2, INPUT);//vochtsensor3
        attachInterrupt(A2, KLEP3toggle, RISING);//
        pinMode(A3, INPUT);//Vochtsensor1
        attachInterrupt(A3, KLEP1toggle, RISING);//
        pinMode(A4, INPUT);//Vochtsensor2
        attachInterrupt(A4, KLEP2toggle, RISING);
        }
    }

<<<The previous 3 voids referring to KLEP0 are repeated for KLEP1, KLEP2 and KLEP3; I’ve skipped them as they are not relevant>>>

int SETtMAXMNL(String tijdmaxM)//waarde voor maximale ÁAN'-tijd wordt ingesteld vanuit APP: deze routine wordt gestart vanuit Particle.function("Settmax0", settmax0);
    {
    tijdMAXMNL = 1000* tijdmaxM.toInt();//de String variabele "tijd" wordt omgezet in een Integer. NB tijdx = string met tijd in seconden; tijdmax0 = integer met tijd in millisec
    if (tijdMAXMNL > 300000) {tijdMAXMNL = 300000;}
    tMAX0.changePeriod(tijdMAXMNL);
    tMAX0.stop();
    tMAX1.changePeriod(tijdMAXMNL);
    tMAX1.stop();
    tMAX2.changePeriod(tijdMAXMNL);
    tMAX2.stop();
    tMAX3.changePeriod(tijdMAXMNL);
    tMAX3.stop();
    }

int SETt0(String tijd0)
    {
    tijd0A = 1000* tijd0.toInt();
    if (tijd0A > 300000) {tijd0A = 300000;}
    }
int SETt1(String tijd1)
    {
    tijd1A = 1000* tijd1.toInt();
    if (tijd1A > 300000) {tijd1A = 300000;}
    }
int SETt2(String tijd2)
    {
    tijd2A = 1000* tijd2.toInt();
    if (tijd2A > 300000) {tijd2A = 300000;}
    }
int SETt3(String tijd3)
    {
    tijd3A = 1000* tijd3.toInt();
    if (tijd3A > 300000) {tijd3A = 300000;}
    }

int AutoRun1(String TIJD1)
    {
    hr = TIJD1.toInt();
    mr = 0;

    }
int AutoRun2(String TIJD2)
    {
    hr2 = TIJD2.toInt();
    mr2 = 0;
    }
int AutoRun3(String TIJD3)
    {
    hs = TIJD3.toInt();
    ms = 0;
    }
int AutoRun4(String TIJD4)
    {
    hs2 = TIJD4.toInt();
    ms2 = 0;
    }

void SIGN()
    {
    s = false;

Was your first programming language Python by any chance?

The indentation and variable/function naming makes is difficult (at least for me) to follow the code.
I’d also propose using arrays and structs instead of distinct variables like tMAX0, tMAX1, …

This is not how you used to register a string - even in the deprecated syntax.
Back then it was done without the ampersand and now it would be

Particle.variable("ESSENTIALS", ESSENTIALS);

(all caps is typically “reserved” for constants not variables)

Finally, I’d suggest to stay away from String objects and rather use C-strings (aka character arrays).

1 Like

Thanks for the reply ScruffR!

No, my first programming language wasn’t Python; I am a retired Electronics Engineer (rather hardware-oriented) and my only ‘formal’ programming education dates from 50 years ago: Algol (you need to be my age to know what language that was, I guess. In my professional life I have been in management positions and started only programming when I retired, which makes me a “good amateur” at best…:wink:

About your other suggestions:
1.
I wasn’t aware of these syntactical issues, nor of te “caps”-thing. Can you recommend a good comprehensive manual where I could find these things? My main knowledge source is the book “Getting Started with Photon” by Simon Monk and the Particle documentation.
2.
I was aware that you should avoid String Objects and as you can see I used a some of character arrays for that reason. However, If you want to make things available as Particle.variables these should be Strings isn’t it???
Or is there a trick that I am unaware of to use C-strings directly as Particle.variables and Particle-functions?
Please advice!
3.
I don’t know if it is necessar for you to follow the entire code. If your suggestion is to review the systax and the use of the Strings, I will first do that and see if that solves the problem.
If not, I will briefly explain the code.
Thanks so far!

1 Like

They can be both (String or char[]) - as they are both considered strings and the former provides a conversion to the latter.
This is perfectly acceptable code

char someString[128];
void setup() {
  Particle.variable("myString", someString);
  Particle.function("takeCString", someFn);
}

int someFn(const char* cString) {
  return strlen(cString);
}

I also see that you have char ACTUELEWAARDEN[24]; but then feed a bunch of numeric values into it. I’m not quite sure why and whether any of the values may ever be greater than 255 (which would result in loss of data integrity).

I’d also rework this

On the Photon you should be able to call Particle.connect() without a previous call to WiFi.connect() (and probably even WiFi.on()) and after that I’d rather waitFor(Particle.connected, 30000) than for WiFi.ready().

And as you intend to have your code running even without cloud connection I’d suggest trying out SYSTEM_THREAD(ENABLED) to ensure the WiFi/cloud stuff will be taken care of by a dedicated thread.

I’ve tried your suggestion and have put the char Strings directly into Particle.variables (and making 7 Particle.variables this way instead of one giant string) ;
so:

char ACTUELEWAARDEN[24];
char …
etc.

void setup()
{ 
  Particle.variable("ESSENTIALS", ACTUELEWAARDEN);
  etc.

}

However, when trying to GET that variable “ESSENTIALS” in Particle Console that results into the error message: <<<Failed to fetch ESSENTIALS>>>
Same for the other char strings that I registered as Particle variables.
Did I ommit something?

I prefer t connect in several consequtive steps, so that when WiFi not connects within 15 seconds the “off-line” program still continues to run. I am using the hotspot of an old iPhone as WiFi, but sometimes the iPhone requires user-interaction and then blocks the hotspot for some time…(So: rather unreliable).
What happens when you call Particle.connect directly while WiFi is not available? Will the program block, or can you apply a timeout?

The error message wasn’t copied, but it sais something like: failed to…(a message in a red rectangle used in the console)

You can still use a single string.
In order to construct the string you can use snprintf(), strcpy() and strncat().
I’d also construct that string in a loop instead of listing all the individual fields of each array hardcoded.

char essentials[622];
...
void loop() {
  ...
  snprintf(essentials, sizeof(essentials), "%d", actWaarden[0]);
  for (int i = 1; i < 23; i++)
    snprintf(essentials, sizeof(essentials), "%s,%d", essentials, actWaarden[i]);

  for (int i = 0; i < 23; i++)
    snprintf(essentials, sizeof(essentials), "%s,%d", essentials,  tempTrack[i]);

  for (int i = 0; i < 24; i++)
    snprintf(essentials, sizeof(essentials), "%s,%d", essentials,  accuTrack[i]);

  for (int i = 0; i < 24; i++)
    snprintf(essentials, sizeof(essentials), "%s,%d", essentials,  klep0Track[i]);

  for (int i = 0; i < 24; i++)
    snprintf(essentials, sizeof(essentials), "%s,%d", essentials,  klep1Track[i]);

  for (int i = 0; i < 24; i++)
    snprintf(essentials, sizeof(essentials), "%s,%d", essentials,  klep2Track[i]);

  for (int i = 0; i < 24; i++)
    snprintf(essentials, sizeof(essentials), "%s,%d", essentials,  klep3Track[i]);

  for (int i = 0; i < 24; i++)
    snprintf(essentials, sizeof(essentials), "%s,%d", essentials,  arDefects[i]);
  ...
}

With some slight modifications to your data structure could make that even shorter

  essentials[0] = '\0'; // clear string
  for (int i = 0; i < 24; i++)
    snprintf(essentials, sizeof(essentials)
            , "%s%d: %d\t%d\t%d\t%d\t%d\t%d\t%d\r\n"
            , essentials
            , i
            , actWaarden[i]
            , tempTrack[i]
            , accuTrack[i]
            , klep0Track[i]
            , klep1Track[i]
            , klep2Track[i]
            , klep3Track[i]
            , arDefects[i]
            );

As I mentioned above, you can still use waitFor() with a timeout.
With SYSTMEM_THREAD(ENABLED) you can even fire the Particle.connect() call and then carry on with your work (with a somewhat slower performance tho’) without waiting for it to finish. You’d just need to make sure not to use anything cloud related or call Particle.connect() again as long the connection hasn’t been reestablished.