Gentoo Archives: gentoo-user

From: waltdnes@××××××××.org
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] wakeup from suspend
Date: Sun, 10 Jan 2016 21:14:41
Message-Id: 20160110211400.GA14534@waltdnes.org
In Reply to: [gentoo-user] wakeup from suspend by Meino.Cramer@gmx.de
1 On Sun, Jan 10, 2016 at 02:55:57PM +0100, Meino.Cramer@×××.de wrote
2 > Hi,
3 >
4 > currently I am experimenting with a new embedded system
5 > (OrangePI PC). I want to suspend the system to RAM.
6 > After a period of time the system should wakeup.
7 >
8 > The RTC on the board seems to support alarms.
9 >
10 > Is there a tool to set the alarm time of an RTC
11 > from the commandline like hwclock set the RTC
12 > time itsself?
13 >
14 > I couldn't find one (or successfully overlooked it...)
15 >
16 > Thank you very much in advance for any help!
17 > Best regards,
18 > Meino
19
20 I'm not aware of any utilities. Is it linux, and how good are you at
21 shell scripts? Two virtual files you'll need to know about are...
22
23 /sys/class/rtc/rtc0/since_epoch
24 /sys/class/rtc/rtc0/wakealarm
25
26 Note that writing to /sys requires root privileges. Both files are in
27 seconds since 1970-01-01 00:00:00 UTC. This is the same output that
28 "date +%s" produces. To test it, run the command...
29
30 date +%s ; cat /sys/class/rtc/rtc0/since_epoch
31
32 Let's say that you want it wake up in 3 minutes (i.e. 180 seconds from
33 now). You'll have to use either "eval" or backticks. The command
34 would be...
35
36 #!/bin/bash
37 echo $(( 180 + `cat /sys/class/rtc/rtc0/since_epoch` )) > /sys/class/rtc/rtc0/wakealarm
38
39 ...and powerdown. It should wake up 3 minutes after you issued the
40 command.
41
42 How about specifying a future time, you ask? First, we need to know
43 the input format. The "--date" command uses the format
44 "MM/DD/YYYY HH:mm:ss" (Month/Day/Year Hour:Minute:Second)
45 the brackets indicate optional items. To get the seconds since epoch at...
46
47 year 2016
48 month 01
49 day 20
50 hour 23
51 minute 00
52 second 00
53
54 the command is...
55
56 date +%s --date="01/20/2016 23:00:00"
57
58 ...which outputs 1453348800
59
60 To set a wakeup alarm for that time...
61
62 date +%s --date="01/20/2016 23:00:00" > /sys/class/rtc/rtc0/wakealarm
63
64 You'll probably want to write a script to accept input from a user or
65 another program. Beware of UTC offsets and Daylight Saving Time.
66
67 --
68 Walter Dnes <waltdnes@××××××××.org>
69 I don't run "desktop environments"; I run useful applications

Replies

Subject Author
Re: [gentoo-user] wakeup from suspend Meino.Cramer@×××.de