Detecting Listening Mode on PowerUp / Reboot

I have a need to detect and display if the Photon is in listening mode on powerup / reset. These Photons are mounted in an electrical box where the flashing blue LED cannot be seen. I have an OLED display connected to the Photon and would like to display “Listening” in this situation. These Photons, (8 so far) operate in “Automatic” mode and I would like to keep it that way if possible. I guess what I am asking for is a way to run my code in listening mode. The code I am currently using is…

#include "application.h"
#include "WebServer.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 5
#define SSD1306_96_16
Adafruit_SSD1306 display(OLED_RESET);

int listeningMode = 0;
...

void setup() {
...
    if (digitalRead(6) == LOW ) { ListeningMode(); } // manually put the Photon is listening mode
}

void loop() {
    if (! listeningMode) { // run the loop code as normal
    if (! Particle.connected()) { Particle.connect(); } // If connection is lost re-establish it
    webserver.processConnection(); // Process web requests
   // ------------------- Time / Temperature Inside and Out --------------------
    display.clearDisplay();
   ...
   }

 void ListeningMode() {
    listeningMode = 1; // disable the void loop from doing anything, i.e. clear the OLED display
    display.clearDisplay(); display.setCursor(10,0); display.setTextSize(2); display.print("Listening");
    display.setCursor(0,24); display.setTextSize(1);
    display.print(EEPROM.get(26, tempname)); // display the last known "hardware name" of the Photon
    display.display();
    WiFi.clearCredentials(); // delete all the old WiFi credentials
    WiFi.listen(); // put the Photon in listening mode
  }

(ScruffR: Did the reformatting)

I know there is some redundancy in the above code however, this same code is used to put the Photon in Listening Mode when a button is pressed on boot-up. The key to this is the OLED displays “Listening” to identify the Photon is in Listening Mode. The code works as I want on a power-up / reset IF there are Credentials currently in the Photon.

The problem is, if the Photon is reset a second time or a power cycle occurs, the Photon does not run the setup / loop code. Therefore the OLED display is blank and the user cannot tell the Photon is in listening mode.

Any Suggestions?

Sorry not sure why the include/ defines and are in large bold font. (on my screen they were normal size)

When you post code it should be enclosed like so to format it correctly,

```cpp
// your code here
```

Those tick marks are grave accent characters (the one on the same key as the tilde) not apostrophes. You can edit your post to do this.

1 Like

You can use SYSTEM_THREAD(ENABLED) in order to keep your application code running while in Listening Mode.

Thank You Rick!

Thank You, I will try it!