Switch PC On Via RTC (with Linux)

In my company at the end of the day I’m putting my PC into S3 sleep state and wake it up next morning. In the past I had been using the /proc/acpci/alarm ACPI device to setup the alarm clock, so that the PC would already be ready when I return to my desk. Sometime in the past with I don’t know which new kernel version I lost the ability to use the alarm function (or due to some reconfiguration in the kernels ACPI parameters). So I manually switched the PC on (what else?).

Apparently I didn’t look hard enough for a solution, then I would have found the below earlier. I found the solution in the KnoppMyth vincinity.

Check if you have a directory rtc0 in the /sys hierachy.

ls /sys/class/rtc/rtc0/

If you don’t have this directory you might need to check, if the appropriate rtc-module is loaded. For me it is rtc-cmos. See to it, that it is correctly loaded during boot.

Apart from other files, there should be a file named wakealarm. Write 0 to file to disable the wakeup function, otherwise write the seconds since the epoch (seconds since Jan 1st 1970) to the file.

disabling
# echo 0 > /sys/class/rtc/rtc0/wakealarm 
wakeup after 5 minutes
# echo $(date '+%s' -d '+ 5 minutes') > \ 
    /sys/class/rtc/rtc0/wakealarm
or wakup tomorrow at 7:15
# echo $(date '+%s' -d 'tomorrow 7:15') > \ 
    /sys/class/rtc/rtc0/wakealarm
# cat /sys/class/rtc/rtc0/wakealarm

You might want to check the output of the file /proc/driver/rtc:

# cat /proc/driver/rtc
rtc_time        : 15:09:52
rtc_date        : 2009-01-07
alrm_time       : 07:15:00
alrm_date       : 2009-01-08
alarm_IRQ       : yes
alrm_pending    : no
24hr            : yes
periodic_IRQ    : no
update_IRQ      : no
HPET_emulated   : yes
DST_enable      : no
periodic_freq   : 1024
batt_status     : okay

What I noticed however, when I write multiple times to wakealarm I’m getting an error message.

# echo 0 > /sys/class/rtc/rtc0/wakealarm
# echo $(date -u '+%s' -d 'tomorrow 7:15') > /sys/class/rtc/rtc/wakealarm
# echo $(date -u '+%s' -d 'tomorrow 7:15') > /sys/class/rtc/rtc/wakealarm
echo: write error: Device or resource busy

This error is cleared by another echo 0 > ....


Tags:

 
 
 

Leave a Reply