Skip to content

Instantly share code, notes, and snippets.

@technobly
Created July 20, 2016 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save technobly/bb27555bc293a15bbbc9bde747f818c1 to your computer and use it in GitHub Desktop.
Save technobly/bb27555bc293a15bbbc9bde747f818c1 to your computer and use it in GitHub Desktop.
Manually enter and exit listening mode with the D0 pin
// Configure a wifi network with a bogus name or password into the Photon
// Ground D0 to call WiFi.listen(true) while the connection attempt is ongoing
// Open, then Ground D0 again to call WiFi.listen(false)
///
#include "application.h"
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(AUTOMATIC);
void reconnectAfterListen() {
Particle.connect();
}
void setup() {
System.on(wifi_listen_end, reconnectAfterListen);
pinMode(D0, INPUT_PULLUP);
}
void loop() {
if(digitalRead(D0) == LOW) {
if (!WiFi.listening()) {
// Delay of ~20 seconds to enter listen mode if these 2 disconnect calls are missing
Particle.disconnect();
WiFi.disconnect();
// -------------------------
WiFi.listen(true);
}
else {
WiFi.listen(false);
}
delay(50);
while (digitalRead(D0) == LOW) Particle.process();
delay(50);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment