Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Readers > Amazon Kindle > Kindle Developer's Corner

Notices

Reply
 
Thread Tools Search this Thread
Old 03-14-2014, 03:55 AM   #1
peterson
Connoisseur
peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.
 
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?
peterson is offline   Reply With Quote
Old 03-14-2014, 03:35 PM   #2
ramast
Member
ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'
 
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
ramast is offline   Reply With Quote
Advert
Old 03-14-2014, 03:58 PM   #3
peterson
Connoisseur
peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.
 
Posts: 74
Karma: 889004
Join Date: Mar 2014
Device: Kindle PW2
Quote:
Originally Posted by ramast View Post
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
I did another test earlier today, where I had my screensaver update every 10 minutes (the weather image has a timestamp so I know when it was updated). Unfortunately I have not yet figured out how to refresh the screensaver, however turning the Kindle on, entering my passcode and turning it off again would show me the latest screensaver available on the device.

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
shows me that the device was suspended multiple times.

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)
peterson is offline   Reply With Quote
Old 03-14-2014, 04:56 PM   #4
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
Quote:
Originally Posted by peterson View Post
I did another test earlier today, where I had my screensaver update every 10 minutes (the weather image has a timestamp so I know when it was updated). Unfortunately I have not yet figured out how to refresh the screensaver, however turning the Kindle on, entering my passcode and turning it off again would show me the latest screensaver available on the device.

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
shows me that the device was suspended multiple times.

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.
The kernel log, dmesg, will tell you when it changes state.

There is a KUAL button for a utility that copies the kernel ring buffer to a *.txt file you can view on the Kindle.
knc1 is offline   Reply With Quote
Old 03-14-2014, 05:24 PM   #5
peterson
Connoisseur
peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.
 
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).
peterson is offline   Reply With Quote
Advert
Old 03-15-2014, 12:36 AM   #6
ramast
Member
ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'ramast knows the difference between 'who' and 'whom'
 
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
ramast is offline   Reply With Quote
Old 03-15-2014, 02:16 AM   #7
peterson
Connoisseur
peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.
 
Posts: 74
Karma: 889004
Join Date: Mar 2014
Device: Kindle PW2
Quote:
Originally Posted by ramast View Post
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.
That's not necessarily true, a suspended computer can wake up from various events. E.g. the kindle can wake up when button pushes are detected or USB events. My laptop also wakes up when there is network traffic (wake-on-lan).

I hope that e.g. the RTC (realtime clock) can provide alarms that might wake up the Kindle.

Quote:
your only bet is to prevent your kindle form being suspended in the first place, not sure how though
That's easy. I could just increase the timeout or defer suspend indefinitely. But this would be plan B (or C).
peterson is offline   Reply With Quote
Old 03-15-2014, 10:46 AM   #8
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,477
Karma: 26012492
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.
NiLuJe is offline   Reply With Quote
Old 03-15-2014, 12:56 PM   #9
peterson
Connoisseur
peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.
 
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
and run it via "./test.sh &". Then I unplugged the cable (screen saver was active). From previous tests I know that the device goes to suspend after roughly 120 seconds. So I waited 7 minutes and turned the device back on.

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.
peterson is offline   Reply With Quote
Old 03-16-2014, 02:20 AM   #10
peterson
Connoisseur
peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.
 
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
}
peterson is offline   Reply With Quote
Old 03-16-2014, 09:20 AM   #11
NiLuJe
BLAM!
NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.NiLuJe ought to be getting tired of karma fortunes by now.
 
NiLuJe's Avatar
 
Posts: 13,477
Karma: 26012492
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
@peterson: Neat! .
NiLuJe is offline   Reply With Quote
Old 03-16-2014, 11:43 AM   #12
peterson
Connoisseur
peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.
 
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.
peterson is offline   Reply With Quote
Old 03-18-2014, 01:47 AM   #13
peterson
Connoisseur
peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.peterson ought to be getting tired of karma fortunes by now.
 
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
peterson is offline   Reply With Quote
Old 06-26-2017, 03:03 PM   #14
Bluescreen
Member
Bluescreen began at the beginning.
 
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
Bluescreen is offline   Reply With Quote
Old 06-26-2017, 03:33 PM   #15
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
Quote:
Originally Posted by Bluescreen View Post
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
Are you using the version shown in the post immediately prior to your own post?
knc1 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 08:19 PM.


MobileRead.com is a privately owned, operated and funded community.