# Photon/P1 loop()/user code blocking in SEMI\_AUTOMATIC mode

**URL:** <https://community.particle.io/t/photon-p1-loop-user-code-blocking-in-semi-automatic-mode/14089>\
**Category:** Troubleshooting\
**Created:** [August 4, 2015, 12:07am UTC](https://community.particle.io/t/photon-p1-loop-user-code-blocking-in-semi-automatic-mode/14089 "2015-08-04T00:07:21Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [August 4, 2015, 2:31pm UTC](https://community.particle.io/t/photon-p1-loop-user-code-blocking-in-semi-automatic-mode/14089/4 "2015-08-04T14:31:28Z")

</div>

@bing1106, I’m not sure if you actually tested how long application code is blocked during connection attempts.  
But if you want to get a feeling how the Photon behaves in your outlined scenario have a play with this code

```auto
SYSTEM_MODE(SEMI_AUTOMATIC);

const uint32_t waitConnect = 5000; // at least 5 sec between reconnect attempts

uint32_t msConnect;
bool firstAttempt;

void setup() 
{
    pinMode(D7, OUTPUT);
    WiFi.connect();
    firstAttempt = false;
}

void loop() 
{
    if (firstAttempt && Spark.connected())
    {
        firstAttempt = false;
    }
    else if(!firstAttempt && !Spark.connected())
    {
        Spark.connect();
        firstAttempt = true;
        msConnect = millis();
    }

    digitalWrite(D7, millis() & 0x80); // blink every 256ms
}

```

When looking at the onboard LED, you’ll see that it does not block permanentliy till a cloud connection is reestablished, but only for up to 5sec (on my device this is).  
If your code can cope with this kind of blocking periode, you can even get away without any interrupts.

---

_[View the full topic](https://community.particle.io/t/photon-p1-loop-user-code-blocking-in-semi-automatic-mode/14089)._
