[PHOTON] Blinking Cyan

I have a problem with a Photon being regularly disconnected from the Cloud. When that happens it’s getting stuck blinking cyan rapidly.

I tried this workaround with some more debugging (see code below) and noticed the photon gets disconnected about every minute. It then reconnect with the help of the workaround, but sometimes it gets stuck on solid blue LED (which in my code means in Particle.process()).

From here I don’t know where to look.
I’m on firmware 0.4.9 which I compiled and installed manually.
I started to look at how Particle.process() is implemented, but this is all asynchronous and I don’t know how and where the thread queue gets fed…

Workaround and debugging code (call blink_cyan() at the begining of loop()):

#include <Particle.h>

static uint32_t lastdisconnect = 0;
static uint32_t firstdisconnect = 0;
static uint32_t disconnected = 0;
static uint32_t connected = 0;


bool blink_cyan() {
    if (!Particle.connected()) {
        RGB.control(true);

        RGB.color(255, 255, 0); // ORANGE

        //record when photon lost connection      
        disconnected = millis();

        if(millis() > (firstdisconnect + 6000)) {
            //try reconnect if disconnected > 6 secs

            RGB.color(0, 255, 0); // GREEN

            Particle.connect();
            while ((!Particle.connected()) && (millis()-lastdisconnect < 30000) ) {
                RGB.color(0, 0, 255); // BLUE
                Particle.process();
                delay(100);
                RGB.color(255, 0, 0); // RED
                delay(100);
            }
            RGB.color(255, 255, 255); // WHITE
            if(firstdisconnect == 0) {
                firstdisconnect = millis();
            }
        }
    }

    if(Particle.connected()) {
        if(disconnected) {
            RGB.control(false); // BREATHING CYAN
            char stmp[128];
            sprintf(stmp, "Disconnected %ld ms (previous connection: %ld ms)", millis() - disconnected, disconnected - connected);
            Particle.publish("reconnect", stmp, 60, PRIVATE);
            disconnected = 0;
            connected = millis();
        }
        lastdisconnect = millis();
        return false;
    }
    return true;
}

Generated logs with timestamps;

First attempt:
{"name":"reconnect","data":"Disconnected 901 ms (previous connection: 58113 ms)","ttl":"60","published_at":"2016-01-28T16:44:36.765Z"}
{"name":"reconnect","data":"Disconnected 921 ms (previous connection: 53107 ms)","ttl":"60","published_at":"2016-01-28T16:45:30.796Z"}
{"name":"reconnect","data":"Disconnected 931 ms (previous connection: 52183 ms)","ttl":"60","published_at":"2016-01-28T16:46:23.932Z"}
{"name":"reconnect","data":"Disconnected 929 ms (previous connection: 52972 ms)","ttl":"60","published_at":"2016-01-28T16:47:17.827Z"}
{"name":"reconnect","data":"Disconnected 931 ms (previous connection: 53063 ms)","ttl":"60","published_at":"2016-01-28T16:48:11.822Z"}
{"name":"reconnect","data":"Disconnected 935 ms (previous connection: 52074 ms)","ttl":"60","published_at":"2016-01-28T16:49:04.836Z"}
{"name":"reconnect","data":"Disconnected 928 ms (previous connection: 53062 ms)","ttl":"60","published_at":"2016-01-28T16:49:58.821Z"}

<MANUAL RESET>

Second attempt:
{"name":"reconnect","data":"Disconnected 931 ms (previous connection: 58156 ms)","ttl":"60","published_at":"2016-01-28T17:13:42.346Z"}
{"name":"reconnect","data":"Disconnected 933 ms (previous connection: 53084 ms)","ttl":"60","published_at":"2016-01-28T17:14:36.358Z"}
{"name":"reconnect","data":"Disconnected 2809 ms (previous connection: 52181 ms)","ttl":"60","published_at":"2016-01-28T17:15:31.358Z"}
{"name":"reconnect","data":"Disconnected 899 ms (previous connection: 53067 ms)","ttl":"60","published_at":"2016-01-28T17:16:25.291Z"}
{"name":"reconnect","data":"Disconnected 897 ms (previous connection: 53102 ms)","ttl":"60","published_at":"2016-01-28T17:17:19.288Z"}
{"name":"reconnect","data":"Disconnected 1036 ms (previous connection: 53097 ms)","ttl":"60","published_at":"2016-01-28T17:18:13.420Z"}
{"name":"reconnect","data":"Disconnected 947 ms (previous connection: 52977 ms)","ttl":"60","published_at":"2016-01-28T17:19:07.345Z"}
{"name":"reconnect","data":"Disconnected 2865 ms (previous connection: 58398 ms)","ttl":"60","published_at":"2016-01-28T17:21:15.249Z"}
{"name":"reconnect","data":"Disconnected 4962 ms (previous connection: 58122 ms)","ttl":"60","published_at":"2016-01-28T17:23:24.793Z"}
{"name":"reconnect","data":"Disconnected 6971 ms (previous connection: 52143 ms)","ttl":"60","published_at":"2016-01-28T17:24:24.513Z"}

<MANUAL RESET>

Third attempt:
{"name":"reconnect","data":"Disconnected 4856 ms (previous connection: 58112 ms)","ttl":"60","published_at":"2016-01-28T17:35:44.593Z"}
{"name":"reconnect","data":"Disconnected 2841 ms (previous connection: 52257 ms)","ttl":"60","published_at":"2016-01-28T17:36:39.713Z"}

I think I’ve found the bug for the blinking cyan death.

I’ve sent a PR:

This fix didn’t work, but I’ve set up a test case here if anyone can try to reproduce the problem.

My Core is blinking cyan too on Firmware 0.4.9 so I downgraded to 0.4.7.

I hope you’d be willing to provie more details to help us troubleshoot the issue. What application are you running? Using system threading? Is it really a core or another device, such as a Photon?

Hi @mdma

this is my code:

 // This #include statement was automatically added by the Particle IDE.
#include "elapsedMillis/elapsedMillis.h"
   
const long updateInterval = 10000L;
unsigned long previousMillis = 0;

bool smoke_detected = false;

uint16_t SMOKE_SENSOR = D4;
uint16_t LED = D7;
    
void setup() {

 Serial.begin(9600);
 
 pinMode(SMOKE_SENSOR, INPUT);
 pinMode(LED, OUTPUT);
}

void loop() {
    
    unsigned long currentMillis = millis();
    
    smoke_check();
    
    if ( smoke_detected ) {
    
        if(currentMillis - previousMillis < updateInterval){
            return;
        }
    
        previousMillis = currentMillis;   

        Particle.publish("Smoke", "fire", 60, PRIVATE);
    }
    
}

int smoke_check()
{
    if (digitalRead(SMOKE_SENSOR)) {
        
        //if fire is already detected, no need to do anything, since an alarm will be fired
        if (smoke_detected){
            return 0;
        }
        
        smoke_detected = true;
        
        digitalWrite(LED,HIGH);
    } else {
        
        digitalWrite(LED,LOW);
        smoke_detected = false;
    }
    return 0;
}

it works well with 0.4.7.
with 0.4.9 it blinks cyan, then green for a short time and again cyan. I am using a good old Core :smile:

1 Like