# Particle Photon Connecting Timeout

**URL:** <https://community.particle.io/t/particle-photon-connecting-timeout/58674>\
**Category:** Connectivity\
**Tags:** photon\
**Created:** [December 4, 2020, 7:48pm UTC](https://community.particle.io/t/particle-photon-connecting-timeout/58674 "2020-12-04T19:48:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmativi](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jmativi](https://community.particle.io/u/jmativi)\
**Post date:** [December 4, 2020, 7:48pm UTC](https://community.particle.io/t/particle-photon-connecting-timeout/58674/1 "2020-12-04T19:48:43Z")

</div>

I have a Particle Photon. I would like to be able to tell the device to go into sleep mode for a while if it’s unable to connect to WiFi after trying for some amount of time. I have tried the following:

```
time1 = millis();   
while(WiFi.connecting())
{
    if((millis() - time1) >= 30000)
    {
        System.sleep(SLEEP_MODE_DEEP, 60); 
        break;
    }
}

```

That’s at the top of my loop(). However, when I turn off the WiFi that the Photon connects to, it just flashes green until I turn the WiFi back on (at my router). Anyone have any ideas?

I just want it to basically give up and save power to try again later when it can’t connect to WiFi. When it can connect, everything works fine.

Thank you in advance!

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 4, 2020, 7:52pm UTC](https://community.particle.io/t/particle-photon-connecting-timeout/58674/2 "2020-12-04T19:52:10Z")

</div>

Are you using `SYSTEM_THREAD(ENABLED)`?  
If not your code will stall as soon the connection is lost and probably won’t get to that portion of your code.

---

<div class="post-metadata">

**Author:** ![jmativi](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jmativi](https://community.particle.io/u/jmativi)\
**Post date:** [December 4, 2020, 9:01pm UTC](https://community.particle.io/t/particle-photon-connecting-timeout/58674/3 "2020-12-04T21:01:50Z")

</div>

I don’t call SYSTEM\_THREAD(ENABLED) anywhere… what does that do? Should I add it in the setup() function?

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [December 4, 2020, 9:04pm UTC](https://community.particle.io/t/particle-photon-connecting-timeout/58674/4 "2020-12-04T21:04:56Z")

</div>

No, you should not add it to `setup()` but _outside_ at the top of your code

To know what it does you can have a read here  
[https://docs.particle.io/reference/device-os/firmware/photon/#system-thread](https://docs.particle.io/reference/device-os/firmware/photon/#system-thread)

In a nutshell it will make sure your application is running independently of the cloud stuff which will be executed on its own “system thread”.

---

<div class="post-metadata">

**Author:** ![jmativi](https://avatars.discourse-cdn.com/v4/letter/j/ac8455/32.png) [@jmativi](https://community.particle.io/u/jmativi)\
**Post date:** [December 7, 2020, 8:15pm UTC](https://community.particle.io/t/particle-photon-connecting-timeout/58674/5 "2020-12-07T20:15:41Z")

</div>

Thank you! I added this line and switched my code around to use some WiFi.ready() if statements and it’s working like a charm. The SYSTEM\_THREAD(ENABLED) was key to getting my code to run instead of it halting on blinking green forever if it can’t see WiFi. Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/particle/original/3X/3/2/3291e3c9351789fe8620ae5bcec8d3fec67ff221.png) [@system](https://community.particle.io/u/system)\
**Post date:** [June 8, 2021, 8:15am UTC](https://community.particle.io/t/particle-photon-connecting-timeout/58674/6 "2021-06-08T08:15:47Z")

</div>

Closed on June 8, 2021, 8:15am UTC

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