# Can a photon boot without WiFi?

**URL:** <https://community.particle.io/t/can-a-photon-boot-without-wifi/17685>\
**Category:** Troubleshooting\
**Created:** [November 22, 2015, 5:38am UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685 "2015-11-22T05:38:43Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jrubins](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@jrubins](https://community.particle.io/u/jrubins)\
**Post date:** [November 22, 2015, 5:38am UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/1 "2015-11-22T05:38:43Z")

</div>

Just moved to a new place today, but the at&t won’t be hooked up until next week. My dryer isn’t working, the photon keeps blinking green (that’s looking for WiFi, right?). Will it eventually boot without WiFi or am I stuck without a clothes dryer until att hooks us up?

Thanks,  
JR

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [November 22, 2015, 6:02am UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/2 "2015-11-22T06:02:44Z")

</div>

In the default mode (AUTOMATIC), the user code will only run when wifi is connected.

You can attempt to create the same Wifi SSID and password using your mobile hotspot and then modify the code to work without wifi first.

Let us know if you need help!

I have an example here: [https://github.com/kennethlimcp/particle-examples/blob/master/wifi-auto-reconnect/wifi-auto-reconnect.ino](https://github.com/kennethlimcp/particle-examples/blob/master/wifi-auto-reconnect/wifi-auto-reconnect.ino)

---

<div class="post-metadata">

**Author:** ![jrubins](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@jrubins](https://community.particle.io/u/jrubins)\
**Post date:** [November 24, 2015, 1:09am UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/3 "2015-11-24T01:09:48Z")

</div>

Hey kenneth, I tried adding your code to my own, but now it takes several seconds -minutes to register button presses. Will the photon run with just WiFi.off()? If so, how do I update it later?

---

<div class="post-metadata">

**Author:** ![kennethlimcp](https://avatars.discourse-cdn.com/v4/letter/k/c0e974/32.png) [@kennethlimcp](https://community.particle.io/u/kennethlimcp)\
**Post date:** [November 24, 2015, 2:01am UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/4 "2015-11-24T02:01:43Z")

</div>

If you use `WiFi.off()` you will have to manually place it in dfu mode to flash firmware.

Can you paste your code in a gist and share the link so that we can see why the button presses are taking so long to register?

---

<div class="post-metadata">

**Author:** ![jrubins](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@jrubins](https://community.particle.io/u/jrubins)\
**Post date:** [November 24, 2015, 3:57am UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/5 "2015-11-24T03:57:46Z")

</div>

First time using a gist, let me know if it works/doesn’t

> <https://gist.github.com/anonymous/317d484723d375a8d4a1>

---

<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:** [November 24, 2015, 12:33pm UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/6 "2015-11-24T12:33:09Z")

</div>

Also _Safe Mode_ and OTA flash would be possible (if a WiFi network is available and credentials are set too).

Try using `Piettetech_DHT` library instead of `Adafruit_DHT` (which sometimes blocks).

You should also add a “one-shot” flag for your `WiFi.connect()` and `Particle.connect()` (`Spark.connect()` should be replaced by the new wording ;-)) attempts, to not interfere with a running attempt by retriggering the connect.

---

<div class="post-metadata">

**Author:** ![jrubins](https://avatars.discourse-cdn.com/v4/letter/j/c67d28/32.png) [@jrubins](https://community.particle.io/u/jrubins)\
**Post date:** [January 6, 2016, 6:17am UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/7 "2016-01-06T06:17:30Z")

</div>

Hi ScruffR,  
I have still been having issues with my photon ‘locking up’. A quick reset usually sets things right. I’ve updated the DHT library to the PietteTech lib. However, I’m wondering if the wifi connection may also play a role… If nothing else, I want to handle dropped wifi connections a little more gracefully. Ideally, the photon will start up, look for wifi, and if the network is there, connect and start running code. If no connection is available, it should go about running it’s code, but every 5 or so minutes, try to connect to wifi.

One thing that I’m struggling with is the notion of wifi.connect() and particle.connect(). What is the difference between the two? When does one get used over the other?

Thanks,  
JR

---

<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:** [January 6, 2016, 2:01pm UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/8 "2016-01-06T14:01:16Z")

</div>

The locking up, might be an issue difficult to track down with this many libraries playing together (or not).  
Maybe you need to step back a bit and add one component after the other, starting with the one most likely to be the foe. I’ve used the DHT sensors without pull-up resistors, but I think the recommendation is to use one.

But for your WiFi issue there definetly is a cure.  
First thing is to change from default `SYSTEM_MODE(AUTOMATIC)` to `SYSTEM_MODE(SEMI_AUTOMATIC)` which allows your code to run even without cloud and/or WiFi connection - and possibly also use `SYSTEM_THREAD(ENABLED)`.  
This then brings us to the difference between [`WiFi.connect()`](https://docs.particle.io/reference/firmware/photon/#wifi-connect-) and [`Particle.connect()`](https://docs.particle.io/reference/firmware/photon/#particle-connect-) (which actually would be explained in the docs ;-)).  
The former **_only_** connects your device to your local WiFi network, so you could use TCP/UDP communication but would not have the `Particle.xxxx()` cloud functions working. For these to work you also need to call `Particle.connect()` (which implicitly would call the former, if there is no WiFi connection already).

So a possible use case for you might look like this

```cpp
SYSTEM_MODE(SEMI_AUTOMATIC)
SYSTEM_THREAD(ENABLED)

const uint32_t msRetryDelay = 5*60000; // retry every 5min
const uint32_t msRetryTime = 30000; // stop trying after 30sec

bool retryRunning = false;
Timer retryTimer(msRetryDelay, retryConnect); // timer to retry connecting
Timer stopTimer(msRetryTime, stopConnect); // timer to stop a long running try

void setup()
{
  Serial.begin(115200);
  pinMode(D7, OUTPUT);
  Particle.connect();
  if (!waitFor(Particle.connected, msRetryTime))
    WiFi.off(); // no luck, no need for WiFi
}

void loop()
{
  // do your stuff
  digitalWrite(D7, !digitalRead(D7));
  
  if (!retryRunning && !Particle.connected())
  { // if we have not already scheduled a retry and are not connected
    Serial.println("schedule");
    stopTimer.start(); // set timeout for auto-retry by system
    retryRunning = true;
    retryTimer.start(); // schedula a retry
  }
  delay(500);
}

void retryConnect()
{
  if (!Particle.connected()) // if not connected to cloud
  {
    Serial.println("reconnect");
    stopTimer.start(); // set of the timout time
    WiFi.on();
    Particle.connect(); // start a reconnectino attempt
  }
  else // if already connected
  {
    Serial.println("connected");
    retryTimer.stop(); // no further attempts required
    retryRunning = false;
  }
}

void stopConnect()
{
    Serial.println("stopped");

    if (!Particle.connected()) // if after retryTime no connection
      WiFi.off(); // stop trying and swith off WiFi
    stopTimer.stop();
}

```

---

<div class="post-metadata">

**Author:** ![tobia](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/tobia/32/5334_2.png) [@tobia](https://community.particle.io/u/tobia)\
**Post date:** [July 2, 2016, 9:35pm UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/9 "2016-07-02T21:35:23Z")

</div>

[rant redacted—see below]

Why are @kennethlimcp’s and @ScruffR’s solutions so different???

I’d really like an official example on how to make the user code always run and the WiFi connection interfere as little as possible, even when no signal and/or no Internet is present.

---

<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:** [July 3, 2016, 6:09am UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/10 "2016-07-03T06:09:14Z")

</div>

Apparently 😉 in order to have `waitFor()` work properly you'd need `SYSTEM_THREAD(ENABLED)` anyway.

> [@tobia](#):
>
> I'd really like an official example on how to make the user code always run and the WiFi connection interfere as little as possible, even when no signal and/or no Internet is present.

I'm not convinced that there will/should be an "official" example since both ways do their job but act slightly different - neither is better than the other IMHO.  
So it's up to the user to select the best fitting for his purpose or even come up with an own solution.  
These should not be taken as boilerplate code but only _ **show what** _ can be done, to make an informed decision.

---

<div class="post-metadata">

**Author:** ![tobia](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/tobia/32/5334_2.png) [@tobia](https://community.particle.io/u/tobia)\
**Post date:** [July 3, 2016, 2:53pm UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/11 "2016-07-03T14:53:42Z")

</div>

After some experimentation, I found that the simplest and most effective way to make WiFi-proof Photon applications is to leave everything in the default configuration and just enable the system thread:

```
SYSTEM_THREAD(ENABLED);

```

No mucking around with timers, countdowns, `WiFi.on()`, and so on.

This makes `setup()` and `loop()` run as soon as the power is connected—literally, even while the LED is still white—and keep running while the system thread looks for a WiFi, tries to get online, looks for the Particle servers, handshakes, etc.

Edit: the only exception seems to be if you need to register cloud variables or functions: in that case, you also need to set `SYSTEM_MODE(SEMI_AUTOMATIC)` and to register all the variables and functions **before** calling `Particle.connect()`. The docs explain this well.

Thanks a lot to the system engineers that [worked on this feature](https://community.particle.io/t/particle-firmware-update-thread/14378/12). It’s awesome!

---

<div class="post-metadata">

**Author:** ![jsejcksn](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/jsejcksn/32/16233_2.png) [@jsejcksn](https://community.particle.io/u/jsejcksn)\
**Post date:** [January 7, 2018, 6:25am UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/12 "2018-01-07T06:25:54Z")

</div>

@tobia Thanks for your message; it helped me greatly and pointed me to what I needed to research in the reference documentation. On that topic, I wanted to post an update to what you wrote because the bit you added about cloud variables and functions seems to have changed—from the [System Thread section](https://docs.particle.io/reference/firmware/photon/#system-thread) in the reference docs:

> `Particle.function()`, `Particle.variable()` and `Particle.subscribe()` will function as intended whether the cloud is connected or not.

---

<div class="post-metadata">

**Author:** ![PopQuiz](https://avatars.discourse-cdn.com/v4/letter/p/c67d28/32.png) [@PopQuiz](https://community.particle.io/u/PopQuiz)\
**Post date:** [August 21, 2018, 3:14am UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/13 "2018-08-21T03:14:01Z")

</div>

How do you access setup mode to change wifi credentials while in Semi-Auto mode? I have a Photon running in Semi-Auto mode and when you hold setup, the light will flash blue for a little while, but not really long enough to connect to it and setup new credentials.

---

<div class="post-metadata">

**Author:** ![AaronD](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@AaronD](https://community.particle.io/u/AaronD)\
**Post date:** [August 23, 2018, 11:36pm UTC](https://community.particle.io/t/can-a-photon-boot-without-wifi/17685/14 "2018-08-23T23:36:09Z")

</div>

@PopQuiz, I was able to solve that problem like this.

> [@Go into listening mode if no known networks are available](https://community.particle.io/t/go-into-listening-mode-if-no-known-networks-are-available/28701/12):
>
> Ok, here’s the code I ended up with. It’s certainly not as compact/clean as it could be, but I’m still learning so trying to keep it as simple as possible for my benefit. Any comments/advice appreciated. UPDATE: Moved WiFi.disconnect() and listen() calls outside of signaling for() loop as caught by @ScruffR below (thanks). #include "Particle.h" #include "softap\_http.h" SYSTEM\_MODE(SEMI\_AUTOMATIC); SYSTEM\_THREAD(ENABLED); // INITIALIZE VARIABLES ===…

It looks for known WiFi networks on boot up and if it doesn't find one starts the softap and starts listening for new credentials, after which it performs a system reset. In the meanwhile it continues to run loop code in parallel.

If WiFi info ever changed (router was reconfigured) I guess I'd have to reboot it to give new credentials. Maybe you can improve on that part.
