Author Topic: LowPower.powerDown and interrupts - best way to save power question  (Read 2815 times)

xavier

  • Jr. Member
  • **
  • Posts: 65
  • Country: us
I have a set of weather sensor (rain and wind) that generate interrupts to gather rain and wind data. Every 15 minutes I send that data to my server (well or so I thought)

I put my moteino to sleep using a loop and LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF) - but by design the interrupts stop the sleep loop and I end up sleeping partially and sending data to the server depending of how many interrupts I had...

I was hoping I could figure out how many loops I missed but then the issue I'm trying to figure out if since I can't find out how much of the 8s I slept I'm pretty much not sleeping at all when it's windy.

Now for my question and with the goal of optimizing battery time:
- is there a better to organize the code flow in order to maybe alway sleep in the loop and have an external timer call my sendDataToServer at a specific interval? I looped around but could not find a way to do this since the sleep function pretty much turns off all timers
- is the only way to do this to use Extended Standby and turn on T2 so I can have a timer be called every 15min, gather the data and send it?

I have a feeling I'm overthinking this and should just go w option #2 but I'd be interested to see if anyone has a better option (without having to had a external HW clock)

thanks!

X

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5938
  • Country: us
    • LowPowerLab
Re: LowPower.powerDown and interrupts - best way to save power question
« Reply #1 on: November 17, 2015, 06:55:48 AM »
In my mind interrupts are something that you need to pay attention to.
Sounds like your problem is that you still need to pay attention to them, except it becomes a problem when too many interrupts happen and you loose track of time using the mega328 internal timers. In that case you need an external reference. If you use a gateway like a Pi then you can easily reference time at the gateway, like I do in my gateway, then I don't need any timers in end nodes.
The only other solution that I can think of is use a dedicated external timer on the end node where you need to keep track of time.

TomWS

  • Hero Member
  • *****
  • Posts: 1888
Re: LowPower.powerDown and interrupts - best way to save power question
« Reply #2 on: November 17, 2015, 07:19:48 AM »
I have a set of weather sensor (rain and wind) that generate interrupts to gather rain and wind data. Every 15 minutes I send that data to my server (well or so I thought)

I put my moteino to sleep using a loop and LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF) - but by design the interrupts stop the sleep loop and I end up sleeping partially and sending data to the server depending of how many interrupts I had...

I was hoping I could figure out how many loops I missed but then the issue I'm trying to figure out if since I can't find out how much of the 8s I slept I'm pretty much not sleeping at all when it's windy.

Now for my question and with the goal of optimizing battery time:
- is there a better to organize the code flow in order to maybe alway sleep in the loop and have an external timer call my sendDataToServer at a specific interval? I looped around but could not find a way to do this since the sleep function pretty much turns off all timers
- is the only way to do this to use Extended Standby and turn on T2 so I can have a timer be called every 15min, gather the data and send it?

I have a feeling I'm overthinking this and should just go w option #2 but I'd be interested to see if anyone has a better option (without having to had a external HW clock)

thanks!

X
I would highly recommend using ListenMode with your gateway sending wakeup messages every sample period (15 minutes in your case) as described in https://lowpowerlab.com/forum/index.php/topic,1136.0.html.  Then the other interrupts can be handled without worrying about timing.  The device is woken up by something (interrupt or wakeup poll), easy to determine which, service the interrupt and then go back to sleep forever (until the next event).  In my case the gateway is time synchronized to an NTP server, but in your case probably a free running timer is good enough.

Tom

xavier

  • Jr. Member
  • **
  • Posts: 65
  • Country: us
Re: LowPower.powerDown and interrupts - best way to save power question
« Reply #3 on: November 17, 2015, 05:57:58 PM »
Thank you Tom et Felix to take the time to reply, much appreciated as always!

I missed the fact that the gateway could be the one to wake up the moteino and ask for the data - I think the only thing I would get back though is aggregate data for the period (it rained x millimeters in the last 15min) and wont be able to get water per minute. I suppose it's fine and I can sample for 1 minute when the moteino is requested data so at least I'll know if it's currently raining.

I'll have to change some code around so for now I'll leave as it is and use the extended standby function which enables me to keep track of time on the moteino and if the rocketScream web site is correct consumes 416.0 ľA - I'm connecting a small solar panel to the Power Shield from Felix as well so hopefully this is enough to keep my lips going for a while.

Felix: I was thinking getting a water mote, do you ask for data every minute from your PI? how long does your battery last? (and what battery are you using?) If we could find a way to keep track of time on the moteino during deep sleep we could make an histogram and send that every 15m - anyhow maybe that's overkill

I'll will check the link you sent Tom since I'd like to be able to get instant data reading from my iPhone app so I'll definitely be using the info from JoeLucid (had the thread bookmarked but haven't had a chance to get to implementation yet)

Thanks again for the help!

X

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 5938
  • Country: us
    • LowPowerLab
Re: LowPower.powerDown and interrupts - best way to save power question
« Reply #4 on: November 17, 2015, 09:08:36 PM »
The "water mote" is more of a sketch rather than a complete solution. I use a photo reflective sensor that reads a small triangular dial on my water meter. Every rotation is 1/15 of a gallon. So that sensor has to be ON all the time because that triangle could spin very very fast. So the Moteino has to be permanently powered from a 5v wall wart. Then it sends data every 5s when water flows actively and only rarely in between when nothing really happens. Take a look at the code.