Author |
Message |
iscraigh
|
Posted: Sun Apr 27, 2008 1:45 am |
|
Joined: Mon Mar 21, 2005 1:43 pm
Posts: 388
Location:
Nanaimo BC
|
Thought I better start a new thread
Trying to get ACPI wakeup to work
Status so far
Can set a sleep time as described on wiki and box wakes up.
After running commands from scripts it appears the command
/bin/date -d "1970-01-01 UTC $2 sec" +%F\ %T\ %:z
Gives me
1969-12-31 16:00:01 -08:00
Now unless I have traveled back in time and froze time this appears incorrect (it never changes always 1600 hours)
This explains why my wakeup time is always the same 03:00 haven't figured out that calculation yet.
Now ignoring the date because it doesn't seem to matter, I see that it thinks I am 8 hrs ahead of utc (pacific time PDT) but my bios thinks I am -7 hrs when I check an online utc clock I am 7 hrs
So the bios is correct my frontend displays the correct time Why does the above command put me @-8 (which will be correct when Daylight savings time ends)
2 different issues?
Any help appreciated.
Thanks
Craig
|
|
Top |
|
|
iscraigh
|
Posted: Sun Apr 27, 2008 2:20 am |
|
Joined: Mon Mar 21, 2005 1:43 pm
Posts: 388
Location:
Nanaimo BC
|
okay more info
If I run this command
Code: /bin/date -f /home/mythtv/timestamp +%F\ %T\ %z I get 1970-01-01 00:00:01 -0800If I run the same command without the -f (file switch) Code: /bin/date +%F\ %T\ %z
I get
2008-04-27 01:16:49 -0700
Correct time correct offset
any idea's
Thanks
Craig
|
|
Top |
|
|
marc.aronson
|
Posted: Sun Apr 27, 2008 8:06 am |
|
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location:
California
|
I was running into a problem that sounds similar. In essence, when I converted local time to UTC, it was off by one hour. I eventually got it working and decide to encapsulate the logic into a series of BASH functions.
Code: # # Convert time stamp $1, provided in local time, to # seconds since epoch # function date_local_2_epoch { echo `date -d "$1 " +"%s"` return } # # Convert # secs since epoch ($1), to UTC time stamp # function date_epoch_2_utc { echo `date -u -d "1970-01-01 UTC + $1 sec" +"%Y-%m-%d %T" ` return } # # Convert # secs since epoch ($1), to local time stamp # function date_epoch_2_local { echo `date -d "1970-01-01 UTC + $1 sec" +"%Y-%m-%d %T" ` return } # # Convert time stamp $1, provided in local time, to UTC time stamp # function date_local_2_utc { epoch=$( date_local_2_epoch "$1" ) echo `date_epoch_2_utc "$epoch"` return 0 }
|
|
Top |
|
|
iscraigh
|
Posted: Sun Apr 27, 2008 11:52 am |
|
Joined: Mon Mar 21, 2005 1:43 pm
Posts: 388
Location:
Nanaimo BC
|
I found this script and late last night turned my box off and it appears to have worked. My understanding is it calculates # of seconds to wakeup and sets the time this way.
stamp_file=/home/mythtv/timestamp
#just log what we get as command line parameters
echo $1 $2 $3> $stamp_file
#I set mythtv to output the number of seconds since epoch
#so I calculate the number of hours, minutes and seconds from
#now the computer has to wakeup:
sfn=$(($2 - `date +"%s"`))
# Offset from GMT as the awk function does timezone correction.
Code: tzone=3600 #and then send it to /proc/acpi/wakeup in the format we saw above y=`(echo $(($sfn - $tzone))|awk '{print strftime("+00-00-00 %H:%M:%S", $1)}')` echo "$y">/tmp/alarm echo "$y">>$stamp_file echo "executed at `date`" >> $stamp_file exit It looks similar to Marc's, one question this line Code: tzone=3600
What is it doing? I will report back if this continues working.
Craig
|
|
Top |
|
|
marc.aronson
|
Posted: Sun Apr 27, 2008 12:42 pm |
|
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location:
California
|
3600 is the number of seconds in one hour. I suspect that what they are doing is subtracting 1 hour from the SFN (Seconds From Now) to compensate for the 1-hour time zone problem that I also saw. I am not sure if this solution will always work, as I suspect that 1-hour offset is not required once BST (British Summer Time) is over, but I can't be certain of this as I am not as familiar with how the awk function strftime handles these situations.
Marc
|
|
Top |
|
|
iscraigh
|
Posted: Sun Apr 27, 2008 2:26 pm |
|
Joined: Mon Mar 21, 2005 1:43 pm
Posts: 388
Location:
Nanaimo BC
|
I guess I will find out in the fall
Craig
|
|
Top |
|
|
alien
|
Posted: Mon Apr 28, 2008 5:49 am |
|
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location:
Germany
|
First off, a few things to check: Is the last line of /etc/adjtime "UTC" (i.e. is the hwclock running UTC)? Does the "date" command show local time? Does the "date -u" command show the correct UTC time? If the above are all yes, then you might try a simpler "date" command. I use the following Code: #!/bin/bash
TIME=@$2 date -u -d $TIME +"%F %T" > /tmp/alarm # Then, /etc/init.d/hwclock.sh is modified to read this file Basically "date -u -d @<sec> +"%F %T" should give the correct wakeup time in UTC. Ex: Code: sh-3.1$ date +%s 1209382982 sh-3.1$ date -u -d @1209382982 +"%F %T" 2008-04-28 11:43:02 sh-3.1$
_________________ ASUS AT3N7A-I (Atom 330) TBS 8922 PCI (DVB-S2)
|
|
Top |
|
|
iscraigh
|
Posted: Mon Apr 28, 2008 5:47 pm |
|
Joined: Mon Mar 21, 2005 1:43 pm
Posts: 388
Location:
Nanaimo BC
|
Okay I think I am starting to understand, modifying the origional script to look like this
Code: #!/bin/bash
# Script to set wakeup time using acpi alarm # Called from mythwellcome: # first option passed from mythwelcome is --settime second is seconds since 1970
# Convert from stupid time in seconds since 1970 ### (old)datum=$(/bin/date -d"1970-01-01 UTC $2 sec" +%F\ %T\ %:z) datum=$ date +%s ##new way # Reinterpret this in utc and write to alarm utcdatum=$(/bin/date -u -d "$datum" +%F %T)
# Write wakeup time to acpi alarm echo $utcdatum>/tmp/alarm # Then, /etc/init.d/hwclock.sh is modified to read this file
##Try this script out should work or am I missing something (your commands work in a terminal---Yes to all above questions) I did not understand this line Code: TIME=@$2 Is TIME (called datum in the script I was using) not coming from this command. Code: $ date +%s
I don't get the @$2 reference sorry to be a pain but it is about learning a bit. I will have to by a book and teach myself some basic scripting, I am getting tired of not understanding it. Thanks for your reply if what I am planning to do looks correct I will try it out ASAP.
Thanks
Craig
|
|
Top |
|
|
marc.aronson
|
Posted: Mon Apr 28, 2008 8:26 pm |
|
Joined: Tue Jan 18, 2005 2:07 am
Posts: 1532
Location:
California
|
Craig,
If I understand correctly, your script is called with the restart time in local time as "$1", and the restart time as seconds since the "epoch" as "$2". If this is correct, and you include those functions I provided in my original reply at the top of your BASH script, you can then simply:
date_local_2_utc "$1" > /tmp/alarm
or
date_epoch_2_utc "$2" > /tmp/alarm
Marc
|
|
Top |
|
|
alien
|
Posted: Tue Apr 29, 2008 2:13 am |
|
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location:
Germany
|
alien wrote: Code: #!/bin/bash
TIME=@$2 date -u -d $TIME +"%F %T" > /tmp/alarm # Then, /etc/init.d/hwclock.sh is modified to read this file Let me explain this a bit more...
This is the script mythshutdown calls to set the wakeup time. The second parameter ($2) is the time to wakeup in seconds since 1970.
TIME=@$2 sets $TIME to be "@" followed by the seconds since 1970. This is the format to pass seconds since 1970 to date.
date -u -d $TIME +"%F %T" > /tmp/alarm converts $TIME to the format expected by ACPI wakeup and puts it in a file /tmp/alarm.
hwclock.sh then needs to be modified to set the wakeup with what is in /tmp/alarm.
This script does the conversion with just one simple call to date, so there is less risk of a conversion error.
_________________ ASUS AT3N7A-I (Atom 330) TBS 8922 PCI (DVB-S2)
|
|
Top |
|
|
iscraigh
|
Posted: Tue Apr 29, 2008 7:55 pm |
|
Joined: Mon Mar 21, 2005 1:43 pm
Posts: 388
Location:
Nanaimo BC
|
I won't have a chance to try this out until the weekend or possibly I will have an hour tommorow. I thank you for your patience but I am still missing the logic of this line
TIME=@$2
You are setting the time variable
@= literal AT
$2 is a variable....seconds from 1970 til wakeup
Where is the data for the $2 variable coming from.......hang on a moment of clarity (maybe) this variable is coming from the shutdown script? I will have to look, this is like learning a new language never my strong point.
thanks
Craig
|
|
Top |
|
|
alien
|
Posted: Wed Apr 30, 2008 2:17 am |
|
Joined: Mon Jun 21, 2004 5:28 am
Posts: 700
Location:
Germany
|
Using a bash or sh script, $1 is the first parameter on the command line, $2 is the second, etc. Ex. Calling the script like Code: allen@violet:~$ ./set-wakeup.sh manual 1209542813
$1 is "manual" and $2 is "1209542813".
The set-wakeup.sh is configured in mythwelcome setup. mythshutdown will call this script just before shutdown. It passes the seconds since 1970 as the second parameter.
Where did mythshutdown get the time? Well, it was configured in mythtv setup. Mythtv-backend (which knows the next time to wakeup) calls "mythshutdown --set-wakeup <time>" just before shutdown. This then calls set-wakeup.sh.
Allen
_________________ ASUS AT3N7A-I (Atom 330) TBS 8922 PCI (DVB-S2)
|
|
Top |
|
|