Hi there! I’m working on a low power wifi project with a Photon and am having some trouble getting consistent publishing after coming out of deep sleep in MANUAL mode. After digging in the forums and not finding anything addressing this particular problem, I’m here to ask for some help. (Apologies if I’ve missed this problem being addressed somewhere else!) The idea of the device’s functionality is to:
- wake up
- take some sensor readings
- turn on wifi
- connect to particle
- publish those readings
- disconnect from particle
- turn off wifi
- deep sleep for some consistent amount of time (60 seconds in the code below)
The issue I’m experiencing is that it’s doing all steps consistently except step 5 - publishing. Every once in a while (read: 65%+ of the time), the Photon connects to wifi, connects to particle, ‘publishes’ with an ACK - but nothing shows within Particle Console, the webhook doesn’t fire, nothing. The Photon publishes just fine when substituting the sleep for a delay of the same time.
There’s quite a bit of serial debugging in the code below, so turn verbose_mode
off if you’re feeling spammed.
// globals area
// ...
bool verbose_mode = true;
SYSTEM_MODE(MANUAL); // only turn on wifi when necessary
// ...
void loop() {
// ...
// turn on wifi
if (verbose_mode) Serial.print("ready to publish.\n turning on wifi... ");
WiFi.on();
if (verbose_mode) Serial.print("wifi on.\n attempting to connect... ");
WiFi.connect();
if (WiFi.ready()) {
if (verbose_mode) Serial.print("wifi ready.\n force disconnecting from particle... ");
// force disconnect from particle
Particle.disconnect();
waitFor(Particle.disconnected, 10000);
if (verbose_mode) Serial.print("disconnected.\n reconnecting to particle... ");
// re-connect to particle
Particle.connect();
if (waitFor(Particle.connected, 10000) && Particle.connected()) { // make sure we're connected to particle
Particle.process();
if (verbose_mode) {
Serial.print("connected to particle.\n SSID: ");
Serial.print(WiFi.SSID());
Serial.print("\n IP: ");
Serial.println(WiFi.localIP());
}
// take system stats
publish_timestamp = Time.now();
int wifi_strength = WiFi.RSSI();
sprintf(msg, "debugVitals,%i,%i,%i,%i,%i", publish_timestamp, test_number, wifi_strength);
Particle.publish("DEBUG_VITALS", msg, WITH_ACK);
Particle.process();
delay(2000);
Particle.process();
if (verbose_mode) Serial.println(msg);
} else { // never connected to particle
WiFi.off();
if (verbose_mode) Serial.println(" PARTICLE NOT CONNECTED");
}
WiFi.off();
Serial.println(" wifi off.");
} else { // never connected to wifi
WiFi.off();
if (verbose_mode) Serial.println(" WIFI NOT CONNECTED");
}
// go to sleep
System.sleep(SLEEP_MODE_DEEP, 60);
}
Am I going about this in the wrong way? Is there something silly I’ve forgotten? Thanks in advance for any and all help!