Author Topic: Sleep parameter precision  (Read 2879 times)

darkcurrent

  • Newbie
  • *
  • Posts: 20
Sleep parameter precision
« on: August 19, 2015, 09:17:08 AM »
Hi all,

I put my Moteino at sleep during 10min (looping 150 times during 4sec). I noticed a additional delay of about 30sec at each loop. Is something missing in the code??? Does anybody knows what time precision to expect for such a long delay?

Code: [Select]
 for (byte i = 0; i < SLEEP_CYCLES; i++)
  {
    LowPower.powerDown(SLEEP_4S, ADC_OFF, BOD_OFF);
  }

Thanks for your help.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5992
  • Country: us
    • LowPowerLab
Re: Sleep parameter precision
« Reply #1 on: August 19, 2015, 11:31:47 AM »
So if I understand correctly your 150x loop produces a total of:

150 x (4sec + 30sec delay) = 5100 seconds instead of the desired 600 seconds?

darkcurrent

  • Newbie
  • *
  • Posts: 20
Re: Sleep parameter precision
« Reply #2 on: August 19, 2015, 11:41:01 AM »
Euh.. no
Rather it is (150x4s)=600sec but I notice more or less 630 sec between readings...

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5992
  • Country: us
    • LowPowerLab
Re: Sleep parameter precision
« Reply #3 on: August 19, 2015, 11:55:10 AM »
I noticed a additional delay of about 30sec at each loop.

That was a bit confusing, it sounds to me like it adds 30sec to every 4sec of sleep?
Anyway 630sec still is more than I would expect. I will try to look at this soon. In the meantime if someone else does please post updates here, thanks.

darkcurrent

  • Newbie
  • *
  • Posts: 20
Re: Sleep parameter precision
« Reply #4 on: August 19, 2015, 12:10:59 PM »
I also should add that:

1) this additional delay varies between readings, let say between 15 to 30sec
2) timestamps are read in the Node-RED debug window that is running on a Raspberry Pi, each time data are received from the Moteinos.

Would it be possible to send a timestamp from Moteino to Moteino, I mean from node to gateway?

Hope this helps to clarify the problem  :)

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5992
  • Country: us
    • LowPowerLab
Re: Sleep parameter precision
« Reply #5 on: August 19, 2015, 12:24:59 PM »
You can send anything you want. It's gotta be a byte stream into the Send function. So transform your timestamp to bytes and pass it to send.. then decode the other way on the gateway.

darkcurrent

  • Newbie
  • *
  • Posts: 20
Re: Sleep parameter precision
« Reply #6 on: August 19, 2015, 12:31:14 PM »
Well, that's new for me. Where do you get time and date from when there is no RTC ?

joelucid

  • Hero Member
  • *****
  • Posts: 869
Re: Sleep parameter precision
« Reply #7 on: August 19, 2015, 01:33:43 PM »
LowPower.powerDown works with the WDT which has a 10% tolerance. If you need it more precise you need to calibrate the WDT timer in software using the 16mhz crystal. There's a sleep lib that does that - I can't remember the name but Tom uses it.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5992
  • Country: us
    • LowPowerLab
Re: Sleep parameter precision
« Reply #8 on: August 19, 2015, 02:23:52 PM »
Well, that's new for me. Where do you get time and date from when there is no RTC ?

When you asked "Would it be possible to send a timestamp from Moteino to Moteino, I mean from node to gateway?"
...I assumed you already have your timestamp. Moteinos are not RTCs and have no way to make one without a reference. Or you could ask the gateway for one i guess and then try to keep track of time at the node level but you depend on the resonator precision and code is more complex etc.

In my mind it makes no sense to do this unless you want to buffer messages and keep track at the node level when they were generated. Otherwise in the majority of cases you send the message to the gateway which knows what the time is and timestamps that message. This is how its done in my Gateway solution.

TomWS

  • Hero Member
  • *****
  • Posts: 1891
Re: Sleep parameter precision
« Reply #9 on: August 19, 2015, 05:53:54 PM »
There's a sleep lib that does that - I can't remember the name but Tom uses it.
The sleep library #include <Sleep_n0m1.h> has a calibrate function that adjusts the overall sleep delay by the WDT error.  However, even this is an approximation since very long sleep times may drift due to temperature, voltage, solar winds, and other idiosyncrasies of nature.
What I do now is use my gateway to wake up the motes at a precise time using the listener library Joe inspired.  The gateway 'knows' when to wake up as it always gets 'seconds since midnight' value from the server every time the gateway posts a new result.

Tom
« Last Edit: August 19, 2015, 06:03:02 PM by TomWS »

darkcurrent

  • Newbie
  • *
  • Posts: 20
Re: Sleep parameter precision
« Reply #10 on: August 20, 2015, 04:49:49 AM »
Thanks to you all for your answers.

@Felix: Indeed, that's exactly what I'm doing now i.e. let the gateway keep track of time and date.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5992
  • Country: us
    • LowPowerLab
Re: Sleep parameter precision
« Reply #11 on: August 20, 2015, 08:02:48 AM »
@Felix: Indeed, that's exactly what I'm doing now i.e. let the gateway keep track of time and date.

Yeah, if you dont have a specific requirement to keep track at the node, let the gateway do it. That way you also have a single time keeper and not several nodes that might be slightly out of sync.
If you have a need to keep track at the node level, I think it's worth to just add an RTC which is a few dollars and spare you the time and complexity of implementing some code scheme of keeping time. You can then do a one time request to get the starting point from the gateway to initialize the RTC.