WiFi listen mode without pushing the reset button

I need to enter wifi listen mode when I move the photon board to a new location with new SSID & PWD. The board is inside a box so I cannot access the reset button. The wifilistening() function works well if I have a current wifi access so that I can use a function code to force the photon to enter listening mode. But if enter a new area that I cannot access the existing wifi or hardware reset button, is there a way that the during the power on sequence, the code can detect the new wifi situation and automatically enter listening mode?

Try searching the forums, this has been asked before with solutions.

1 Like

Hi @Peter75 -

I might be to assist as I have had similar situations. Quick question, would it be possible to implement a button of some sort on the enclosure, or do you have any expose external pins for sensors maybe. Have a look at this project I did.

I used the same pin I connect a sensor to. I assigned an interrupt to it when the pin is pulled to Ground which then enters listen mode. I also added a pull-up resistor to keep the pin high unless when pulled down specifically.

If you do not have exposed pins, there is a way to do this in software which is a bit more tricky.

Let me know if you have any questions.

Regards, Friedl.

Hi Friedl:

Thank you for your quick response. This is my first thought. Unfortunately, the PCB and box are already built and the size is very limited to add a hardware switch. If there is a software solution, it certainly will be much more preferred.

Peter

HI @Peter75 -

My pleasure, I hope I can assist :slight_smile:

I understand, I had a similar situation with a water tight enclosure. I did have a software solution at the time, but it was not working consistently. The problem occurred when a product needed to be connected to a network the first time. All other scenarios worked seamlessly, automatically switching between modes.

My C++ skills have improved a little, let me see what I can do. Can you tell me which mode are your running, Automatic, Semi-Automatic or Manual as well as do you have Threads Enabled?

Regards,
Friedl.

@Peter75, @friedl_1977, it might be worth doing a search in the forum. I just turned this up:

There are likely more posts worth looking at.

3 Likes

Hi friedl_1977 :

I normally use automatic mode. I did try the following semi-automatic code. It does not seem to enter the WiFi listening mode when I turned off WiFi router.

@Peter75 -

Trying some things now, will let you know as soon as I manage :wink:

Hi @Peter75

EDIT:: Found a bug in my code… will fix it ASAP and repost…

Regards,
Friedl.

Hi friedl_1977

Thanks again. I tried your code. Here are the test results:

  1. Regardless whether if there is a previously konwn WIFI or no WIFI, after trurn on Photon, it goes through slow blue breathing for a few sec then go onto listeing mode (1 sec blue ) for 20 seconds.
  2. If there is a previously known WIFI, it goes to connect and works porperly afterward. Even if the WIFI network is turn off and on again, it automatically re-connects.
  3. If there is no WIFI, the Photon will continue to try to connect but will not enter listening mode anymore. If the known WIFI is turn on later, it will connect the work properly.
  4. I did not have a way to test the situation when there is a new WIFI network when power on the Photon. I assuem that it will do (1) then (3), similar to no WIFI situation.

I suppose that this will work, as long as I extend the period of listenning mode for a longer period (e.g. 60 sec) during power on sequence. This way, there is probably enough time for user can follow the normal “unclaim and claim”) process to connect the Photon to the new network.

Peter

1 Like

Hi @Peter75 -

Yes sorry, I did see the ‘bug’… In my case it is acceptable that it starts in LM and then exits regardless of WiFi presence or not. After exiting LM it connects to WiFi, seems similar to what you found.

For me the problem is that once connected to a WiFi network and loses connection (maybe faulty router or AP) it will remain trying to connect with the stored credentials UNLESS you hit reset (power down/power up) which will allow it to enter listen mode.

This is not acceptable to me though, haha, so I will hack away until I resolve it. I have it working the other way around in Automatic mode, but this renders is useless when WiFi credentials change. Give me a while, I just need to take my Calculus test now. I will hopefully have working code for you by tomorrow??

Regards, Friedl.

Good luck with your test. I look forward to hearing from you. I will continue to test the current solution to make sure it is bullet proof.

Peter

1 Like

Thanks :).

I will post new code as soon as I can!!

Regards,
Friedl

Hi friedl:

I implemented the following code. It seems to work consistently. I tested it both at my home WiFi network and at another WiFi network. I was able to setup new WiFi credentials during the 60 seconds listening mode. Do you see any situations that this code may not work?

1 Like

You forgot to post the code.

1 Like

Hi @Peter75 -

Glad to here it is working :partying_face: There was one instance I found it to not work as I intended which is why @picsil I removed the code until I could find the bug. Here is the code again if I recall correctly.

Here is the scenario I found:

The device starts up and succesfully connects to WiiFi. After a period and for whatever reason, the Network goes down… My intention here was that after t-seconds the device again enters listen mode without user intervention, which seems not to be the case. Instead the device simply keeps trying to connect to WiFi. The workaround of course is to restart the device (power down/power up if you dot have access to the buttons) which then prompts it to look for WiFi and if not found, enter Listen Mode.

As soon as I have code working in ALL these scenarios, I will edit this post again :wink:

#include "Particle.h"

SYSTEM_MODE(SEMI_AUTOMATIC);

unsigned long old_time = millis();      // set Timeout to enter Listening Mode

void setup() {
    
    WiFi.on();
    
    old_time = millis();
    WiFi.setListenTimeout(20);         //Set Listen Mode timeout - exist listen mode aftr timer expires. 

}

void loop() {

    timer();
    connect();    
}

void timer() {
    
    if(millis() - old_time >= 20000)  {      // set time to try connect to Wifi before entering Listen Mode    
        if(!WiFi.ready()){
            WiFi.listen();
        }
   }
}


void connect() {                                        // Connection to Particle Cloud initiated
    
        if(Particle.connected() == false) { 
           if (WiFi.ready() == true) {
                Particle.connect();
         }
     }
 }    

Glad to hear it is working for you @Peter75, but I will keep trying until the bug is resolved :slight_smile: If this code is resolving the issue, would you mind marking it solved :wink:

Regards,
Friedl.