Connect Photon to the Particle Cloud if Internet connected

Hi everyone,
I’m facing this problem with the usage of the Photon. My firmware is supposed to work without an Internet connect and infect I’ve put it in SEMI_AUTOMATIC- By the way, if it is internet connected, I want to try to update the firmware OTA, but if it doesn’t I don’t want the Photon is blocked, trying to connect to the cloud, without ruining the code. How Can I do it? Please write also the lines to put in the setup() method, to perform this!

Thank you in advance for your help!

In most of your other threads you were told about SYSTEM_THREAD(ENABLED) and the docs do also tell how to connect to the Particle cloud - just look at the docs for SEMI_AUTOMATIC.

Thank you for your reply. The problem is that if I try to put Particle.connect() in the setup and there is no an Internet connect, this is blocking and loop doesn’t run. Can you provide me an example of code, to perform what I want?
Thank you in advance for your help!

You keep ignoring this keyword mentioned lots of times to you in regards to your previous questions that go down the same path.

And if you read the docs you will find a full tool set to prevent blocking.
https://docs.particle.io/reference/firmware/photon/#cloud-functions
https://docs.particle.io/reference/firmware/photon/#wifi
https://docs.particle.io/reference/firmware/photon/#system-thread

Thank you for your reply. I’ve read many times the documentation, but I’ve never figure out the solution about my problem. It is forum and it is a good idea to show the solution and not just write other things. I just need to run a firmware correctly both cases I’ve an internet connection and without it.

Might seem a good idea for you, but not so much for us as we already have done that numerous of times and would have to do the same over and over again.
If you show what you tried so far to tackle your problem, we might see where you were not quite doing it right. This way you can learn more than by being spoon fed a solution.

That’s me code:

SYSTEM_MODE(SEMI_AUTOMATIC);

void setup()
{
Serial.begin(9600);
Serial.println(“Setup”);
Particle.connect();
}

void loop(){
//
}

I still see no sign of SYSTEM_THREAD(ENABLED) - have you even tried it?

I’ve tried both, with it or not, but the loop doesn’t run.

SYSTEM_MODE(SEMI_AUTOMATIC)
SYSTEM_THREAD(ENABLED)
void setup()
{
  pinMode(D7, OUTPUT);
  Particle.connect();
}
void loop(){
  digitalWrite(D7, (millis() >> 2) & 0x88);
}

That’s definetly not what I see. Running this code, with or without WiFi connection the D7 LED keeps blinking - even when the connection drops out and also on reconnect.
What system version are you targeting?

Thank you for your reply. Unfortunately the code you send, doesn’t work, since the Photon is blinking blue if there are no internet connection and the wifi connection is lost at each loop…

If all you want to do is check if you have internet you could do something simple like:

     /*
      * Check if there is Internet by pinging 8.8.8.8
      * Returns true if there is Internet; false if not.
      */
      bool have_internet()
      {
        // Should return the number of hops.
        if (WiFi.ping(IPAddress (8,8,8,8), 5) == 0)
          return false;
        return true;
      }

which can enable you to do something like:

if(have_internet())
   Particle.connect();

I’m pretty sure the code does work exactly as I intended it to work, which was to proof that this statement is not true

loop() does in fact run without internet connection and the blue D7 blink pattern proofs it (if need be I can post the video too).

And since loop() does in fact run, all power is yours to make use of this fact by employing the other functions listed under WiFi and Particle in the docs to achieve what you want (including WiFi.scan(), WiFi.ping(), WiGi.resolve(), …)
But since your demands are formulated rather open we could provide a full project which might still not do what you want - hence people write their own programs.

BTW, you haven’t answered my question about your targeted system version.