Take the 2-minute tour ×
Raspberry Pi Stack Exchange is a question and answer site for users and developers of hardware and software for Raspberry Pi. It's 100% free, no registration required.

I want raspi to (1) bootup, (2) do a task, (3) go into suspend mode for x amount of time, (4) wake up and do it all over again.

1 and 2 are easy: sudo crontab -e, which has just one line: @reboot /home/pi/boottasks.sh

boottasks.sh contains (and is made executable with chmod a+x boottasks.sh):

#!/bin/bash

echo 'pi woke at ' ($date) >> boottasks.log
some_other_task

So far, I found out I can force reboot with sudo shutdown -r, and I can force hibernate with sudo shutdown -hP now

The problem is that raspi doesn't seem to obey what's in the crontab. That is, this line in the crontab: */30 * * * * sudo shutdown -r will not work if the last task list in boottasks.sh is sudo shutdown -hP now. In fact, that last bit is a good recipe for an endless loop that has pi rebooting all the time.

I can't believe what I want isnt't possible. I've seen the (somewhat straying discussion) here. Didn't answer my question.

And this, using rtcwake -m mem -s 180, runs into

rtcwake: open failed: /sys/class/rtc/rtc0/device/power/wakeup: No such file or directory
rtcwake: /dev/rtc0 not enabled for wakeup events

I'm new to Linux. But seasoned with computers. Any hints in the right direction would be much appreciated.

share|improve this question
    
I do not think the Pi supports waking up from sleep or going into hibernation? Any way isn't rtcwake (real time clock wake) Do you know how many real-time clocks the Pi has? And why reboot it- Rebooting takes more power than idling. Recurring tasks can be handled using some simple python script or something running on a separate thread. –  ppumkin Oct 23 '12 at 22:15
1  
@ppumkin You're right, raspi doesn't have an rtc, right? Thanks, I hadn't made that connection yet. It does support hibernation, though. Watch what it does when you shutdown -hP now; power consumption drops significantly too. See also what AlesEames wrote on page 3 of this here thread link –  RolfBly Oct 24 '12 at 18:47
add comment

2 Answers 2

In this question you can find some interesting aspects of writing your own crontab.

My personal suggestion is to write your script as you'll do it normally, test & debug it, and then place the script inside the crontab with a line similar to:

*/30  *  *   *   *    /home/youruser/yourscriptdir/yourscriptname.sh >> /tmp/cron-temp.log 2>&1

However, you have to keep in mind that the script will be executed by the user cron with no knowledge of your PATH variable and, tipically, with different environment variables. You can watch them yourself with a line such as:

*/30  *  *   *   *    bash -c "export" >> /tmp/cron-temp.log 2>&1

Also don't forget to place the desired shebang line (such as #!/bin/bash or #!/bin/sh) at the head of your script, otherwise cron will call your script using sh.

If you want to have the sequence at boot, you could also choose to create an init script as mentioned in the post you linked.

Again, the cleanest approach is to have your own script inside your home folder and have an init script such as the following that calls your script:

#!/bin/bash

PATH="$PATH:/home/youruser/yourscriptdir"

case "$1" in
  start|stop)
            echo
            echo "My first startup script!"
            echo

            /home/youruser/yourscriptdir/yourscriptname.sh
    ;;
  restart|force-reload) exit 0 ;;
  *) echo "Usage: $0 {start|stop|restart|force-reload}" >&2; exit 1 ;;
esac

You have to place the init script inside /etc/init.d and then you can add it to the boot sequence with:

update-rc.d name-of-the-init-script-in-etc-init.d defaults

I really don't know if the Pi supports the power management features that you're trying to use, but nevertheless, these two methods are worth knowing.

share|improve this answer
    
Thanks for all the leads. –  RolfBly Oct 24 '12 at 19:02
add comment

Conclusion: Pi can't hibernate for a given amount of time and then wake up by itself. A cheap alternative is an external time-switch. The scenario would then be:
1. Pi wakes up on the timer
2. performs tasks in crontab scheduled for boot time, including housekeeping and garbage collecting afterwards
3. shuts itself off (ie shutdown -h now)
4. timer removes power. You'd have to allow for sufficient time for 1 to 3 to complete, of course.

I find it rather disappointing that a device with so much horsepower can't be tamed, or at least not easily, to perform such a simple task.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.