WiFi.listen(false) doesn't work? Please nooooo


#1

Say it ain’t so…
How do I exit listen mode on a photon?

The following is an edit… I tried a bunch of stuff posted by @mdma and @ScruffR (thanks guys) But basically SYSTEM_THREAD(ENABLED) causes WiFi.listen(false) not to work. I have found this to always be true.

I tried a lot of different tests, but I think this is the most telling.
This works fine (as expected) example posted by mdma

#include "application.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

void listen(system_event_t event, uint32_t param, void* pointer)
{
    if (event==wifi_listen_update)
    {
        // exit listen mode after 3 seconds
        if (param>3000) {
            WiFi.listen(false); 
        }
    }
}

void setup()
{
    WiFi.on();
    System.on(wifi_listen, listen);
    WiFi.listen();
}

void loop()
{
}

if you add SYSTEM_THREAD(ENABLED) after the include statement it doesn’t work.


#2

You can use multithreading - add

SYSTEM_THREAD(ENABLED)

to the top of your sketch. That will then run your loop() code even when the system is listening.

EDIT: oh, I see you have that. Please be sure to update to 0.4.7 firmware.

Alternatively, there is a system event, that calls a function regularly during listen mode, this is described here - Implications of customized system firmware - Photon


#3

isn’t it SYSTEM_THREAD(ENABLED)? that’s what the docs say. It appears to be threading… because I can see the D3 continuing to toggle. without threading it doesn’t toggle.

Jerome


#4

yeah that was a typoi. :wink: Threading is still a beta feature - we are rounding off the edges. To be absolutely certain your code is called regularly to interrupt listening mode, please use the system events as linked above.


#5

I will give it a whirl soon. Thanks for the feedback


#6

I guess you’d need to change this.
Once your loop count exceeds 240 you will be triggering both statements in short succession.
I guess this is not what you want, is it?

Maybe something like this would be better

  // only between 120 and 240 start listening
  if((120 < loop_cnt && loop_cnt < 240) && !WiFi.listening()) WiFi.listen(); 
  // beyond 240 stop listening
  if((loop_cnt > 240) && WiFi.listening()) WiFi.listen(false);

#7

@ScruffR thanks for pointing out the coding error… However even after I fixed it WiFi.listening(false) still doesn’t work if threading is enabled.

Jerome


#8

I tried a bunch of stuff posted by @mdma and @ScruffR (thanks guys) But basically SYSTEM_THREAD(ENABLED) causes WiFi.listen(false) not to work. I have found this to always be true.

I tried a lot of different tests, but I think this is the most telling.
This works fine (as expected) example posted by mdma

#include "application.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

void listen(system_event_t event, uint32_t param, void* pointer)
{
    if (event==wifi_listen_update)
    {
        // exit listen mode after 3 seconds
        if (param>3000) {
            WiFi.listen(false); 
        }
    }
}

void setup()
{
    WiFi.on();
    System.on(wifi_listen, listen);
    WiFi.listen();
}

void loop()
{
}

if you add SYSTEM_THREAD(ENABLED) after the include statement it doesn’t work.


#9

I noticed this… If I load the following code and configure the device using the serial terminal (once the device is in listen mode) this connects fine. Whatever the system does at the end of Serial configuration needs to be done with WiFi.listen(false).

#include "application.h"


SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);


void setup()
{
  WiFi.on();
  Particle.connect();
  WiFi.listen();
}

void loop()
{
}

#10

@mdma, any news that this might be fixed in the next firmware release?


#11

It’s fixed and will be in the next release.

All issues open/fixed are listed against release milestones in the github repo, e.g. searching for issues matching 0.4.9 and WiFi.listen(false):


#12

@mdma
Hello,
Is WiFi.listen(false) working? I have tried

#include “application.h”

SYSTEM_MODE(SEMI_AUTOMATIC);

void listen(system_event_t event, uint32_t param, void* pointer)
{
if (event==wifi_listen_update)
{
// exit listen mode after 3 seconds
if (param>3000) {
WiFi.listen(false);
}
}
}

void setup()
{
WiFi.on();
System.on(wifi_listen, listen);
WiFi.listen();
}

void loop()
{
}

But it gives compilation error. I am building against the latest particle release. (using particle cli to compile). My platform is P1. I need to shut off WiFi.listen(). Please suggest how.

EDIT:
changing uint32_t to int solved the compilation issue. It got compiled but still the access point won’t shut off.


#13

No double posting please


#14