Sleep doesn't work

Hi, everyone

I use the following code to sleep. It usually works, but sometimes it doesn’t work.

  Particle.publish("sleep.");
  System.sleep(dr_echo, RISING, wakeInterval * 60, SLEEP_NETWORK_STANDBY);
  Particle.publish("wake.");

I have several questions:
1, since I use sleep and wake, why does the device come online again and again(see picture)?
2, from the screenshot, no wake events after sleep but “device came online” info.
3, no any event during 2 hours, from 10:55-12:55.

Any suggestion will be appreciated.

Thanks.

@anderson916, I believe you are trying to use this form of sleeping:

System.sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode, SLEEP_NETWORK_STANDBY, long seconds);

However, your parameter for time in the wrong position. Which version of system firmware are you running? I believe only version 0.7.0-rc.x will correctly complete the Particle.publish() before going to sleep.

@anderson916, I guess you are using an Electron, yes?
If so 0.6.2 should already take care of the correct delivery of events before going to sleep - only WiFi devices need 0.7.0-rc.3

And the docs do in deed suggest

System.sleep(wakeUpPin, edgeTriggerMode, seconds, SLEEP_NETWORK_STANDBY);

But what is the definition of dr_echo and wakeInterval and what have you got connected to dr_echo?

And you screenshot doesn’t show the time for most your events.


I found the contradictory definition @peekay123 mentioned before in the docs too - try that instead

// SYNTAX
System.sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode, long seconds);
System.sleep(uint16_t wakeUpPin, uint16_t edgeTriggerMode, SLEEP_NETWORK_STANDBY, long seconds);

If this is the actual syntax, this would explain your symptoms.

I used the last one.

I am very surprised that you told me I used the wrong parameter order, because most of the time it works. I am using firmware 0.6.2.

Anyway, I will try the parameter order you suggested.

Thanks.

Yes, I am using Electron.

And your wiring, and variable definition?


The docs are confusing about that

So both should work.

Yes, both work.

Now, the problems are:
1, since I use sleep and wake, why does the device come online again and again(see picture)? Did the device get disconnected due to the weak signal? But if the signal is weak, why did it get connected again and publish sleep event?

2, from the screenshot, no wake events after sleep but “device came online” info. When the device comes online, it should publish wake event immediately.

My project has been delayed for a long time by these issues. Please help me. Thanks.

And for the third time: "How does your wiring on the wake pin look?"
Unexpected wake will not be caused by a weak radio signal but more likely by a noisy wake line.

You also ignored this question so far

Also "device came online" only tells you that the device came online after it was offline, but this does not necessarily mean that the offline state was due to the device sleeping.
Your code may have caused the connection loss (e.g. panic, hard_fault will most likely come from your code and does inevitably cause a connection loss).

And as also mentioned before, the screenshot does not show the time for most events so it's hard to judge how frequent the issue happened.

That we can't help better comes in parts also from not providing essential info