What could cause a Photon to lose its Cloud connection?

Something in my code (?) seems to be causing a cloud disconnect on one of my Photons. I’m working on homing in on exactly what at the moment.

However, I know from serial monitoring that the code is continuing to execute and loop as normal even though the Photon hasn’t a cloud connection. It’s either blinking Cyan (not breathing) or breathing green.

What can cause this and why isn’t the Photon trying to regain a Cloud connection? 0.7.0

Thanks! :slight_smile:

If only we had some code to look at… :wink:

2 Likes

Thanks, @Moors7, I’ll strip down the code to the relevant bits only and post it.
Believe it or not I didn’t post the code originally as an attempt at a courtesy! :wink:

Hi @Moors7, I thought I’d cracked it yesterday, but no, sure enough, I haven’t. Basically I have one Photon “listening” to the heartbeat of two other Photons. This is a pared away version of my code. It seems that after a while of not hearing from one Photon, the device loses its cloud connection and doesn’t attempt to regain it. Code continues to run on the Photon in the background, just without internet connectivity. I know this because it continues to output the time to serial.
Basically I want to monitor my Photons for them dropping offline. I want to allow for one missed heartbeat (say the WiFi was not available at the precise moment the Photon “phones home”) but if a second call home is missed, I want to be able to react to that. I’m

INO

#include "VineAlert.h"

using namespace RetailAlert;

SYSTEM_THREAD(ENABLED);

// PUB-SUB constants
constexpr char * DEVICE_NAME = "RETAIL_ALERT";
constexpr char * LAUN_FAIL_MSSG = "COMMS FAIL FROM LAUNDRY";
constexpr char * LAUN_FAIL2_MSSG = "2nd COMMS FAIL FROM LAUNDRY";
constexpr char * OPS_FAIL_MSSG = "COMMS FAIL FROM OPSROOM";
constexpr char * OPS_FAIL2_MSSG = "2nd COMMS FAIL FROM OPSROOM";

int slidingstate = 3;
int LAUNDRYkeepstate = 3;
int OPSROOMwindowlocked = 3;
int bathroomwindowlocked = 3;

boolean LAUNDRYFail = false;
boolean OPSROOMFail = false;

Timer HeartbeatLAUNDRY(960000, HBLAUNCallback, true);
Timer ResetHBLAUNDRY(3600000, ResetLAUNCallback, true);
Timer HeartbeatOPSROOM(960000, HBOPSROOMCallback, true);
Timer ResetHBOPSROOM(3600000, ResetOPSROOMCallback, true);

// function declarations
void eventHandler(const char * event,
        const char * data);

#include "TimeAlarms/TimeAlarms.h"

void printDetail(uint8_t type, int value);

void setup() {
        Particle.subscribe(DEVICE_NAME, eventHandler, MY_DEVICES);

        Serial.begin(9600);
        HeartbeatLAUNDRY.start();
        HeartbeatOPSROOM.start();
        Alarm.timerRepeat(15, Repeats); // timer for every 15 seconds    

}

void loop() {

        Alarm.delay(0); // wait one second between clock display

}

void Repeats() {
        // digital clock display of the time
        Serial.print(Time.hour());
        printDigits(Time.minute());
        printDigits(Time.second());
        Serial.println();
}

void printDigits(int digits)
{
  Serial.print(":");
  if(digits < 10)
    Serial.print('0');
  Serial.print(digits);
}

void HBLAUNCallback(void) {

        if (LAUNDRYFail == false) {

                HeartbeatLAUNDRY.start();

                LAUNDRYFail = true;

                ResetHBLAUNDRY.start();

        } else if (LAUNDRYFail == true) {

                HeartbeatLAUNDRY.stop();

                Particle.publish(DEVICE_NAME, LAUN_FAIL2_MSSG, 60, PRIVATE);
                LAUNDRYFail = false;

        }

}

void ResetLAUNCallback(void) {
        LAUNDRYFail = false;

}

void HBOPSROOMCallback(void) {

        if (OPSROOMFail == false) {

                OPSROOMFail = true;

                HeartbeatOPSROOM.start();

                ResetHBOPSROOM.start();

        } else if (OPSROOMFail == true) {

                HeartbeatOPSROOM.stop();

                Particle.publish(DEVICE_NAME, OPS_FAIL2_MSSG, 60, PRIVATE);
                OPSROOMFail = false;

        }

}

void ResetOPSROOMCallback(void) {
        OPSROOMFail = false;

}

void eventHandler(const char * event,
        const char * data) {

        if (sscanf(data, "K%d, S%d", & LAUNDRYkeepstate, & slidingstate)) {
                HeartbeatLAUNDRY.start();

        } else if (sscanf(data, "O%d, B%d", & OPSROOMwindowlocked, & bathroomwindowlocked)) {
                HeartbeatOPSROOM.start();

        }
}

If I need to post the library files here, I can definitely do that, but since there’s four, I haven’t. They are here though. I suspect the error is in my INO heartbeat logic…

Thanks!!