Automatically enter and exit listening mode


#1

Would like to set up a photon to automatically start up in listening mode and remain there for five minutes before exiting this mode.

The idea is to give the opportunity to allow setting up a connection to an Access Point using SoftAP without the need to press the set up button (which in this case is not readily accessible).

I have tried the following without joy, ie it would NOT exit listening mode:

setup()
{
WiFi.listen(TRUE);
// Want to stop listening after 5 minutes
oneShot5minTimer.start();

}

// --------------------------------
// Called just once after 5 minutes
// --------------------------------
void OneShot5minTimerCallBack(void)
{

WiFi.listen(FALSE);

}

I admit to not having experimented further with this as yet, it is probably not working because the call is within a timer callback. If this is the issue, will shift it to the main loop and make the call when a flag is set.

Are there any other strategies, thoughts on how to achieve the aim?


#2

For one, I’d start the timer before entering Listening Mode and additionally if you use SYSTEM_THREAD(ENABLED) you can have your loop() run while in LM.

And as a final hint, using the STARTUP() macro makes sure that you are entering LM as early as possible.


#3

@ScruffR, guess what?

There is an API to do exactly what I want to do - WiFi.setListenTimeout(seconds):

https://docs.particle.io/reference/firmware/photon/#setlistentimeout-

Out of interest, I did try what you suggested and it worked, but my “wifi reconnect” strategy got in the way by kicking off a WiFi connection within loop() and hence a much shorter timeout. I was going to add logic to check to see if it was listening and if so, not to kick off my strategy.

Interesting thing is that by using the WiFi.setListenTimeout() API, my WiFi reconnnect strategy does not kick in (which is good), ie it remains listening for the set timeout.

Case closed!


#4

:+1: Completely forgot about that :blush: