maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting) (https://talk.maemo.org/showthread.php?t=46594)

ade 2012-09-25 14:19

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Quote:

Originally Posted by rotoflex (Post 1271805)
I call a shell script from alarmed to create an internet clock radio.

The first part of the script sets a "safety alarm" - it sets a one time only N900 alarm for 30 minutes from the present time, in case the internet radio station is not broadcasting, or the wireless connection has failed, or whatever.

The N900 alarm is set through alarmed's CLI:
Code:

#use alarmed CLI to set a safety alarm in 30 minutes
/opt/alarmed/alarmed.py -C --title='Clockradio Safety Alarm' -A --date='now +30 minutes'

That does set a one-time only N900 alarm, but unlike setting a one-time-only alarm through the N900's alarm screen, it leaves the entry in the alarmd event list, so that I occasionally must open alarmed & delete the old "safety alarm"s from each time the script was called.

Can anyone suggest a better command for creating a one-time-only alarm, one which will not leave an entry in the alarmd list after it is done?

Side question: is it not more simple to just set a repeating alarm in the alarm clock for this (I don't know if date 'now+30' is always set on a fixed time, but it looks like you do)?

Alarms in Alarmed can be deleted with "-D 'ID'". Not sure if you can create events specifing an ID. If not, you could search the specific ID's according to characteristics and then delete them (would be a simple scripts that can be scheduled in... alarmed :)).

rotoflex 2012-09-25 21:26

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Quote:

Originally Posted by ade (Post 1272032)
Side question: is it not more simple to just set a repeating alarm in the alarm clock for this

I sleep at different times, so I needed to create an internet radio alarm that I could easily switch times (nicely done in alarmed), but it needed the safety alarm coupled to the radio alarm time so I wouldn't need to set *two* alarms each time: 1 for the radio, 1 for the safety.

I created a bunch of alarmed items with different radio stations, & as I wish just activate and/or change the time for them as needed.

Quote:

(I don't know if date 'now+30' is always set on a fixed time, but it looks like you do)?
'now + ...' is really clever & convenient. It's dynamic & sets an alarm for ... after the time you create the alarm. It works well for coupling two alarms, so that you only need to set 1.

Directions toward the 'now +' feature & syntax are in the notes on the first page for ver. 0.1.8-1

Here's the chunky shell script if anyone wants to play with it. It takes 3 command line arguments:
-The stream's URL
-How many seconds to remain mute after connecting (in case they always play a commercial on connection)
-The % (0-100) volume to set the speaker at when it plays. Some internet stations are louder than others.

Code:

#!/bin/sh

# clockradio.sh -- a clock radio script using command line arguments  #
# argument 1 ($1): internet radio station url
# argument 2 ($2): pause (unmute delay, for skipping an initial commercial)
# argument 3 ($3): volume for speakers

# can use the N900 Media Player, but checks first for KMPlayer for most reliable connectivity
PLAYER=NoPlayer

# Check to see if there is at least 1 command line argument, for the internet radio station URL
if [ ! $# == 3 ]; then
  echo "3 command line arguments needed."
  echo "Usage: clockradio.sh URL pause(in seconds) volume(1-100)"
  exit
fi

if [ $2 -lt 0 ]; then
  echo "Pause must be 0 or greater; $2 entered"
  echo "Usage: clockradio.sh URL pause(in seconds) volume(1-100)"
  exit
fi

if [ $3 -lt 0 -o $3 -gt 100 ]; then
  echo "Volume level must be between 0 & 100; $2 entered"
  echo "Usage: clockradio.sh URL pause(in seconds) volume(1-100)"
  exit
fi

# Check to see if KMPlayer is installed
if [ -e "/opt/kmplayer/bin/kmplayer" ] ; then 
    PLAYER="/opt/kmplayer/bin/kmplayer"
else
        echo "KMPlayer not found, using N900 Media Player"
        PLAYER="N900 Media Player"
fi

echo "Connecting $PLAYER to $1, remaining muted for $2 seconds, then increasing volume to $3 %."
echo "A standard alarm will be set for 30 minutes from now in case of internet radio station absence."

#use alarmed CLI to set a safety alarm in 30 minutes
/opt/alarmed/alarmed.py -C --title='Clockradio Safety Alarm' -A --date='now +30 minutes'

# set volume level to 0%
dbus-send --type=method_call --dest=com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer /com/nokia/mafw/renderer/gstrenderer com.nokia.mafw.extension.set_extension_property string:volume variant:uint32:0

if [ $PLAYER == "/opt/kmplayer/bin/kmplayer" ] ; then
        #assemble the command line to play the URL with KMPlayer
        PLAYER=$PLAYER" "$1
        # background process connect KMPlayer to station url
        ($PLAYER)&
else
        # call the N900 media player
        dbus-send --print-reply --dest=com.nokia.mediaplayer /com/nokia/mediaplayer com.nokia.mediaplayer.mime_open string:$1 > /dev/null
fi

#sleep specified seconds before unmuting to miss the at-connect commercial if there is one
sleep $2

# over 60 seconds, increase the volume to level specified (0 - 100%)
SLEEPLEN=$((60/$3))
for i in $(seq 0 $3); do
sleep $SLEEPLEN
        dbus-send --type=method_call --dest=com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer /com/nokia/mafw/renderer/gstrenderer com.nokia.mafw.extension.set_extension_property string:volume variant:uint32:$i
done

As mentioned, the drawback is that it litters alarmed with old, inactive safety alarms that every now & then you must go in & delete.

ade 2012-09-25 21:50

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Just something I created in a few minutes:

Replace the alarm creation line with:
Code:

/opt/alarmed/alarmed.py -C --title='Clockradio Safety Alarm' -A --date='now +30 minutes'|awk '{print $NF}' >> /tmp/clockalarms_ids.txt
This will collect all your ID's

Now when this alarms can all be removed start this script:
Code:

#!/bin/sh
for ID in $(cat /tmp/clockalarms_ids.txt)
do
        /opt/alarmed/alarmed.py -C -D $ID
done
rm -f /tmp/clockalarms_ids.txt

Now your specific alarms are removed and the id-list is gone.

misiak 2012-09-26 06:28

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Quote:

Originally Posted by ade (Post 1272238)
Just something I created in a few minutes:

Replace the alarm creation line with:
Code:

/opt/alarmed/alarmed.py -C --title='Clockradio Safety Alarm' -A --date='now +30 minutes'|awk '{print $NF}' >> /tmp/clockalarms_ids.txt
This will collect all your ID's

Now when this alarms can all be removed start this script:
Code:

#!/bin/sh
for ID in $(cat /tmp/clockalarms_ids.txt)
do
        /opt/alarmed/alarmed.py -C -D $ID
done
rm -f /tmp/clockalarms_ids.txt

Now your specific alarms are removed and the id-list is gone.

Maybe it'd be a better idea to replace /tmp/clockalarms_ids.txt with /home/user/clockalarms_ids.txt, as after reboot file in /tmp would be lost;)

rotoflex 2012-09-26 16:58

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Thank you, ade & misiak. It is a nicely-behaved & self-contained little routine now. If anyone else would like to use it for an internet alarm clock, here's the final version.
Code:

#!/bin/sh

# clockradio.sh -- a clock radio script using command line arguments  #
# argument 1 ($1): internet radio station url
# argument 2 ($2): pause (unmute delay, for skipping an initial commercial)
# argument 3 ($3): volume for speakers

# can use the N900 Media Player, but checks first for KMPlayer for most reliable connectivity
PLAYER=NoPlayer

# Check to see if there is at least 1 command line argument, for the internet radio station URL
if [ ! $# == 3 ]; then
  echo "3 command line arguments needed."
  echo "Usage: clockradio.sh URL pause(in seconds) volume(1-100)"
  exit
fi

if [ $2 -lt 0 ]; then
  echo "Pause must be 0 or greater; $2 entered"
  echo "Usage: clockradio.sh URL pause(in seconds) volume(1-100)"
  exit
fi

if [ $3 -lt 0 -o $3 -gt 100 ]; then
  echo "Volume level must be between 0 & 100; $2 entered"
  echo "Usage: clockradio.sh URL pause(in seconds) volume(1-100)"
  exit
fi

# Check to see if KMPlayer is installed
if [ -e "/opt/kmplayer/bin/kmplayer" ] ; then 
    PLAYER="/opt/kmplayer/bin/kmplayer"
else
        echo "KMPlayer not found, using N900 Media Player"
        PLAYER="N900 Media Player"
fi

echo "Connecting $PLAYER to $1, remaining muted for $2 seconds, then increasing volume to $3 %."
echo "A standard alarm will be set for 30 minutes from now in case of internet radio station absence."

#revised safety alarm creation for old alarm deletion, keeps a list of ID's of the safety alarms
#remove old safety alarm entries
for ID in $(cat /home/user/clockalarms_ids.txt)
do
        /opt/alarmed/alarmed.py -C -D $ID
done
rm -f /home/user/clockalarms_ids.txt
#use alarmed CLI to set a safety alarm in 30 minutes
/opt/alarmed/alarmed.py -C --title='Clockradio Safety Alarm' -A --date='now +30 minutes'|awk '{print $NF}' >>  /home/user/clockalarms_ids.txt

# set volume level to 0%
dbus-send --type=method_call --dest=com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer /com/nokia/mafw/renderer/gstrenderer com.nokia.mafw.extension.set_extension_property string:volume variant:uint32:0

#call the player & connect it to the URL specified
if [ $PLAYER == "/opt/kmplayer/bin/kmplayer" ] ; then
        #assemble the command line to play the URL with KMPlayer
        PLAYER=$PLAYER" "$1
        # background process connect KMPlayer to station url
        ($PLAYER)&
else
        # call the N900 media player
        dbus-send --print-reply --dest=com.nokia.mediaplayer /com/nokia/mediaplayer com.nokia.mediaplayer.mime_open string:$1 > /dev/null
fi

#sleep specified seconds before unmuting to miss the at-connect commercial if there is one
sleep $2

# over 60 seconds, increase the volume to level specified (0 - 100%)
SLEEPLEN=$((60/$3))
for i in $(seq 0 $3); do
sleep $SLEEPLEN
        dbus-send --type=method_call --dest=com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer /com/nokia/mafw/renderer/gstrenderer com.nokia.mafw.extension.set_extension_property string:volume variant:uint32:$i
done

The only configurability issue it has that someone else might want to change is the length of the delay before the safety alarm, now hard-coded at 30 minutes. I monkeyed with that for hours trying to set it with a command line argument, but never could assemble the 'now +30 minutes' string that must be passed to alarmed correctly. I think for some reason, there was always an additional escaped ' character of unknown origin that kept appearing. I am not really experienced or familiar with shell scripting.

ade 2012-09-26 17:48

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
If you want to configure minutes from now:
Alarmed also accepts double quotes. So the most easy solution is to use double quotes instead of single ones, so variables get expanded.

As indication:
Code:

MINUTES=40

/opt/alarmed/alarmed.py -C --title="Clockradio Safety Alarm" -A --date="now +${MINUTES} minutes"


rotoflex 2012-09-27 01:30

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Thanks, ade. I might never have gotten the syntax right!
Here's the final version, if anyone would like it.
Code:

#!/bin/sh

# clockradio.sh -- a clock radio script using command line arguments  #
# argument 1 ($1): internet radio station url
# argument 2 ($2): pause, seconds (unmute delay, for skipping an initial commercial)
# argument 3 ($3): volume for speakers, 0 to 100
# argument 4 ($4): minutes to delay N900 safety alarm
MINARGS=1
MAXARGS=4

# can use the N900 Media Player, but checks first for KMPlayer for most reliable connectivity
# default player assignment, for error message maybe
PLAYER=NoPlayer
# default unmute delay assignment
UNMUTEDELAY=0
# default speaker volume
SPEAKERVOL=50
# default minutes to assign to safety alarm
SAFETYDELAY=15

# Check to see if there are 1 or 4 command line arguments.
# At least one is needed, to specify the internet radio station URL.
# Otherwise, all 4 arguments must be specified
if [ $# -ne $MINARGS ] && [ $# -ne $MAXARGS ]; then
  echo "Command line arguments incorrect."
  echo "Usage: clockradio.sh StationURL"
  echo "or"
  echo "Usage: clockradio.sh StationURL Pause(in seconds) Volume(1-100) 2ndAlarmDelay(in minutes)"
  exit
fi

# substitue the variables if the command line arguments have been initialized
if [ $# == 4 ]; then
        # set the unmute delay
        if [ $2 -lt 0 ]; then
          echo "Pause before increasing volume must be 0 or greater; $2 entered"
            echo "Usage: clockradio.sh URL pause(in seconds) volume(1-100)"
          -exit
        else
          UNMUTEDELAY=$2
        fi

        # set the volume level
        if [ $3 -gt 100 ]; then
          echo "Volume level must be between 0 & 100; $2 entered"
          echo "Usage: clockradio.sh URL pause(in seconds) volume(1-100)"
          exit
        else
          SPEAKERVOL=$3
        fi

        # set the delay for the safety alarm
        SAFETYDELAY=$4
fi

# Check to see if KMPlayer is installed
if [ -e "/opt/kmplayer/bin/kmplayer" ] ; then 
    PLAYER="/opt/kmplayer/bin/kmplayer"
else
        echo "KMPlayer not found, using N900 Media Player"
        PLAYER="N900 Media Player"
fi

echo "Connecting $PLAYER to $1, remaining muted for $UNMUTEDELAY seconds, then increasing volume to $SPEAKERVOL%."

# If the safety delay argument is less than 0, no safety alarm will be set
if [ $SAFETYDELAY -ge 0 ]; then
  echo "A standard alarm will be set for $SAFETYDELAY minutes from now in case of internet radio station absence."
else
  echo "No safety alarm following the player start will be set."
fi

#revised safety alarm creation for old alarm deletion, keeps a list of ID's of the safety alarms
#remove old safety alarm entries
for ID in $(cat /home/user/clockalarms_ids.txt)
do
        /opt/alarmed/alarmed.py -C -D $ID
done
rm -f /home/user/clockalarms_ids.txt
#use alarmed CLI to set a safety alarm in 30 minutes
#if SAFETYDELAY is a negative number, set no safety alarm
if [ $SAFETYDELAY -ge 0 ]; then
        #use alarmed CLI to set a safety alarm in 30 minutes
        /opt/alarmed/alarmed.py -C --title="Clockradio Safety Alarm" -A --date="now +${SAFETYDELAY} minutes"|awk '{print $NF}' >>  /home/user/clockalarms_ids.txt
fi

# set volume level to 0%
dbus-send --type=method_call --dest=com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer /com/nokia/mafw/renderer/gstrenderer com.nokia.mafw.extension.set_extension_property string:volume variant:uint32:0

#call the player & connect it to the URL specified
if [ $PLAYER == "/opt/kmplayer/bin/kmplayer" ] ; then
        #assemble the command line to play the URL with KMPlayer
        PLAYER=$PLAYER" "$1
        # background process connect KMPlayer to station url
        ($PLAYER)&
else
        # call the N900 media player
        dbus-send --print-reply --dest=com.nokia.mediaplayer /com/nokia/mediaplayer com.nokia.mediaplayer.mime_open string:$1 > /dev/null
fi

#sleep specified seconds before unmuting to miss the at-connect commercial if there is one
sleep $UNMUTEDELAY

# over 60 seconds, increase the volume to level specified (0 - 100%)
SLEEPLEN=$((60/$SPEAKERVOL))
for i in $(seq 0 $SPEAKERVOL); do
sleep $SLEEPLEN
        dbus-send --type=method_call --dest=com.nokia.mafw.renderer.Mafw-Gst-Renderer-Plugin.gstrenderer /com/nokia/mafw/renderer/gstrenderer com.nokia.mafw.extension.set_extension_property string:volume variant:uint32:$i
done

It's basically an internet clock radio back end to be scheduled in alarmed.

I touched it up so that it could be called with just one argument, the stream URL, & default to no delay, 50% speaker volume, & a regular N900 alarm 15 minutes later in case of internet radio station silence.
Either
clockradio.sh StationURL
or
clockradio.sh StationURL Pause(in seconds) Volume(1-100) N900AlarmDelay(in minutes)"

example:
Code:

clockradio.sh http://109.123.116.202:8010
or
clockradio.sh http://109.123.116.202:8010 0 55 30


mr_pingu 2013-02-09 22:57

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Quote:

Originally Posted by shaihkritzer (Post 1322079)
found some profile changing config files at /home/user/.config/alarmed/jobs

seems like the ones which still work.

but the time format is strange, like "I1278532860" or "I1278475140"

how do I convert these units to hh:mm time and back?


or it would be easier to delete these configs and create new profile change schedule with Silencer/timed silencer app?

Will this help: http://www.epochconverter.com/

sixwheeledbeast 2013-02-10 10:58

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Anybody looking for an alarmclock in alarmd without writing a script.
I did a walkthough here...
http://talk.maemo.org/showpost.php?p...7&postcount=10

@shaihkritzer
This is posix/unix time as above, safer to edit the time in the GUI IMO.

ade 2013-02-21 22:06

Re: [Announce] "Alarmed" scheduling App (supports automatic GPRS data counter resetting)
 
Quote:

Originally Posted by shaihkritzer (Post 1324199)
is there a way to delete profile changer without GUI?

deleted the /home/user/.config/alarmed/jobs catalog (namely, moved it to other location), but profile changer still works.

These jobs are just the alarmed administration. The real alarm scheduling resides in the alarmd framework (see /var/cache/alarmd/alarm_queue.ini).

As I mentioned a few post ago,
Code:

/opt/alarmed/alarmed.py -C -D <your_job-nr>
should remove your it without GUI (first put your alarmed job files back).


All times are GMT. The time now is 05:42.

vBulletin® Version 3.8.8