Hello,
I am using a couple Photon modules and having trouble getting them to stay connected to the cloud. They seem to stay connected for about a day or two (doesn’t appear to be consistent). I am checking the connection with “if( Particle.connected() )”, if this conditional is “false”, I invoke “Particle.connect();”, but the connection doesn’t seem to re-establish.
My device has two sensors and some LEDs. I have three set-up to monitor and update these components and a fourth timer to maintain the connection with the cloud. This means that my main loop() is essentially empty; it only includes a conditional to help sync the system clock with the cloud. (see below)
//Set-up timers for regular routines:
Timer LED_timer(50, update_LEDs); //20Hz
Timer qTouch_timer(250, update_qTouch); //4Hz
Timer IR_timer(100, update_IR); //10Hz
Timer Cloud_timer(1000, update_Cloud); //1Hz
//Main Loop
void loop()
{
//Sync with Particle Service once a day to ensure long-term reliability:
if (millis() - lastTimeSync > ONE_DAY_MILLIS)
{
Particle.syncTime(); // Request time synchronization from the Particle Cloud
lastTimeSync = millis();
}
} //End of loop()
I suspect that the culprit might be my capacitive touch sensor code. This routine is called 4 times per second. Within it I create a physical interrupt on my sense pin and wait until the interrupt happens. I also have a simple averaging filter with a sample size of 20. With this sample size the execution time seems to range between 500 and 700 micro seconds. (see below)
void update_qTouch()
{
unsigned long total_qTouch_Time=0;
for (unsigned char i=0; i<QTOUCH_SAMPLESIZE; i++)
{
// discharge capacitance at sense pins
pinMode(qT_IN, OUTPUT);
pinResetFast(qT_IN);
pinResetFast(qT_DRIVER);
pinMode(qT_IN,INPUT); // revert to high impedance input
attachInterrupt(qT_IN, qTouch_ISR, RISING); //Enable interrupt on sense pin
u_tS = micros(); //Capture current time.
digitalWriteFast(qT_DRIVER, HIGH);
while (digitalRead(qT_IN)==LOW);
u_tS_delay = micros(); //Capture time triggered
// accumulate the RC delay samples
if ( u_tS_delay>u_tS )
total_qTouch_Time += (u_tS_delay - u_tS);
else // Redo reading when micros() overflows
i--; //Subtract from count to redo
}
current_qTouch = total_qTouch_Time; //update current qTouch value
} //End of update_qTouch()
void qTouch_ISR()
{
u_tS_delay = micros(); //Capture time triggered
detachInterrupt(qT_IN); //Disable interrupt on qTouch sense pin
} //End of qTouch_ISR