You are not logged in.

#1 2009-03-23 20:02:53

hatten
Arch Linux f@h Team Member
From: Sweden, Borlange
Registered: 2009-02-23
Posts: 736

Wake at a set time from suspend to RAM

Google didn't help me, arch wiki didn't help me, ubuntu forums didn't help me when i asked there some time ago. How do i make it possible to suspend to RAM in the evening, and have it automatically waked the following morning?
I want to be awakened by the computer, playing music, in ubuntu i used to hibernate and have BIOS boot it, but now i run with 8x bigger RAM and 4x smaller swap, so there is no choice to hibernate anymore. I don't want the computer running the whole night either.
One alternative is to have arch launch a script at bootup, but i don't really want that either as i might be powering it on some other time of the day than in the morning.

Last edited by hatten (2009-03-23 20:03:33)

Offline

#2 2009-03-23 20:34:39

FALK
Member
From: Denmark
Registered: 2008-03-24
Posts: 95

Re: Wake at a set time from suspend to RAM

Try wake-on-lan, either from some other hardware you own (server, wrt-router) or http://wakeonlan.me/ , but I don't know if that site works.

Offline

#3 2009-03-23 22:18:45

damjan
Member
Registered: 2006-05-30
Posts: 452

Re: Wake at a set time from suspend to RAM

If your BIOS supports that, you can set a wake alarm in the RTC (the real time clock chip on all motherboards).

On my laptop, with the rtc_cmos driver loaded, I have a /sys/class/rtc/rtc0/wakealarm pseudo-file. AFAIU you write a UTC or localtime timestamp to the file and it should trigger an IRQ at that time, which should wake your PC.

There's a lot of maybes and shoulds there so you can try and report what you've done.

Offline

#4 2009-03-24 15:49:37

hatten
Arch Linux f@h Team Member
From: Sweden, Borlange
Registered: 2009-02-23
Posts: 736

Re: Wake at a set time from suspend to RAM

@FALK, no server and no router that can do that, and that site doesn't look like an especially good solution, if I'm not gonna buy it i have to go there once a day and fill in that form =P

@damjan, i didn't understand very much of that, if there's no easy howto on that, or you don't wanna guide me trough the whole process i have to find another solution.

It isn't that hard to write a script that's launched at startup, checks how much the clock is and if it is between 6.30 and 7 launches a program that can play an audiofile or two. Right?
Too bad i only know HTML ... yet =P

Offline

#5 2009-03-25 11:22:11

RaisedFist
Member
From: Romania
Registered: 2007-01-30
Posts: 556
Website

Re: Wake at a set time from suspend to RAM

hatten wrote:

@FALK, no server and no router that can do that, and that site doesn't look like an especially good solution, if I'm not gonna buy it i have to go there once a day and fill in that form =P

I think you're wrong. I can program my Linksys router with DD-WRT firmware to wake-on-lan my desktop at any time. I can do it manually or set it at any wanted time.

Offline

#6 2009-03-25 14:01:47

hatten
Arch Linux f@h Team Member
From: Sweden, Borlange
Registered: 2009-02-23
Posts: 736

Re: Wake at a set time from suspend to RAM

oh, i will rtfm for the router (netgear) and the modem/router and/or stfw. Didn't know that was possible. It's just that my netgear wasn't accesible last time i tried to log into it from my linux install...=(

Offline

#7 2009-03-25 14:20:25

Xappe
Member
Registered: 2008-05-17
Posts: 105

Re: Wake at a set time from suspend to RAM

Hmm, if you can set your BIOS to boot arch at a specific time, I guess that it should be possible to use at/atd for your alarm. I'm not totally sure, but if you add atd to your daemons I guess it should run any events qeued by at, at least if you boot the computer before the event is set to go off...


vanum est vobis ante lucem surgere

Offline

#8 2009-03-25 14:30:08

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Wake at a set time from suspend to RAM

hatten wrote:

i run with 8x bigger RAM and 4x smaller swap, so there is no choice to hibernate anymore.

You could use a swapfiile.

Offline

#9 2009-03-26 21:18:00

hatten
Arch Linux f@h Team Member
From: Sweden, Borlange
Registered: 2009-02-23
Posts: 736

Re: Wake at a set time from suspend to RAM

tomk wrote:
hatten wrote:

i run with 8x bigger RAM and 4x smaller swap, so there is no choice to hibernate anymore.

You could use a swapfiile.

but that still makes me lose the same amount of diskspace! xD
btw, i killed all applications i didn't use, and free -m told me i used less than 512MB RAM, but when i tried hbernating with that it failed, do you actually HAVE to have as big swap as RAM?

Wow, this was a lot more complicated than i thought!

Hmm...if my memory ain't wrong i could in ubuntu write "somecommand 09:00" to make it sleep/suspend/whatever until that time. I don't really care what the comp does, as long as the fan stops (my mom cannot sleep with it":lol:. But i guess that most of the comp have to be stopped to make it possible not to make it overheat =P

haven't rtfm'd the router yet

I'll check up at/atd.

Last edited by hatten (2009-03-26 21:18:55)

Offline

#10 2009-03-26 23:40:51

arkay
Member
Registered: 2008-05-23
Posts: 79

Re: Wake at a set time from suspend to RAM

Most motherboards support wake by RTC alarm these days.

You need to go into your bios and under the power management menu select wake by PME event (is usually what it's called).

You can then, from your command line run:

sudo sh -c "echo 0 > /sys/class/rtc/rtc0/wakealarm"
sudo sh -c "echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm"
cat /sys/class/rtc/rtc0/wakealarm

Check that it worked with:

cat /proc/driver/rtc

The alarm time should be set for 5 minutes into the future.

Shutdown the machine with:

shutdown -h now

All things going well it should wake up in 5 minutes from fully off.

If that works you can then put some conditions around what you want it to do and when it needs to go to sleep.

It's not all that hard to get it all working.  If you really want to learn how it works then I would recommend the myth wiki as myth users tend to use this functionality heavily. http://www.mythtv.org/wiki/ACPI_Wakeup has all the info you could ever need to get this working.

I'll include the script I use for my myth backend.  It take a UTC time in time_t format (which is the number of seconds since the Epoch).
You could just call this script via a cronjob and have a shutdown -h command at the bottom so the last thing it does at night is programs it to wake up then shuts down.

You would also need an additional cronjob to run at a set time in the morning so when it wakes it starts playing music.

#!/bin/sh
#$1 is the first argument to the script. It is the time in seconds since 1970

#Now set the wakeup timers.
echo 0 > /sys/class/rtc/rtc0/wakealarm      #this clears your alarm.
echo $1 > /sys/class/rtc/rtc0/wakealarm     #this writes the alarm.
date=`date "+%a %b %e %H:%M:%S %Y"`
schedutc=`date -u -d @$2 +%F" "%T`
sched=`date -d @$2 +%F" "%T`
cat /proc/driver/rtc | head -4

Depending on your motherboard and bios you might need to stop writing the time back to bios on shutdown (it can wipe the RTC alarm on some boards).  If that is necessary you can comment out this line in /etc/rc.shutdown:

/sbin/hwclock $HWCLOCK_PARAMS

If you do have to do that you can modify the script above to write the time to bios and then set the RTC alarm if you want to make sure the bios time is always perfect.  I'd also install and configure ntp to keep it all in sync wink

So.. Just to be clear:

1. Test wake via RTC alarm and once working.
2. Create a cronjob to program the RTC timer to wake the machine the following morning at say 6:28 am and shut down for the night.
3. Create a cronjob that runs at 6:30am to play the music you want.

Job done.

Cheers,

Arkay.

Last edited by arkay (2009-03-26 23:43:16)

Offline

#11 2009-03-27 07:15:49

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Wake at a set time from suspend to RAM

hatten wrote:
tomk wrote:
hatten wrote:

i run with 8x bigger RAM and 4x smaller swap, so there is no choice to hibernate anymore.

You could use a swapfiile.

but that still makes me lose the same amount of diskspace!

Yes. I'm just pointing out that you do, in fact, have a choice.

Offline

#12 2009-03-27 15:50:38

hatten
Arch Linux f@h Team Member
From: Sweden, Borlange
Registered: 2009-02-23
Posts: 736

Re: Wake at a set time from suspend to RAM

arkay wrote:

<block of text>

Hmm. That said how to wake the comp from shutdown. That's easy and can in my case be used solely by the BIOS. I understand that that script can be useful if you got different times every time it should be awakened.

@tomk: yeah,i have lots of choices!:D

Seems like the easiest is to write a bash script that'll be launched at startup, that script will then launch a media player that will play some music.
Anybody got a tip on a good CLI music player that can play files with a simple command?
Finding out how to launch a script at startup that checks the time and launches a script cannot be too too hard. Off to stfw!

Offline

#13 2009-03-28 12:29:44

archlinuxsagi
Member
Registered: 2008-09-12
Posts: 259

Re: Wake at a set time from suspend to RAM

arkay... great.. I been wanting to do this.. great tip...

Offline

Board footer

Powered by FluxBB