Problematic Argon -

I have an Argon running 1.5.2 that seems to have recurring issues with connectivity. It connects, runs several minutes then disconnects and repeats the process. I noted it was having issues making a cloud connection (rapid cyan blinking followed by 3 orange blinks. I tried doing particle keys server and particle keys doctors as the documentation suggested, but without any benefit. It’s odd that this device has been running for a long time, but I didn’t notice these issues. The LED is hidden from view most of the time, so this may be a long standing issue.

I use the device with a solenoid and a NeoPixel ring to signal when the garage door is open/closed and other conditions. It’s a simplistic program and I can’t see if I’m doing something wrong. Any ideas would be appreciated. It’s a very convenient way to know what’s happening at the garage and now a water leak detector.

Here’s my app code:

#include "Particle.h"
#include "neopixel.h"

SYSTEM_MODE(AUTOMATIC);

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D0
#define PIXEL_COUNT 24
//#define PIXEL_TYPE SK6812RGBW 
#define PIXEL_TYPE WS2812B //this is required for the neopixel ring I own
#define BRIGHTNESS 10 // 0 - 255
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)

int solenoid = D8;

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int hour = 0;
int minute = 0;
int second = 0;
uint32_t color = 0;
uint32_t lights[30];
int i=0;
uint32_t blue = 0xFF;
uint32_t red = 0xFF00;
uint32_t green = 0xFF0000;
char gDeviceInfo [200];
int gAction = 0;

void setup() {
  pinMode(solenoid,OUTPUT);
  Serial.begin(9600);
  Time.zone(-5); //EST
  Particle.function("pulseSolenoid",pulseSolenoid);
  Particle.function("setPixelsRed", setPixelsRed);
  Particle.function("setPixelsGreen", setPixelsGreen);
  Particle.function("setPixelsBlue", setPixelsBlue);
  Particle.function("setPixelsOff",setPixelsOff);
  Particle.subscribe("waterLeak",waterLeak,MY_DEVICES);
  Particle.subscribe("GDO",doorOpened,MY_DEVICES);
  Particle.subscribe("GDOSTILL",doorOpenStill,MY_DEVICES);
  Particle.subscribe("GDC",bothDoorsClosed,MY_DEVICES);
  strip.setBrightness(BRIGHTNESS);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  gAction = 8;
  snprintf(gDeviceInfo, sizeof(gDeviceInfo)
             ,"Application: %s, Date: %s, Time: %s, System firmware: %s, SSID: %s, RSSI: %d"
             ,__FILENAME__
             ,__DATE__
             ,__TIME__
             ,(const char*)System.version()  // cast required for String
             ,(const char*)WiFi.SSID()       // cast not required but always safe when in doubt if String or char*
             ,WiFi.RSSI().rssi
             );
  Particle.variable("deviceInfo",gDeviceInfo);
}

void loop() {
  switch (gAction)
  {
    case 0: //do nothing
      gAction = 0;
      break;

    case 1: // door opened
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      for (uint16_t i=0;i<=23;i++){
        strip.setPixelColor(i,255,0,0); //red
      }
      strip.show();
      gAction = 0;
      break;
    
    case 2: // doorOpenStill
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      delay(1000);
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      delay(1000);
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      gAction = 0;
      break;

    case 3: // bothDoorsClosed
      for (uint16_t i=0;i<=23;i++){
        strip.setPixelColor(i,0,255,0); //green
      }
      strip.show();
      gAction = 0;
      break;

    case 4: // pulse solenoid
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      setPixelsRed("");
      gAction = 0;
      break;

    case 5: // set pixels red
      //Serial.println("setPixelRed");
      for (uint16_t i=0;i<=23;i++){
        strip.setPixelColor(i,255,0,0); //red
      }
      strip.show();
      gAction = 0;
      break;

    case 6: //set pixels green
      //Serial.println("setPixelGreen");
      for (uint16_t i=0;i<=23;i++){
        strip.setPixelColor(i,0,255,0); //green
      }
      strip.show();
      gAction = 0;
      break;

    case 7: //set pixels blue
      //Serial.println("setPixelBlue");
      for (uint16_t i=0;i<=23;i++){
        strip.setPixelColor(i,0,0,255); //blue
      }
      strip.show();
      gAction = 0;
      break;

    case 8: // set pixels off
      //Serial.println("setPixelOff");
      for (uint16_t i=0;i<=23;i++){
        strip.setPixelColor(i,0,0,0); //off
      }
      strip.show();
      gAction = 0;
      break;

    case 9: // doorOpenStill
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      delay(1000);
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      delay(1000);
      Particle.process();
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      delay(1000);
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      delay(1000);
      Particle.process();
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      delay(1000);
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      delay(1000);
      Particle.process();
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      delay(1000);
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      delay(1000);
      Particle.process();
      digitalWrite(solenoid,HIGH);
      delay(50);
      digitalWrite(solenoid,LOW);
      gAction = 0;
      break;
    default:
      gAction = 0;
  }
}

void doorOpened(const char *event, const char *data) {
  gAction = 1;
}

void doorOpenStill(const char *event, const char *data) {
  gAction = 2;
}

void bothDoorsClosed(const char *event, const char *data) {
  gAction = 3;
}

void waterLeak (const char *event, const char *data) {
  gAction = 9;
}

int pulseSolenoid (String command) {
  gAction = 4;
  return 1;
}

int setPixelsRed (String command) {
  gAction = 5;
  return 1;
}

int setPixelsGreen (String command) {
  gAction = 6;
  return 1;
}

int setPixelsBlue (String command) {
  gAction = 7;
  return 1;
}

int setPixelsOff (String command) {
  gAction = 8;
  return 1;
}

Hi @ctmorrison! Mind sourcing some logs for us via Argon/Photon Cloud Debug?

Hi,
looks like your loop for some reason is blocking for too long, time to time which is weird as you are using Particle.process()
did you considered to use SYSTEM_THREAD(ENABLED);


may be this will help

Another stylistic tip would be to avoid multiple instances of this number literals when you have a perfectly fine way to keep that central

  for (uint16_t i=0;i<=23;i++)

is better replaced with

for (uint16_t i = 0;i < PIXEL_COUNT; i++)

While it may be unlikely your pixel count will ever change, it’s still best to make it a habit to use central definitions for things that may change once but affect your code in multiple places.

BTW, delay() (when not used with SYSTEM_THREAD(ENABLED) will call Particle.process() internally every 1000 ms of accumulated delay time.

@dreamER and @ScruffR, thanks for your thoughts. The device has been behaving today. Don’t know why… If it gets “weird” again, I’ll run the Argon WiFi Debug app and post the output. Note…the problem connecting seems to occur right after a reset. It has also had this nasty habit of simply going offline/online every couple of minutes once it’s up and running. I had made a couple of changes right before my post, but had still experienced issues. I do need to take a close look at the code to see if I’m doing something dumb that I just haven’t seen. One of the changes was that I had forgotten to include a default: case in my switch statement. I also moved a the strip. statements after the Particle.function and Particle.subscribe statements in setup(), since the phenom was occurring as part of startup. It really looked like a keys issue, but as I said, I tried to address that possibility without apparent success.

Again, thanks for your tips and I will incorporate them.