[Multithreading]Photon hangs on 'clearCredentials' call

My photons are hanging after calls to ‘WiFi.clearCredentials()’ when multithreading is enabled. The photon’s LED is slowly flashing blue and the user application is not executing after the call to ‘WiFi’. Is this happening to anyone else?

Test application:

#include "application.h"


namespace usr {
  struct Timer {
    uint32_t period;
    uint32_t _end;

    bool isTime() {
      return millis() > _end;

    void start() {
      _end = millis() + period;

    void setPeriod(uint32_t T) {
      period = T;
  } wifiTestTimer;

  void setup() {
    Serial.print(" - Starting... ");

    wifiTestTimer.setPeriod(20 * 1000);

  void process() {
    if(wifiTestTimer.isTime()) {
      Serial.println("Clearing credentials...");
      Serial.println("Setting credentials...");
      WiFi.setCredentials("network", "123456", WPA2);
      Serial.println("WiFi test done.");


void setup()

void loop()

At the moment this seems to be default (but will be reworked - look here) as Listening Mode itself is blocking user code. One reason is the shared resource Serial that is taken hold of for entering credentials this way, to avoid app firmware interfering.

I guess one workaround might be to change for a non-AUTOMATIC SYSTEM_MODE and disconnect WiFi before clearing credentials.

The same thing is also happening when I use the manual system mode. And I am using system firmware 0.4.7.

I’ll have a look unless some cleverer folk get in there first :wink:

1 Like

OK, I’ve now tested your code, but added some D7 blink to actually see if user code still runs and I also added some code to prevent user::process() from permanently retriggering the WiFi test, once isTime became true (I think this is required).

And now I’m sort of stuck, since I can’t see any hanging.
This is my serial output

1447452504 - Starting... <deviceID>
Clearing credentials...
Setting credentials...
WiFi test done.

My blink only ever stopped for a brief moment while acquiring the WLAN_CIPHER and reconnecting to the cloud for about a second.
With SEMI_AUTOMATIC there was no observable delay in the blink at all.

Ah I see now, the process was missing “wifiTestTimer.setTime()”. I’ll fix and run this test again tomorrow and I’m guessing (hoping) it will work now :smiley: