![]() |
#1 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 74
Karma: 889004
Join Date: Mar 2014
Device: Kindle PW2
|
Wake up from sleep
Is there a way to force the Kindle (here a PW2) to execute a command (shell script, ...) at a specific time? Obviously one could add a cron job, however when the device goes into suspend the cron jobs are not executed.
The only solution I can think of right now is to prevent the device from suspending (hence in part my other question regarding power consumption (235820)). However, ideally one could set some kind of "alarm" that triggers the device to wake at a specific time? |
![]() |
![]() |
![]() |
#2 |
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 18
Karma: 10000
Join Date: Mar 2014
Device: Kindle Paperwhite
|
Are you sure PW2 does actually suspend? if you try to make a crontab that execute every 20 minute and append system date to a file in /tmp and leave it overnight we can tell if it actually suspend or not
|
![]() |
![]() |
Advert | |
|
![]() |
#3 | |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 74
Karma: 889004
Join Date: Mar 2014
Device: Kindle PW2
|
Quote:
What I noticed was that after some (not measured amount of) time, turning it on/off would not show a timestamp from the last 10 minutes, instead significantly older. Also, doing Code:
dmesg | grep suspend As I did a lot of tests today, I will repeat the test overnight to make sure I did observe this correctly. But as far as I can tell so far, the device actually suspends. Last edited by peterson; 03-14-2014 at 03:59 PM. Reason: Fix typo (susped -> suspend) |
|
![]() |
![]() |
![]() |
#4 | |
Going Viral
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
There is a KUAL button for a utility that copies the kernel ring buffer to a *.txt file you can view on the Kindle. |
|
![]() |
![]() |
![]() |
#5 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 74
Karma: 889004
Join Date: Mar 2014
Device: Kindle PW2
|
Okay. I unplugged the device about 2 hours ago. The cron job was set to add a timestamp every 10 minutes.
Connecting to the device, I see three timestamps. Two from after the power-off, one from power-on (apparently the cron job catches up). For these two timestamps I still had the USB cable plugged in and an active ssh session. I unplugged the cable, and according to dmesg the device suspended 110 seconds later. q.e.d. So now I wonder: how do I wake it up during this suspend? In powerd, I see a rtcWakeUp property, which sounds promising. Anybody ever used it? I can't seem to find a value it accepts (X=0, 1, 100, 20000, all return "can only seem to set it to 0 or 1 However I am not sure what precisely" when running lipc-set-prop com.lab126.powerd rtcWakeup -i X). |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 18
Karma: 10000
Join Date: Mar 2014
Device: Kindle Paperwhite
|
If your kindle is suspended no matter what code you will write it will not execute to wake up your kindle.
Its like writing a program to wake up your computer from sleep mode. your only bet is to prevent your kindle form being suspended in the first place, not sure how though |
![]() |
![]() |
![]() |
#7 | ||
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 74
Karma: 889004
Join Date: Mar 2014
Device: Kindle PW2
|
Quote:
I hope that e.g. the RTC (realtime clock) can provide alarms that might wake up the Kindle. Quote:
|
||
![]() |
![]() |
![]() |
#8 |
BLAM!
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,506
Karma: 26047190
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
@peterson: The only hint we have in that direction is that the ad management system seems to be able to do it, but, AFAIK, noone has dug something useful out of it yet.
|
![]() |
![]() |
![]() |
#9 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 74
Karma: 889004
Join Date: Mar 2014
Device: Kindle PW2
|
I did some digging, googling and minor head scratching, and I believe it is possible to wake up a device at a specific time.
The Kindle's processor has a RTC (real time clock) that can be accessed via /sys/class/rtc/rtc0. There's also rtc1 and rtc2. I wrote the following small script: Code:
TS=`date +%s` TS=$(($TS + 200)) for i in 0 1 2; do echo 0 > /sys/class/rtc/rtc$i/wakealarm echo $TS > /sys/class/rtc/rtc$i/wakealarm if test $TS -ne `cat /sys/class/rtc/rtc$i/wakealarm`; then echo "Failure setting alarm on rtc$i, wanted $TS, got `cat /sys/class/rtc/rtc$i/wakealarm`" else echo "Success on rtc$i" fi done while test $TS -gt `date +%s`; do sleep 1 done date >> /tmp/alarmlog In dmesg I can see that after I unplugged the cable the Kindle would suspend. Then it woke up and a minute later went back to sleep. It woke up again when I plugged the cable back in. /tmp/alarmlog shows a date-time which is 206 seconds after I issued the command. I will have to do more tests, mainly to see which rtc is safe to use (wouldn't want to overwrite an alarm by the Kindle OS). Also how long the device wakes up, it may be that one has to trigger some action to prevent it going back to sleep too soon. |
![]() |
![]() |
![]() |
#10 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 74
Karma: 889004
Join Date: Mar 2014
Device: Kindle PW2
|
![]() The alarm seems to work very well. Still some minor parts I am unsure about, but it definitely works. Below is a shell function that will wait for a given amount of time. Last night I set my weather screensaver script to run in 30 minute intervals, and it did. According to the log I created and the accompanying dmesg output, the device woke up every 30 minutes, downloaded the latest weather report, and then went back to sleep 90 seconds after that. Code:
# the RTC to use RTC=0 OUTPUTFILE=/tmp/alarmlogger # sets an RTC alarm # arguments: $1 - time in seconds from now wait_for () { TS=`date +%s` TS=$(($TS + $1)) echo "Setting alarm to $TS ($1 seconds in the future)" >>$OUTPUTFILE echo 0 > /sys/class/rtc/rtc$RTC/wakealarm echo $TS > /sys/class/rtc/rtc$RTC/wakealarm if test $TS -ne `cat /sys/class/rtc/rtc$RTC/wakealarm`; then echo "Failure setting alarm on rtc$RTC, wanted $TS, got `cat /sys/class/rtc/rtc$RTC/wakealarm`" >>$OUTPUTFILE else echo "Success on rtc$RTC" >>$OUTPUTFILE # wait for the alarm to end while test 1 -eq 1; do if test 0 -eq $((`cat /sys/class/rtc/rtc$RTC/wakealarm`)); then break; elif test `date +%s` -gt $((`cat /sys/class/rtc/rtc$RTC/wakealarm`)); then break; else sleep 1 fi done fi # not sure whether this is required lipc-set-prop com.lab126.powerd -i deferSuspend 1 } |
![]() |
![]() |
![]() |
#11 |
BLAM!
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 13,506
Karma: 26047190
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
@peterson: Neat!
![]() |
![]() |
![]() |
![]() |
#12 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 74
Karma: 889004
Join Date: Mar 2014
Device: Kindle PW2
|
I am still looking for a better way to wait for the wake-up. The "sleep 1" seems too aggressive. Maybe increasing slightly (to 5s?) may be better, but still I really am not a fan of polling :-)
Also I noticed that sometimes (or right now quite often) I can not turn the WiFi on. My device wakes up rather reliably and my script runs, but it does not successfully establish a wifi or internet connection. Timeout is 20s. |
![]() |
![]() |
![]() |
#13 |
Connoisseur
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 74
Karma: 889004
Join Date: Mar 2014
Device: Kindle PW2
|
Here is an updated and probably final version.
It uses lipc-wait-event to not have to busy-wait, so there is virtually no additional overhead now. Precision is plus/minus a second at best, though the RTC clock may wake up several seconds earlier/later. But this should be okay. N.B.: My wifi issue is only at work, so this must be a network problem (probably need a higher timeout). At home it is working flawlessly. Code:
RTC=0 currentTime () { date +%s } wait_for () { # calculate the time we should return ENDWAIT=$(( $(currentTime) + $1 )) # disable/reset current alarm echo 0 > /sys/class/rtc/rtc$RTC/wakealarm # set new alarm echo $ENDWAIT > /sys/class/rtc/rtc$RTC/wakealarm # check whether we could set the alarm successfully if [ $ENDWAIT -eq `cat /sys/class/rtc/rtc$RTC/wakealarm` ]; then # wait for timeout to expire while [ $(currentTime) -lt $ENDWAIT ]; do REMAININGWAITTIME=$(( $ENDWAIT - $(currentTime) )) if [ 0 -lt $REMAININGWAITTIME ]; then # wait for device to resume from sleep, or for time out lipc-wait-event -s $REMAININGWAITTIME com.lab126.powerd resuming || true fi done else echo "Failure setting alarm on rtc$RTC, wanted $ENDWAIT, got `cat /sys/class/rtc/rtc$RTC/wakealarm`" fi # not sure whether this is required lipc-set-prop com.lab126.powerd -i deferSuspend 1 } # wait 2 hours and then wake up wait_for 120 echo "Good morning" Last edited by peterson; 03-18-2014 at 07:08 AM. Reason: removed waiting for readyToSuspend, this is not necessary |
![]() |
![]() |
![]() |
#14 |
Member
![]() Posts: 12
Karma: 10
Join Date: Feb 2010
Device: Kindle Paperwhite 2
|
Hi,
I played around with this onlinescreensaver now. But I cannot get it working properly on my Kindle PW2. I have the bad 5.8.9.2 firmware and jailbreaked it via serial hack. This seems to work. I can install packages and so on. Also the downloading and setting the picture works. But only if the Kindle is on. It seems the RTC cannot wakeup the kindle from suspend mode. I made some experiments with the wait_for function. It can set the timer in /sys/class/rtc/rtc0/wakealarm and can reread the value. If I set the wait value to something so short that the device does not go to sleep, it correctly returns after the desired time. If I short press the power button to suspend the device after letting wait_for set the alarm it never returns until I power on the device. Any ideas? BTW. is there any way to set the screensaver timeout (maybe with the installed screensaver hack) or suspend/screensave the device via script. Thorsten |
![]() |
![]() |
![]() |
#15 | |
Going Viral
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
|
Quote:
|
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Glo Kobo Glo won't wake from sleep - on battery | jamawg | Kobo Developer's Corner | 3 | 11-15-2013 10:33 PM |
Nov Patch doesn't fix Wake-from-Sleep bug | borisb | Kobo Tablets | 77 | 12-04-2011 09:06 PM |
Kindle 2 Screensaver or Wake From Sleep Problem | JoeC | Amazon Kindle | 13 | 04-03-2011 02:58 PM |
Shortcut to wake up? Way to increase time between idle & sleep-mode? | joe2010 | Amazon Kindle | 0 | 06-11-2010 08:41 PM |