Using WiFi.off()

Hi Everyone, Just a quick question, is there anyway that in my coding i can call WiFi.off() while my photon is on listening mode and then later if i want to leave an WiFi.off() be able to go back to previous mode which in this case it was in the listening mode?

The reason for this is because I want a user to be able to put his photon offline even if it is in the listening mode and maybe for some reason his photon cannot connect to his router.
I have attached few lines of coding. So far a photon can go from listening mode to offline easily but doesn’t leave the offline mode unless i restart the photon.

if (mbut == UI_SELECT) {
    if(WiFi.listening()) {
       WiFi.off();
    }
    else{
      WiFi.on();
    }
}

Thanks!

By default Listening Mode suspends execution of your code, hence your code cannot end Listening Mode which means you need to reset the device (or use any of the repspective serial commands to make Listening Mode end itself).
In order to keep executing your application code while in Listening Mode you need to use ´SYSTEM_THREAD(ENABLED)`.

However, can you elaborate a bit more why you want WiFi.off() in Listening Mode? That somewhat defeats the purpose of Listening Mode.

When the Photon is put into Listening Mode it will disconnect from the previous WiFi router anyway since it will expose its own SoftAP (which it couldn’t with WiFi.off()).

Lately I have been receiving complaints from some of my clients having issues with connecting the photon to their router but somehow in my studio all these photons that my clients are complaining about they do connect just fine.

Now this is why and my teammates agreed that it’d be better if we have an option for a user in UI to switch off the wifi so that the Photon can breath a constant white instead of flashing blue since that can somehow irritate the user.

FYI before we ship off the photons to clients, we completely reset WiFi credentials meaning the client always receive it in listening mode

In that case, I’d suggest an entirely different approach (thinking outside the box).

If you want your device to not be in LM you may want to opt for SYSTEM_MODE(SEMI_AUTOMATIC)

I’m also not conviced that this …

… should be addressed by “faking” signals like …

Breathing white has a distinct meaning which is entirely different from Listening Mode.

I’d think an uninstructed user won’t be able to make sense of either signal but good communication can help users understand any signal.
Assumptions what users may or may not understand are typically only rarely helpful, but properly “educating” them should be the preferred way.

Having said that, we’d need more background on the actual, intended behaviour of your devices in these situations and what your UI would do in such cases to provide better advice.

Also, have you considered taking over RGB control to disable or reappropriate the RGB LED instead of “messing” with the underlying logic to indirectly achieve something you could get cheaper otherwise?

Okay thanks for advise I will opt for SYSTEM_MODE(SEMI_AUTOMATIC) surely it will help me,

Anyway eventually I would like to fix this problem once and for all, so like i said before that other devices cannot connect to other clients router but it does successfully connect to my studio.

When the device is at my client’s house and using the app to connect, the app will go through all the process of connecting and the device will also attempt to connect but lose connection afterwards and go back to flashing blue even after the app report that the device is successfully connected.

So it seems like these devices they don’t make it to the cloud.
I would really appreciate your insight based on that.

You will need some info from your users about their WiFi environment.
e.g. WEP needs some special care with providing the key, 5GHz networks are not supported, captive portals are neither, are they using a proxy, …

Without a complete understanding of the context any “counter action” will be no more than a shot in the dark.