Author Topic: Using ListenMode as Wakeup timer  (Read 89552 times)

kobuki

  • Sr. Member
  • ****
  • Posts: 289
Re: Using ListenMode as Wakeup timer
« Reply #60 on: February 25, 2017, 04:58:05 PM »
Sorry guys, I haven't been following this thread all along. Could you outline the PLL lock method? What steps are involved? Maybe a short, working code fragment that says it all instead of explaining things again... Thanks.

Neko

  • NewMember
  • *
  • Posts: 37
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #61 on: March 25, 2017, 09:17:29 PM »
This looks like a very useful technique for the project I am working on. Does anyone have experience with it? Is there more recent code than joelucid's original listen.cpp code?

Thanks.

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #62 on: March 26, 2017, 12:13:19 PM »
I'm using the basic notion.  It works reliably.  I think short of adding an ultra low power RTC, it's probably the best (= least current consuming) way to sleep your Moteino and still be able to wake it at a particular future time.  All the details of how to do it are in this thread.  Start by getting regular Listen Mode to work, and then you're 80% of the way there.
« Last Edit: March 26, 2017, 12:27:25 PM by WhiteHare »

Neko

  • NewMember
  • *
  • Posts: 37
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #63 on: April 04, 2017, 10:15:31 PM »
I'm using the basic notion.  It works reliably.  I think short of adding an ultra low power RTC, it's probably the best (= least current consuming) way to sleep your Moteino and still be able to wake it at a particular future time.  All the details of how to do it are in this thread.  Start by getting regular Listen Mode to work, and then you're 80% of the way there.

It's a little beyond my level, WhiteHare. I'm working hard to understand. (I've read the thread several times, and am studying the cpp file.) But I'm new to Moteino and at an intermediate level with Arduino. I do have Felix's Listener examples working, but am not sure how to go from there. Here's a really basic question, for example. In the cpp file, RFM69Listener.delay (and others) has as its first argument "RFM69& radio". What value do you set that to when you call the function? What would the call look like in my ino file?

Would there be a basic example of how to get a fixed delay using this method?
« Last Edit: April 04, 2017, 11:29:58 PM by Neko »

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #64 on: April 05, 2017, 07:00:41 AM »
You should probably ask the author.  I don't have any demo code.

Neko

  • NewMember
  • *
  • Posts: 37
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #65 on: April 07, 2017, 08:30:56 PM »
I have it working now. Thanks.

From what I'm seeing (and some hints in this thread), it seems like the clock is not super accurate. About 1% variability among the moteinos I have. I need more like more like 0.25% accuracy in my application.

I do have a very accurate once-per-minute wakeup burst coming from the master node, however. Is there a way to use that to calibrate the clock (also hinted at earlier in the thread)? I thought about running a fixed delay (e.g. 58 sec), and then waking up and trying to count the exact time until the next wakeup burst using millis() (which is somewhat more accurate). But I wonder if there is a better way?

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #66 on: April 07, 2017, 09:18:37 PM »
JoeLucid did quite a bit of work on the topic of calibration and clock syncing.  He posted some general descriptions of his approach, as well as the results he was able to get.  I don't recall that he ever posted any demo code, but you might start with that.

Neko

  • NewMember
  • *
  • Posts: 37
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #67 on: April 07, 2017, 10:28:09 PM »
Right. I found the thread. Lots of great ideas there, and I even understand about 20% of them!

My goal is to have 250 nodes send message to the gateway once per minute, each in its own 1/4-second time slot. I think the easiest way to do this is a variation on one of your posts in the thread:

1) The gateway starts a 1-minute cycle by a wakeup burst to all nodes.

2) Each node immediately sleeps for 250 ms times its ID#.

3) Each node then wakes up and sends its data to the gateway.

4) The gateway responds with the actual time since the burst.

5) The node can then adjust itself accordingly on the next round. After a round or two, the nodes should nicely avoid talking at the same time.

At least this seems like a good idea. I'm sure the problems will surface when I actually try to implement it...



WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #68 on: April 08, 2017, 02:53:47 AM »
Sounds like an interesting approach.  Please do post on how it pans out for you!

Neko

  • NewMember
  • *
  • Posts: 37
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #69 on: April 18, 2017, 11:38:50 PM »
Works quite nicely. All the elements are in place.

Neko

  • NewMember
  • *
  • Posts: 37
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #70 on: May 22, 2017, 11:55:16 PM »
I'm using joelucid's radio.delay() code to time the responses of a number of nodes relative to a wakeup burst. 99.9% of the time it all works nicely, with the nodes hitting their mark within a few ms. But some of my moteino's hang after several hundred trials, requiring a power cycle to recover. It happens only on 4 out of seven nodes. The other 3 have gone for 10's of thousands of trials without a problem.

The nodes get stuck in the third instance of
        LowPower.powerDown( SLEEP_FOREVER, ADC_OFF, BOD_OFF );

I wonder if the 1st two of the three interrupts happen too fast, so that the MCU is not able to enter the second SLEEP mode before the second interrupt occurs. But that's just a guess.

Is there a way to avoid this? Should I be using the PLLLock method instead? Is it something related to the "stuck in listen mode" bug?
« Last Edit: May 23, 2017, 12:34:42 AM by Neko »

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #71 on: May 23, 2017, 07:23:40 AM »
Do the nodes which get stuck have additional flash memory chips on them, and the ones that don't get stuck don't have additional flash memory?  In the past I reported an apparent  bug which relates to that.  If you wire your DTR pin to ground on the nodes which have the problem, does the problem go away?  Which version of Arduino IDE are you compiling with?  If you compile using Arduino IDE 1.0.6, does the problem go away?  There is another fix which you might also try if those don't work, but it's more involved.  So, please report back which, if any, of the above solved your problem.

I use ListenMode as a wakeup timer all the time, and I've never had a problem with it failing.  Based on your description, it's almost impossible that it is the root of your particular problem.
« Last Edit: May 23, 2017, 07:43:42 AM by WhiteHare »

Neko

  • NewMember
  • *
  • Posts: 37
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #72 on: May 23, 2017, 09:43:38 AM »
Do the nodes which get stuck have additional flash memory chips on them, and the ones that don't get stuck don't have additional flash memory?  In the past I reported an apparent  bug which relates to that.

Some have SPI and some don't, so it doesn't seem to be related to that.

Quote
If you wire your DTR pin to ground on the nodes which have the problem, does the problem go away? 

Doesn't seem to help. I've had one failure already in the time I took to write this. You mean DTR on the 6-pin programming interface, right?

Quote
Which version of Arduino IDE are you compiling with? If you compile using Arduino IDE 1.0.6, does the problem go away?

I am using 1.6.4 on OSX (MacBook Pro). I can move to Windows and/or to 1.0.6.

Quote
There is another fix which you might also try if those don't work, but it's more involved.  So, please report back which, if any, of the above solved your problem. I use ListenMode as a wakeup timer all the time, and I've never had a problem with it failing.  Based on your description, it's almost impossible that it is the root of your particular problem.

That's encouraging. The failure always occurs just after the last SLEEP command. I use two radio.delay's in a row (one shorter than 262 ms, one longer). The failure is always on the first one.

Can you post or send the code you use for it? As I said, I am using joelucid's code from earlier in this thread. The only modification is that the last SLEEP of the three, and the ListenModeEnd, are moved to the main body of the code instead of staying in the cpp file.

Code: [Select]
radio.delayms(smallTime);
LowPower.powerDown( SLEEP_FOREVER, ADC_OFF, BOD_OFF );
radio.listenModeEnd();

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #73 on: May 23, 2017, 10:03:55 AM »
Try 1.0.6 on Windows next.  Compared to anything else, it's the least effort.

Neko

  • NewMember
  • *
  • Posts: 37
  • Country: us
Re: Using ListenMode as Wakeup timer
« Reply #74 on: May 23, 2017, 12:35:09 PM »
Version 1.0.6 on Windows still has trouble.

One interesting thing I notice is that I have 2 delays in succession. The first is many seconds long, but only has 262-ms resolution. The second delay is only a few ms to get to the exact desired time. No matter what order I do these in, the error occurs just after the short delay.