Photon resets to default after a few days when looping deep sleep

I’m running the below code with FW 0.4.9. Simply turning on two LEDs, for 5 seconds, turning them off, then turning off WiFi, wait 5 seconds, and go into deep sleep for 10 seconds. Setup makes sure wifi credentials are set. Basically after running this loop for a about 3-4 days, the Photon eventually clears its memory and returns to “listening” mode (blinking blue). At this point, I have to re-setup the Photon and reflash the code. Any ideas why the Photon is losing it’s brain running this simple sketch? Thanks!

int led1 = D0;
int led2 = D7;

void setup() {
  WiFi.setCredentials("WIFISSID", "PASSWORD");

  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);

void loop() {
  digitalWrite(led1, HIGH);
  digitalWrite(led2, HIGH);
  digitalWrite(led1, LOW);
  digitalWrite(led2, LOW);;

   System.sleep(SLEEP_MODE_DEEP, 10);

This cycle is a nice way to put some wear strain on the Broadcom flash.
I’d rather do this clear-set-credentials business only when required.

In a year of this you’ll have a good million of clear/flash cycles.

Ahh, ok… so you’re thinking my problem is with the clearing/setting credentials (which will happen every time it comes out of deep sleep)? I was thinking the problem was going into, coming out of, deep sleep. I’ll take that out and see if I get better results. Thanks!

In fact, if you are using this code in default SYSTEM_MODE(AUTOMATIC), if you had no valid WiFi credentials or can’t connect to your WiFi for any other reason, you setup() would never execute and hence you’d never set the credentials anyway.

Each time you do this, you’d only set the credentials for next time round and it this fails for any reason, your next wake will be blinking blue.

You’d either need to put this part in a seperate function which gets called from the STARTUP() macro or use a non-AUTOMATIC mode.

Apart from the implementation and (dis)advantages, is there any reason you’d need to sett he credentials every time? Unless you delete them, they stick, so you’d only have to set them once.

I guess my thought process was that if I took a Photon-based project to a friends house, and knew their wifi credentials, I could put those in the setup block… and when I got their house it would just work. In reality, the code posted above wasn’t a realistic use case… I was just playing around with the deep sleep mode, and I thought it was causing the device to reset itself. Basically, just testing out two different features of my new Photon, and it ended up causing me to build a snippet of code that was leading me down the wrong debug path. You guys have talked some sense into me, and I have learned something today. Thanks!


If you got a way to program the credentials to the device you’d also have the option to just put the device into listening mode and store the credentials via the standard means.
The Photon can remember up to five sets of different WiFi credentials.