You are not logged in.

#1 2011-11-12 20:05:04

fogobogo
Member
Registered: 2008-08-24
Posts: 83

[wakeup] testers wanted.

Some while ago I stumbled onto this article http://lwn.net/Articles/429925/ which tells that theres a clock that can wake your system from suspend. However I found no tool that would actually make use of it, thus I wrote one. It's pretty rudimentary but as they say, "release early, release buggy".

So what does it do? It just sets up a timer that will wake your system from suspend (not hibernate) after the time set ran out. The syntax is a lot like 'sleep'. Here is an example:

$ ./wakeup 4h30m10s

That (should) wake up your box from suspend in 4 hours 30 minutes 10 seconds. Pretty obvious I guess.

IMPORTANT: currently it calls pm-suspend directly. So if you run it it will suspend your box immediately.
You need to run it as root. That wasn't my idea. CLOCK_REALTIME_ALARM requires it.

The code can be found here:
https://github.com/fogobogo/wakeup

For compiling you will need a few things.
1. a working pm-suspend
2. linux-api-headers from the repos
3. a kernel beyond 2.6.38 (that feature was merged then)

So if you misuse your box as an alarm clock and want to safe a bit energy for the sake of our planet or for being a cheapass give it a whirl.

Known issues:

- You cant query / nor delete the timer at the moment. Once set it will happen (*if* you are suspended). However I *think* you can overwrite a timer.
- The arg parsing isn't very robust
- Probably a lot of other things. If anyone is good with POSIX timers... I could need a 101 course.

Offline

#2 2011-11-12 20:29:40

SS4
Member
From: !Rochford, Essex
Registered: 2010-12-05
Posts: 699

Re: [wakeup] testers wanted.

I'll give it a go - see you in 3 minutes!

Success

Last edited by SS4 (2011-11-12 20:33:41)


Rauchen verboten

Offline

#3 2011-11-12 20:31:16

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [wakeup] testers wanted.

Is it related to what hamelg posted? https://bbs.archlinux.org/viewtopic.php … 2#p1015782

Offline

#4 2011-11-12 20:43:09

Shark
Member
From: /dev/zero
Registered: 2011-02-28
Posts: 684

Re: [wakeup] testers wanted.

There is a command to wake your computer ----  rtcwake.


If you have built castles in the air, your work need not be lost; that is where they should be. Now put foundations under them.
Henry David Thoreau

Registered Linux User: #559057

Offline

#5 2011-11-12 20:43:57

fogobogo
Member
Registered: 2008-08-24
Posts: 83

Re: [wakeup] testers wanted.

karol wrote:

Is it related to what hamelg posted? https://bbs.archlinux.org/viewtopic.php … 2#p1015782

Hard to say. If I cat the file I get no output so I cant find out if it sets anything there. Maybe? Probably?

Offline

#6 2011-11-12 20:47:32

fogobogo
Member
Registered: 2008-08-24
Posts: 83

Re: [wakeup] testers wanted.

Shark wrote:

There is a command to wake your computer ----  rtcwake.

Yes. But it doesn't use this interface (or at least didn't). Afaik it is deemed pretty hackish.

Offline

#7 2011-11-12 22:11:08

whitethorn
Member
Registered: 2010-05-02
Posts: 153

Re: [wakeup] testers wanted.

Last christmas I wrote a script in bash that kinda works the same.

#!/bin/bash
####Script to WakeUP pc from Sleep or Hibernate and Play music ####
##Create by nongag ##
### Needed packages
# - working mpd && mpc, with a playlist -OR- Audio player from which playback can be started from a command, just substitute mpc play (line 89 & 96) with your command
# - rtcwake (comes with basei package in normal Arch installation)
# - Working pm-suspend, pm-hibernate
# - passwordless sudo access to pm-suspend & pm-hibernate.  Check visudo for how to set that up.
# - screen
####  Setting needed Variables. ####
num=0
min=0
### Functions ####
## Check if input is a number ##
function numbertest(){
if [ $1 -eq $1 2> /dev/null ]; then
 num=1
else
 num=0
fi
}
## Get Number ##
function getnumber(){
read -p "Please insert amount of $1 " b
numbertest $b
while [ "$num" -lt 1 ]; do
 numbertest $b
 if [ $num -eq 1 ]; then
  echo "Number of $1 = $b"
 else
  read -p "-$b- is not a number please insert a number " b
 fi
done
}
## Calculate amount of seconds ##
#hours*60*60 + minutes*60 = total amount of seconds
function calculate(){
 let b=$1*3600+$2*60
}
## Countdown ##
#accepts one argument which is a number and countdown from that number
function countdown(){
 c=$1
 while [ "$c" -gt 0 ]; do
  echo -ne "$c..."
  sleep 1
  let c=$c-1
 done
echo
}
## Last Yes / No Check
#asks for confirmation, if answer is y or Y then counts down and continues, otherwise it stops the program
function yn(){
 echo
 echo "Are you sure?"
 read -p "  Wakeup in h:$hours m:$minutes, and till then $1. y/n " yesno
  if [[ $yesno == "Y" || $yesno == "y" ]]; then
   echo -ne "Continueing " && countdown 5
  else
   echo "Restart the Program"
   exit
  fi
}
## Choose What to do after calculating Time ##
#Here it decides what to do before suspending.  Change this list to reflect what you need. As in deadbeef --play
function choice(){
echo "Do you want to Suspend / Hibernate / Remain on?"
echo "    1) Suspend"
echo "    2) Hibernate"
echo "    3) Set time up but do it yourself (volume && suspend/hibernate)"
read -p "What is your choice? ex. 1  : " cin
case $cin in
 1)
  yn suspend
  amixer set Master 80%
  mpc play
  screen -d -m -S wakeup rtcwake -s $seconds -m on
  sudo pm-suspend
 ;;
 2)
  yn hibernate
  amixer set Master 80%
  mpc play
  screen -d -m -S wakeup rtcwake -s $seconds -m on
  sudo pm-hibernate
 ;;
 3)
  echo "In this mode you have to turn up the volume and suspend/hibernate yourself"
  screen -d -m -S wakeup rtcwake -s $seconds -m on
 ;;
 *)
  Nothing running.
  exit
 ;;
esac
}
## Main Program ##
echo "Please input amount of hours and minutes till Wakeup"
getnumber hours
hours=$b
num=0
getnumber minutes
minutes=$b
num=0
calculate $hours $minutes
seconds=$b
echo "Time till wakeup = $hours:$minutes . In seconds $seconds"
choice

Offline

#8 2011-11-17 09:27:10

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: [wakeup] testers wanted.

I've packaged your software
(AUR) and
am also happy to report that it worked exactly as advertised. I told
it to suspend my system for a minute, and while it was in suspend
mode, the power button of my ThinkPad blinked a bit, until my laptop
turned back on, where it resumed its solid green hue. Was that to be
expected?

Thanks for the lovely program!

As a side note, I was unsure how to make kernel26>=2.6.38 a
dependency, given that now the kernel package is called 'linux'. So I
didn't add that as a dependency. If you have a solution to this,
please let me know. Thanks again.

Last edited by Sara (2011-11-17 09:34:28)


Registed Linux User 483618

Offline

#9 2011-11-17 10:50:31

pommes_
Member
From: Germany
Registered: 2007-12-30
Posts: 31
Website

Re: [wakeup] testers wanted.

It works pretty good. However, a --help or -h parameter option would be nice. Also at the moment if you try to invoke an option like -h it goes into suspend, you should limit the characters you can use for the time to numbers followed by h/m/s.

Offline

#10 2011-11-17 11:24:14

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: [wakeup] testers wanted.

pommes_ wrote:

Also at the moment if you try to invoke an option like -h it goes into suspend, you should limit the characters you can use for the time to numbers followed by h/m/s.

I'm entering `wakeup -h` on the commandline and getting the following
output

wakeup from suspend in: 0 hours 0 min 0 sec
zsh: alarm      wakeup -h

and my system does not suspend. Are you entering anything differently?


Registed Linux User 483618

Offline

#11 2011-11-17 11:37:55

pommes_
Member
From: Germany
Registered: 2007-12-30
Posts: 31
Website

Re: [wakeup] testers wanted.

Sara wrote:
pommes_ wrote:

Also at the moment if you try to invoke an option like -h it goes into suspend, you should limit the characters you can use for the time to numbers followed by h/m/s.

I'm entering `wakeup -h` on the commandline and getting the following
output

wakeup from suspend in: 0 hours 0 min 0 sec
zsh: alarm      wakeup -h

and my system does not suspend. Are you entering anything differently?

I am entering exactly the same.

>>> wakeup -h
wakeup from suspend in: 0 hours 0 min 0 sec
tick.
Der Wecker klingelt

But if the things I mentioned above get implemented this issue will be gone anyway.

Offline

#12 2011-11-18 14:35:55

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: [wakeup] testers wanted.

fogobogo wrote:

- You cant query / nor delete the timer at the moment.
Once set it will happen (*if* you are suspended). However I *think*
you can overwrite a timer.

Do you mean that if you set it to suspend, you cannot unsuspend until
the time is up? Because with a laptop, that is set to resume from
suspend by opening the lid, this is not an issue, because I can resume
by just opening the lid. Or maybe you meant something else.


Registed Linux User 483618

Offline

#13 2011-11-20 21:30:21

fogobogo
Member
Registered: 2008-08-24
Posts: 83

Re: [wakeup] testers wanted.

pommes_ wrote:

It works pretty good. However, a --help or -h parameter option would be nice. Also at the moment if you try to invoke an option like -h it goes into suspend, you should limit the characters you can use for the time to numbers followed by h/m/s.

You're right. I'll fix that soon. As mentioned the arg parsing isn't very robust at the moment. using h/m/s shouldn't be a problem since that differs from -h.

update: updated. There was a check for digits already in place btw. What was missing was that it interpreted the 'h' and no digits as 0 hours. That should be fixed now.

Last edited by fogobogo (2011-11-20 22:54:35)

Offline

#14 2011-11-20 21:40:53

fogobogo
Member
Registered: 2008-08-24
Posts: 83

Re: [wakeup] testers wanted.

Do you mean that if you set it to suspend, you cannot unsuspend until
the time is up? Because with a laptop, that is set to resume from
suspend by opening the lid, this is not an issue, because I can resume
by just opening the lid. Or maybe you meant something else.

No it means that if you set the timer and don't suspend (it currently does that by itself but imagine a version that wouldn't automatically trigger suspending) and you suspend at some later timer it would wake up again. That is potentially troublesome which is why I choose to let it trigger suspending immediately.
So for example, you set a timer, do some stuff and forget about it. then you suspend sometime later and then the timer will trigger a wakeup. In case you are just making a romantic walk with your laptop in the bag that behaviour can be problematic. If you aren't suspended and the timer runs out nothing happens.

As for the tint, well... no idea about that. It sure hasn't anything to do with the program since all it does is setting a timer and execute 'pm-suspend' just like you would in a terminal. I'll see if upower can be used as an alternative.

And many thanks for the PKGBUILD!

Offline

#15 2011-11-20 22:42:50

fogobogo
Member
Registered: 2008-08-24
Posts: 83

Re: [wakeup] testers wanted.

Alright. I added a bit stuff and there is a -h as well as a --help parameter now. I wouldn't call the arg parsing idiotproof right now but it should also throw a lot less nonsensical output and also be a bit more sensitive.

Offline

#16 2011-11-21 00:09:07

Sara
Member
From: USA
Registered: 2009-07-09
Posts: 219
Website

Re: [wakeup] testers wanted.

fogobogo wrote:

As for the tint, well... no idea about that. It sure hasn't anything to do with the program since all it does is setting a timer and execute 'pm-suspend' just like you would in a terminal. I'll see if upower can be used as an alternative.

And many thanks for the PKGBUILD!

The tint is actually something my laptop (x220) does by default, but
my last ThinkPad didn't have that nice LED, so I wasn't expecting it.
I hadn't realized it always did this because in the past I just closed
the lid to suspend, and never looked at the power button.

No problem.


Registed Linux User 483618

Offline

#17 2011-12-04 12:30:45

onny
Member
From: Europe
Registered: 2010-08-07
Posts: 46
Website

Re: [wakeup] testers wanted.

I love this script, works very well on my laptop and saves a lot of battery wink Thank you!

Offline

#18 2011-12-04 15:24:34

ijanos
Member
From: Budapest, Hungary
Registered: 2008-03-30
Posts: 443

Re: [wakeup] testers wanted.

Nicely done! Feature request: what about adding an option which accepts an exact time and calculates the time difference from now.

Something like ./wakeup -at 8:00 or with some intelligent syntax: ./wakeup -at tomorrow, 8:00

I could write a bash wrapper for this if I really want to, but it would be better suited inside the application.

Offline

#19 2011-12-04 19:21:19

el mariachi
Member
Registered: 2007-11-30
Posts: 595

Re: [wakeup] testers wanted.

how can I connect this to mplayer and make it a *real* alarm clock? I wonder what waking up beethoven's 9th sounds like xD

Offline

#20 2011-12-04 21:18:46

ijanos
Member
From: Budapest, Hungary
Registered: 2008-03-30
Posts: 443

Re: [wakeup] testers wanted.

el mariachi wrote:

how can I connect this to mplayer and make it a *real* alarm clock? I wonder what waking up beethoven's 9th sounds like xD


Easyly open a terminal and write this:

sleep 20 && mplayer /path/to/9th.mp3

then you have 20 seconds to put your computer to suspend. In suspend the mplayer's countdown will be freezed and it will be resumed when the computer wakes up.

Offline

#21 2011-12-06 09:21:04

fogobogo
Member
Registered: 2008-08-24
Posts: 83

Re: [wakeup] testers wanted.

ijanos wrote:

Nicely done! Feature request: what about adding an option which accepts an exact time and calculates the time difference from now.

Something like ./wakeup -at 8:00 or with some intelligent syntax: ./wakeup -at tomorrow, 8:00

I could write a bash wrapper for this if I really want to, but it would be better suited inside the application.

I will try that next, however that kind of parsing isn't trivial. It might take a while before its working

Offline

#22 2011-12-06 09:25:00

fogobogo
Member
Registered: 2008-08-24
Posts: 83

Re: [wakeup] testers wanted.

el mariachi wrote:

how can I connect this to mplayer and make it a *real* alarm clock? I wonder what waking up beethoven's 9th sounds like xD

I'm on it currently. It isn't as straightforward as it sounds since the process is already done and finished (hence not running anymore) once you set a time and well, a process that isn't running can't do anything. It should work with a signal event though.

Offline

#23 2011-12-06 11:20:00

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [wakeup] testers wanted.

fogobogo wrote:
ijanos wrote:

Nicely done! Feature request: what about adding an option which accepts an exact time and calculates the time difference from now.

Something like ./wakeup -at 8:00 or with some intelligent syntax: ./wakeup -at tomorrow, 8:00

I could write a bash wrapper for this if I really want to, but it would be better suited inside the application.

I will try that next, however that kind of parsing isn't trivial. It might take a while before its working

leverage a tool that already does this parsing, and just have wakeup read an absolute time as seconds from epoch, e.g.

$ wakeup -a "$(date -d 'tomorrow 8:00' +%s)"

Adding this feature becomes trivial then.

Offline

#24 2011-12-06 11:45:19

fogobogo
Member
Registered: 2008-08-24
Posts: 83

Re: [wakeup] testers wanted.

falconindy wrote:

leverage a tool that already does this parsing, and just have wakeup read an absolute time as seconds from epoch, e.g.

$ wakeup -a "$(date -d 'tomorrow 8:00' +%s)"

Adding this feature becomes trivial then.

It should be possible to do that inside the application with somewhat minimal hassle. strptime() looks like a good start, but stuff like "tomorrow" might be a bit over the top for it.

Offline

#25 2011-12-06 13:33:18

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [wakeup] testers wanted.

strptime(3) is pretty much an analog to sscanf(3) and is meant for parsing well-known structured data. You'd have to reverse engineer (so to speak) the user's intentions. At that point, you may as well just be parsing the string manually.

Offline

Board footer

Powered by FluxBB