Connection Unstable Wifi

SOO getting tired of this, I have added an external antenna, router is stable as can be and is on auto channel.
What’s weird is it seems to be something with the photon.
About 1 out of ever 10 power cycles it will lock up a solid connection for DAYS with no issues.
Then just a simple power cycle of the Photon and it’s back to this garbage forever.

I’ve tried moving the device and putting it 2 feet away from the router and I get these issues.
Tried an old wifi router for a few days same issues, tried manually setting a clear channel in the router to no avail…

I give up!!! My project is worthless with connection issues like this, I’m so frustrated I’m ready to give up at this point and say to hell with Photons.

Any ideas?

@funman1, posting some code might be a good idea.

1 Like

Not sure why that would matter?
I have it set to never sleep, power save, or anything weird.
Just normal code that should run in a loop?

Can’t get it to format correctly on these forums

#include "elapsedMillis/elapsedMillis.h"
const long AutoCloseTime = 300000; //300000 Set Time for 5 mins no movement in garage then close door
const long DoorCloseErrTime = 30000; //30 seconds to close door, (Close time + Open backup up time) if still open then send error out
const long DoorOpenErrTime = 15000; //15 seconds to open door, if still closed then send error out
int DoorOpen = 0; int OpenDoor = 0; int CloseDoor = 0; int MotionTime = 0; int DoorClosing = 0; int DoorinError = 0; int TooLong = 0;
long Motion;
elapsedMillis LastPRIEvent; 
int MotionPin = D4;
int DoorSwitchPin = D5;
int DoorCyclePin = D6;
int OpenRelayLED = D7;
STARTUP(WiFi.selectAntenna(ANT_EXTERNAL))
void setup() {
  pinMode (MotionPin, INPUT); 
  pinMode (DoorSwitchPin, INPUT);
  pinMode (DoorCyclePin, OUTPUT);
  pinMode (OpenRelayLED, OUTPUT);
  delay(2000);
  Spark.publish("GarageDoor","Booted: Firmware 1.55",60,PRIVATE);
  Spark.subscribe("GarageDoorCommand", GDCommands, MY_DEVICES);
  DoorOpen = digitalRead(DoorSwitchPin); //Read DoorSwitchPin and Set Var
  if (DoorOpen == 1) {Spark.publish("GarageDoor","ColdBoot: Door is Open",60,PRIVATE);}
    else {Spark.publish("GarageDoor","ColdBoot: Door is Closed",60,PRIVATE);}
}
void loop() {
 CheckPRIandDoor();
 CheckCloseStatus();
}
void CheckPRIandDoor(){   
    DoorOpen = digitalRead(DoorSwitchPin); //Read DoorSwitchPin and Set Var
    if (DoorOpen == 1) 
    {
        if (digitalRead(MotionPin)==HIGH && LastPRIEvent >= 5000) {LastPRIEvent = 0; {Spark.publish("GarageDoor","Motion",60,PRIVATE);}} // If motion detected then reset Auto-Close Timer
        if (LastPRIEvent >= AutoCloseTime) {CloseDoor = 1; TooLong = 1;} // If door is open and AutoCloseTime reached, then Flag CloseDoor & TooLong Var
    }
    if (LastPRIEvent >= 540000) {LastPRIEvent = 0;{Spark.publish("GarageDoor","Reset Time",60,PRIVATE);}} // if the timer gets beyond 9 mins IE: Door is closed, then reset to keep from getting too large
}
void CheckCloseStatus() {
    if (CloseDoor == 1) {
        if (TooLong == 1) {TooLong = 0; Spark.publish("GarageDoorTxt","Left Open, Attempting to Close",60,PRIVATE);}
            else {Spark.publish("GarageDoor","Attempting to Close",60,PRIVATE);}
        CloseDoor = 0; LastPRIEvent = 0; DoorClosing = 1;
        digitalWrite(DoorCyclePin, HIGH); digitalWrite(OpenRelayLED, HIGH); delay (500); digitalWrite(DoorCyclePin, LOW); digitalWrite(OpenRelayLED, LOW);// Pulse Relay to close door
        delay (DoorCloseErrTime);   
        if (digitalRead(DoorSwitchPin) == HIGH) {
            DoorClosing = 0; 
            DoorinError = 1; 
            Spark.publish("GarageDoorTxt","Error, Can't Close Door!!",60,PRIVATE);
        }
            else {
                DoorClosing = 0; 
                DoorinError = 0; 
                Spark.publish("GarageDoorTxt","Confirmed Door Closed",60,PRIVATE);
            }
    }
 if (OpenDoor == 1) {
        LastPRIEvent = 0; OpenDoor = 0; 
        Spark.publish("GarageDoor","Attempting to Open",60,PRIVATE);
        digitalWrite(DoorCyclePin, HIGH); digitalWrite(OpenRelayLED, HIGH); delay (500); digitalWrite(DoorCyclePin, LOW); digitalWrite(OpenRelayLED, LOW); // Pulse Relay to close door
        delay (DoorOpenErrTime);       
        if (digitalRead(DoorSwitchPin) == LOW) {
            DoorinError = 1; 
            Spark.publish("GarageDoorTxt","Error, Can't Open Door!!",60,PRIVATE);
        }
            else {
                DoorinError = 0; 
                Spark.publish("GarageDoor","Confirmed Door Open",60,PRIVATE);
            }
    }
}
void GDCommands(const char *event, const char *data){
    DoorOpen = digitalRead(DoorSwitchPin); //Read DoorSwitchPin and Set Var
    if (strcmp(data,"Open")==0){
    if (DoorOpen == 0) {OpenDoor = 1;}
            else {Spark.publish("GarageDoor","Already Open?, Can't Open Again",60,PRIVATE);}
    }
    else if (strcmp(data,"Close")==0){
        if (DoorOpen == 1) {CloseDoor = 1;}
            else {Spark.publish("GarageDoor","Already Closed?, Can't Close Again",60,PRIVATE);}
    }
    else if (strcmp(data,"Status")==0){
        Motion = ((LastPRIEvent / 1000) / 60); 
        if (DoorOpen == 1) {Spark.publish("GarageDoorTxt","Status: IS OPEN  Motion Time:" + String (Motion),60,PRIVATE);}
        if (DoorOpen == 0) {Spark.publish("GarageDoorTxt","Status: IS CLOSED  Motion Time:" + String (Motion),60,PRIVATE);}            
    }
}

I’m having a similar issue, today around 4PM PST, the code on my photon just stopped booting, it won’t hold a wifi connection, can’t push new code to it (it reboots after a split second of purple LED), and it’s the same issue with a second Photon. Is it possible that Particle is having issues with it’s systems?

I doubt it I’ve been beating my head with my issue for weeks

Just some general hints for what I’ve seen so far.

  • for switches you should use INPUT_PULLDOWN or INPUT_PULLUP unless you’ve got external pull resistors.
  • WiFi.selectAntenna() is only needed once when switching between antenna types, not each time
  • give SYSTEM_THREAD(ENABLED) a try (and/or play with SYSTEM_MODE(SEMI_AUTOMATIC))
  • if you call Particle.publish() without connection (even before signalled via LED) you might cause issues, try to check Particle.connected() first (should cured in 0.5.0)
  • don’t quite give up yet, firmware 0.5.0 is not too far away and will improve stability (e.g. publish issue)
  • minor style issue: Use Particle. instead of deprecated Spark.
  • make sure your publishes don’t violate the 1/sec (with 4/sec burst + 4sec pause) rate limit
  • break up multi instruction lines - makes it easier to read and understand

Non of this alone will cure your issue, but might help stability.


I just reformatted your code by wrapping it between

 ```cpp
 // your code

For more hints have a look here
 https://community.particle.io/t/forum-tips-and-tricks/3999
2 Likes

You could try reducing your DoorCloseErrTime to be less then 20 seconds. The Photon firmware documentation states:

from https://docs.particle.io/reference/firmware/photon/#automatic-mode

You could also use two delays of 15 seconds with a Particle.process() in the middle in order to achieve the total 30.
Another option would be adding some reconnect code like:

@Joeri, actually delay() does call Particle.process() once every accumulated second of waiting internally, to keep the cloud connection alive.

It does? This isn’t mentioned in the documentation :o
Edit: Found it burried in the automatic system mode description

  1. Yep I never completely trust internal ones so I use my own external ones.
  2. Yeah I know, it’s there more out of testing and frustration…
  3. I will have to look more into those
  4. I have boot up publishes, so THAT may be a REAL issue and that’s why like 1 out of 10 boots is fine, If it gets called before perhaps it’s hosing the entire unit and it’s just luck of the draw if it’s really connected before sending publish statements… Thanks I will look into that a LOT more now…
  5. OK I will keep up the good fight then.
  6. Didn’t know that, I will have to change it. Thanks
  7. Yep I’m good there, the fastest it can publish is once every 5 seconds or so with the exception of startup.

Thanks I will look into all of this and make the needed changes.

You should note that “two feet from the router” may actually be a problem. Too much signal is as bad as too little signal - typically you want an RSSI no stronger than -30dBm otherwise the PER (packet error rate) will be elevated and this may cause issues.

This affects both sides - you can deafen routers as well as deafen tiny devices - it’s just it’s usually worse on a device as routers tend to have more transmit power (but the same receive sensitivity).

What’s the RSSI you’re seeing?

One note on startup publishes:
Whenever your device connects it will also publish one to three (in rare circumstances) status events which are also counted for the rate limit. So don’t get surprised if some of your own events get muted.

Well that seems to have bricked my device for now…
I have to get on a ladder tomorrow and try and get the device running again.

I uploaded that code and never heard from it again, so prolly need to boot in safe mode and see what I can do. I tired a power cycle to no avail so down the device comes tomorrow.

Thanks for the help so far guys…

Hi,

I have the same problem. Have not used my particle in a while but now when starting using it again it takes a long time to connect to the router. But when it finally connects its seems stable. Trouble comes when making power on/off, pushing reset or updating SW, then again it takes many tries for it to connect, sometimes it can take up to 30min before its connected again.

After reset it starting with blinking green which is followed by blue, then it goes to yellow+red. After that it restarts with green, blue, yellow+red… and over again.

Anyone have any suggestions how to solve it?

Thanks.

I got a new device and gave up on that one.
Also still have connection issues now and then so I added a separate processor to close my door regardless of what the photon status was. My new system seems to work very well.

I managed to get mine working. I pushed setup button for over 10 seconds making the photon forget all previous networks and then connected it to the cloud. After that it works fine. I have changed password for the hotspot it connects to and my guess is that the photon have trouble handling having more than one network with same name (but obviously different login passwords) in its previous network list.

2 Likes