Cannot use Photon with intermittent wifi

If the wifi (router) is working but the internet (fiber) is disconnected, the photon makes a strange behavior.
How can I ensure that the photon can work properly on these three cases?:

  1. wifi with internet
  2. wifi without internet
  3. no wifi
    and a combination of all the above…

The photon wont respond until the wifi with internet returns, it blinks cyan for 5-10 seconds, then breathes green for about 5 seconds, then blinks yellow twice and blinks cyan again. It is as stubborn as me…

How long does it try Particle.connect(); ? what happens if it does not reach the internet? How can I program it to “let it go” and stop trying over and over to connect? maybe giving it a few seconds between tries. My code needs to run continuously becasue it is reading a sensor several times per second. This wifi problem screws everything.

Im using:
SYSTEM_THREAD(DISABLED)
SYSTEM_MODE(MANUAL);

Take a look at:
System thread (enabled)
System modes

System threading separates the particle system processes from the user code, letting your sensors continue to collect data.

Semi automatic or manual modes let you have more control over the connection process.

Thanks @Mjones
I used to have threads enabled but Im using softap to get new wifis and I realized it did not work properly (SOS).
I had to get rid of a huge amount or RAM and disable threads.
Would you please explain how the threads enabled work? I mean, if I need to have continuous readings from a sensor and the other thread takes care of the wifi, where can I see this working or control it?
Do you have a sample of code that I can use as main structure ?

My needs are:
A)

  1. wifi with internet
  2. wifi without internet
  3. no wifi
    and a combination of all the above…

B) continuos readings of sensors.
(note: if no internet I am storing the results in RAM, If internet is back I publish the stored results)

thanks

If you had to free up memory to get your system to run, you probably don’t have that option on the photon. Have you looked at migrating to the Argon?

You can read about all of the benefits of system_thread(enabled) here: Device OS API | Reference Documentation | Particle

Hi there, I have used Photons for a few outdoor projects that have varying WiFi signal and poor internet reliability (has IP address but no internet, aka blue flashing). I have experienced the exact some things you describe.
My solution was to completely control the enabling, connecting and disconnecting of all things internet. I use a state machine to control the connecting sequence. I also use Blynk for IoT interface.

uint32_t msStepTime = 1000; // timer used to for the connection step logic
Timer stepTimer(msStepTime, stepOK, FALSE);         // timer to step logic, was oneshot, now repeditive

//**********************************************
// Function to handle particle and Blynk connect
//
//
//**********************************************
void handleInternet(void)
{
  switch(iConnectStep)
  {
    case 0: // Switch off the WiFi
    {
      WiFi.off();
      bWifi_On = FALSE;
      bStepNow = FALSE;
      stepTimer.changePeriod(1000);
      stepTimer.start();
      iConnectStep++;
      iConnectRetry++;
    } break;
    case 1: // wait for 2sec
    {
      if(bStepNow)
      {
        iConnectStep++;
      }
    } break;
    case 2: // Switch on the WiFi after the step timer delay
    {
      WiFi.on();
      bWifi_On = true;
      bStepNow = FALSE;
      stepTimer.changePeriod(1000);
      stepTimer.start();
      iConnectStep++;
    } break;
    case 3: // Wait one second then attempt connection
    {
      if(bStepNow)
      {
        bStepNow = FALSE;
        stepTimer.changePeriod(60000);
        stepTimer.start();
        iConnectStep++;
        WiFi.connect();
      }
    } break;
    case 4: // Wait for WiFi to be connected or 60sec timeout
    {
      if(WiFi.ready())
      {
        iConnectStep++;
      }
      if(bStepNow) // Has timed out
      {
        iConnectStep=0;
      }
    } break;
    case 5: // Connect to Particle server
    {
      bStepNow = FALSE;
      stepTimer.changePeriod(60000);
      stepTimer.start();
      iConnectStep++;
      Particle.connect();
    } break;
    case 6: // Wait for Particle connected
    {
      if(Particle.connected())
      {
        iConnectStep++;
      }
      if((bStepNow) || !WiFi.ready())// Has timed out or no wifi
      {
        iConnectStep=0;
      }
    } break;
    case 7: // Start the Blynk Authentication, with a timeout
    {
      bStepNow = FALSE;
      stepTimer.changePeriod(60000);
      stepTimer.start();
      iConnectStep++;
      Blynk.begin(auth); // Do this after we've started the timer
    } break;
    case 8: // Wait for Blynk connected or timeout
    {
      if(Blynk.connected())
      {
        iConnectStep++;
        iConnectRetry=0; // Reset our retry count because we've connected successfully
        stepTimer.stop();
      }
      if(bStepNow) // Has timed out
      {
        iConnectStep=0;
      }
    } break;
    case 9: // Process Blynk requests
    {
      Particle.process();
      Blynk.run();
      // If we lost connection to Blynk cloud or Particle then restart the process
      if((Blynk.connected() == false) || (Particle.connected() == false))
      {
        iConnectStep = 0;
      }
    } break;
    default:
    {
      iConnectStep = 0;
    } break;
  }
}

//**********************************************
// Function triggered via a timer interrupt
//
//**********************************************
void stepOK()
{
  bStepNow = TRUE;
}


The above function is called in loop() and SYSTEM_MODE(MANUAL), SYSTEM_THREAD(ENABLED) must be set at the top of the program. Not all variable declarations are shown, this is part of the full working code.

I have also found that under patchy reception sometimes the Photon processor CPU never returns from some of its Ethernet or internet functions and you end up with a solid LED of various colours. This situation requires a physical press of the reset button. But given that my projects are outdoors and not easily accessible I’ve had to build separate external watchdog reset circuits that the Photon ‘pats’ periodically, without which the Photon has its reset pin triggered which reboots it.

Hope this is helpful.

2 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.