I guess because you are using AUTOMATIC mode which only executes your code after the device regained cloud connection, which may take different amounts of time.
You can use SYSTEM_THREAD(ENABLED) to decouple your code from WiFi and cloud reconnection delays, but you need to check for your ubidots code whether you are WiFi.ready() or not.
BTW: For your code you could even use SYSTEM_MODE(SEMI_AUTOMATIC) and WiFi.connect() and not even connect to the Particle cloud to save time and energy.
Do you mean you are using an Electron?
But yes, cell connection can take even longer, but what I said for WiFi would work the same for Cellular.
Additionally, if you are using the Particle SIM and intend to wake every 23 minutes or less, you may want to consider using
System.sleep(WKP, RISING, time, SLEEP_NETWORK_STANDBY);
instead of deep sleep. This wouldn’t use a lot more power but saves an aweful lot of data (6K per wake). (unless you are already usin system v0.6.0-rc.1)
ah that’s a good tip. my wakeup is an hour for test. the way things are going i think i am going to have to rely in checkingthe pin instead of the time.now() difference
so… does this make sense?
void loop {
now=Time.now();
WiFi.on();
WiFi.connect();
waitUntil(WiFi.ready);
waitUntil(Particle.connected);
SendStuff();
.
.
i get the breathing green led… hmm. could not find any guide for when i have to manually do the connections
void loop {
now=Time.now();
// here you'd calculate difference between now and your expected wake time
// and guess if it was a button or time wake
if (!WiFi.ready())
{
//WiFi.on(); // should not be required unless you called WiFi.off() or use MANUAL mode
WiFi.connect();
waitUntil(WiFi.ready); // you could also use waitFor() if you want a timeout in case of WiFi problems (e.g. router down)
//waitUntil(Particle.connected); // will never continue since you don't ever call Particle.connect()
}
SendStuff();
...
System.sleep(WKP, RISING, time, SLEEP_NETWORK_STANDBY);
}
Breathing green is OK for WiFi.ready() and ubidots, if you need the Particle cloud, you need to call Particle.connect() and waitUntil(Particle.connected) (instead of WiFi.connect() and WiFi.ready())
Cloud connection implicitly activates WiFi connection if not present.
Going to bump this thread just in case something new has come up.
I need to measure a regular interval in milliseconds (~1400ms) and if a pulse is missed then the electron should send a publish. But if time.now only gives me seconds then trying to sleep would be useless? I can no longer measure the pulse interval correctly… Any suggestions?
If you need millisecond resolution, you could use a millis() timer or a software timer, but it would be helpful if you could give us more detail about what you’re trying to do. What have you tried so far, and what are the problems with your current approach?
Thanks for the fast response Rick, but as mentioned in the first post millis() and software timers dont carryover during sleep. At least as far as i know, (I don’t have any electrons to verify right now).
I have a regular interval pulse coming in on the WKP pin roughly every 1400ms but this can vary up to 500ms.
Right now I keep a running average of time between pulses and wait for an out of range event (+1/2 duration average) before triggering an alarm. So everything works as it should right now but I want to reduce power with sleep.
Ok, I think I get what you’re trying to do. Does the Electron need to wake up every 1400 milliseconds, or only when you exceed your missing pulse time? If the latter, I think you might need to use an external watchdog timer (with a timeout period of ~2100 ms), that the pulse would tickle every 1400 milliseconds. If a pulse doesn’t come in within that timeout period, the watchdog would wake your Electron. I assume you want to use deep sleep. Is that the case?
If i am using a photon microcontroller and i am using the stop mode described here. I have been putting my photon in stop mode for 1 second and found that it does stop and starts again after what appears to be 1 second without bridging the 3V3 to Vbat. Although it appears to be working, is it necessary to bridge 3v3 to Vbat so that i dont encounter any timing errors in the future?