Notices


Reply
Thread Tools
Posts: 1,100 | Thanked: 2,797 times | Joined on Apr 2011 @ Netherlands
#521
Originally Posted by rotoflex View Post
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 ).
 

The Following User Says Thank You to ade For This Useful Post:
Posts: 569 | Thanked: 462 times | Joined on Jul 2010 @ USA
#522
Originally Posted by ade View Post
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.

(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.
 

The Following 2 Users Say Thank You to rotoflex For This Useful Post:
Posts: 1,100 | Thanked: 2,797 times | Joined on Apr 2011 @ Netherlands
#523
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.
 

The Following 4 Users Say Thank You to ade For This Useful Post:
Posts: 804 | Thanked: 1,598 times | Joined on Feb 2010 @ Gdynia, Poland
#524
Originally Posted by ade View Post
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
 

The Following 2 Users Say Thank You to misiak For This Useful Post:
Posts: 569 | Thanked: 462 times | Joined on Jul 2010 @ USA
#525
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.
 

The Following 2 Users Say Thank You to rotoflex For This Useful Post:
Posts: 1,100 | Thanked: 2,797 times | Joined on Apr 2011 @ Netherlands
#526
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"
 

The Following 2 Users Say Thank You to ade For This Useful Post:
Posts: 569 | Thanked: 462 times | Joined on Jul 2010 @ USA
#527
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
 

The Following 2 Users Say Thank You to rotoflex For This Useful Post:
Posts: 1,163 | Thanked: 1,873 times | Joined on Feb 2011 @ The Netherlands
#528
Originally Posted by shaihkritzer View Post
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/
__________________
N900 loaded with:
CSSU-T (Thumb)
720p recording,
Pierogi, Lanterne, Cooktimer, Frogatto
N9 16GB loaded with:
Kernel-Plus
--
[TCPdump & libpcap | ngrep]
--
donate
 

The Following User Says Thank You to mr_pingu For This Useful Post:
Posts: 2,290 | Thanked: 4,133 times | Joined on Apr 2010 @ UK
#529
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.
__________________

Wiki Admin
sixwheeledbeast's wiki
Testing Squad Subscriber
- mcallerx - tenminutecore - FlopSwap - Qnotted - zzztop - Bander - Fight2048 -


Before posting or starting a thread please try this.
 

The Following User Says Thank You to sixwheeledbeast For This Useful Post:
Posts: 1,100 | Thanked: 2,797 times | Joined on Apr 2011 @ Netherlands
#530
Originally Posted by shaihkritzer View Post
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).
 

The Following 2 Users Say Thank You to ade For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 20:37.