Alarm clock functionality - sleep and wakeup via scripts


spiralofhope

Member
Joined
Jun 20, 2011
Messages
201
Website
blog.spiralofhope.com
I'd like to write some scripts which can control the Pandora's wakefulness / standby state. Wake up and perform tasks at specific times, sleep/standby on specific events or times.


Is there software provided with the Pandora which I can send a particular time for the system to be brought out of standby? (hopefully also with parameters like work like the `sleep` program).


What command would I use to put the Pandora on standby?


To clarify, this is not possible with at, cron, or any alarm clock app because nothing is running when the Pandora is on standby. It must be a Pandora-specific utility.


Once I have a utility which can have the Pandora enable standby, or bring it out of standby either at a certain time or in a certain number of seconds.. I can write a script to do everything I need.


--


Related?: Does pandora have a rtc


[edited for clarity]
 
Last edited by a moderator:
It depends - not sure what state is the Pandora in when you close the lid and goes "on sleep" - whether scripts can be executed in the background during that time or not. If you could, then a cron job may work to execute a series a command at a precise time or time intervall.
 
I too would like this. I might take a look when my Pandora returns - alongside the PND command wrapper
 
It depends - not sure what state is the Pandora in when you close the lid and goes "on sleep" - whether scripts can be executed in the background during that time or not. If you could, then a cron job may work to execute a series a command at a precise time or time intervall.

Closing the lid just turns the screen off (by default). I'm talking about the sleep state when the power switch is flicked.

I too would like this. I might take a look when my Pandora returns - alongside the PND command wrapper

I'd appreciate that.


I'm trying to replicate the alarm clock functionality on my hp200lx and stop using my cell phone as an alarm clock.
 
The TWL chip which is the battery charger is also a the real time clock. You can give it i2c commands to trigger an interrupt at a specific time. This interrupt is effectively the exact same as flipping the power switch, so can be used to turn your Pandora on at a specific time or bring it out of standby. Install the i2c-tools package from the repo and I'll see if I can remember the exact instructions that need to be sent that you can experiment with.
 
The TWL chip which is the battery charger is also a the real time clock. You can give it i2c commands to trigger an interrupt at a specific time. This interrupt is effectively the exact same as flipping the power switch, so can be used to turn your Pandora on at a specific time or bring it out of standby. Install the i2c-tools package from the repo and I'll see if I can remember the exact instructions that need to be sent that you can experiment with.
Is there no way to put it to sleep and wake it up without adding a non-default library?


Would something like this work?


http://stackoverflow.com/questions/726596/continual-wake-and-sleep-for-minimal-power-usage-on-linux


My plan is to build a full GUI app. Am tempted to build in a simple media player, with the idea that you'll press a button to "go to sleep", which will continue to play music at ever decreasing volumes for 30 minutes or so (maybe also option to decrease screen brightness), before suspending to RAM; and do the reverse for the "alarm" side.


Either that, or just control the master volume and leave the user to run their own player
 
You could put it into the old "low power" mode where it's just wifi and screen off, and then wake it up again at a future date. Would that work? That's the only thing you can do from the user side, the actual suspend is effectively "off" so no scripts will run without that interrupt and the only way to trigger the interrupt is with an i2c command.


edit: Actually, that "/sys/class/rtc/rtc0/wakealarm" might already be doing the i2c commands. Have you tried it?


The Pandora needs to do more than just modify "/sys/power/state" when it needs to go to sleep, but you can manually call "sudo /usr/pandora/script/op_power.sh" which will do the same thing as flipping the power switch: ie, go to standby.
 
Last edited by a moderator:
I've not got my Pandora back yet, so I can't try it yet :(


I can't even browse what scripts there are to see if there's anything useful. Thanks for pointing out the op_power.sh, that probably will be
 
Awesome, it worked exactly as expected.


It needs to be done as super user (sudo su) but then you can just "echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm; /usr/pandora/script/op_power.sh;" and it'll shut down for 5 minutes.
 
Awesome, it worked exactly as expected.


It needs to be done as super user (sudo su) but then you can just "echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm; /usr/pandora/script/op_power.sh;" and it'll shut down for 5 minutes.

Thanks again for the advice. I've been playing with it, and I have much more playing to do.


--


For others following this thread who are interested, something is broken - I have not spent any time investigating yet.



Code:
\echo $( \date '+%s' -d '+ 10 seconds' ) > \

/sys/class/rtc/rtc0/wakealarm

/usr/pandora/script/op_power.sh



I'll play with the `date` command to understand it some more.



It looks like there are issues with the op_power script:





Code:
/usr/pandora/script/op_power.sh: line 13: test: /var/run/polkit: binary operator expected

Can't get device info: No such device

Can't get device info: No such device

/usr/pandora/script/op_power.sh: line 196: echo: write error: Operation not permitted

Can't get device info: No such device

Starting WL1251 MAC80211 Wireless LAN driver: wl1251.


In time I will investigate this and fix the script myself if I can.


I guess that I can choose to not run op_power. Then the user can run this script, continue working and turn it off when they like. Then the Pandora will wake up to run the alarm.


This is all very basic right now, but it seems like I will be able to do what I want - in time.
 
Last edited by a moderator:
Awesome, it worked exactly as expected.


It needs to be done as super user (sudo su) but then you can just "echo `date '+%s' -d '+ 5 minutes'` > /sys/class/rtc/rtc0/wakealarm; /usr/pandora/script/op_power.sh;" and it'll shut down for 5 minutes.
When I try the echo line, I get permission denied on the wakealarm file, even if I sudo it. Any ideas?


Edit: Okay, so if I do "sudo su" first, it works (to clarify, it writes to the wakealarm). However, my app won't be running as a super user. Is there any way I can get around this?


Edit 2: Urm, my Pandora isn't waking up when I do this either :(
 
Last edited by a moderator:
Edit: Okay, so if I do "sudo su" first, it works (to clarify, it writes to the wakealarm). However, my app won't be running as a super user. Is there any way I can get around this?
Write the echo line into it's own script, and then call that script with gksudo. It'll ask for the user's password to set it. Alternatively, can probably change the permission on /sys/class/rtc/rtc0/wakealarm file. Generally not recommended, but what harm could it really do?


Specifically what is happening when you try to "sudo" the entire line is that it applies the super user to the echo "line" which technically ends at the > redirection. Regular user is then used to try and write the file. There was a reason that unix was designed this way, I just never understood it.

Edit 2: Urm, my Pandora isn't waking up when I do this either :(
I remember having some issues with timezones, but didn't think much of it at the time because I was constantly messing with the dates and such.


You may have to add the "-u" option to the date command indicate it should be in UTC.
 
Write the echo line into it's own script, and then call that script with gksudo. It'll ask for the user's password to set it. Alternatively, can probably change the permission on /sys/class/rtc/rtc0/wakealarm file. Generally not recommended, but what harm could it really do?


Specifically what is happening when you try to "sudo" the entire line is that it applies the super user to the echo "line" which technically ends at the > redirection. Regular user is then used to try and write the file. There was a reason that unix was designed this way, I just never understood it.
Notaz indicated similar in my thread on screen brightness. I might write it as an op_wakeup.sh that I can add to the auto-sudo list (as I like to call it) that I can just pass in a date as a parameter - might be useful to the Pandora in general?

I remember having some issues with timezones, but didn't think much of it at the time because I was constantly messing with the dates and such.


You may have to add the "-u" option to the date command indicate it should be in UTC.
Hmmm, surely it should just use the local time - which is what I was setting; but I'll give it a fiddle with the UTC instead when I get home, see if that helps.


Cheers
 
Pmprog, if you manage to get it working let me know. I am also interested...


By the way, I would like to know the following:


- if you use that command to put the Pandora to sleep, does that offset the effect of pressing a key when it is sleeping to wake it up ?


- Is it possible to : 1) run the script through the program to shut down the Pandora for x-hours and 2) keep the possibility to wake the Pandora up at anytime ?
 
The sleep aspect is induced by the op_power.sh - which is the same as flicking the switch for less than two seconds - so yes, you can wake it up normally (don't know if it's by any key, I've never tried, I just flick the power switch again)


I'm assuming the wakealarm bit will only activate if the Pandora is asleep - so if you wake it prematurely, it won't really make any difference.
 
The sleep aspect is induced by the op_power.sh - which is the same as flicking the switch for less than two seconds - so yes, you can wake it up normally (don't know if it's by any key, I've never tried, I just flick the power switch again)

Usually any key will make the pandora wake up, FYI :)
 
Back
Top