2013-08-04

A few weeks ago, while being entranced by a software bug, I failed to keep an eye on the clock and thus I missed a work meeting. Do you know when that tragedy is going to happen again? never. Obviously, I need to set some sort of alarm...

In my minds eye, I had a vision of what I wanted the alarm to do: play an audio file and flash some lights. Fortunately, the software I've been writing could almost do what I wanted to do. almost. A bit of code hacking needed to be done.

For audio playback, MuttonChop media player was installed on the toaster(which has an amplifier and speaker). A Star Trek Alert was selected as the audio to play when the alarm goes off. However, before the alarm would work as I wanted, I needed to add a bit of code to MuttonChop to make a playing file loop over and over. In the MuttonChop API, this resulted in the following new API calls:

  1. HOST:PORT/player/loop
    retrieves the loop state of the player
  2. HOST:PORT/player/loop/true
    set the player loop state to 'true'
  3. HOST:PORT/player/loop/false
    set the player loop state to 'false' (to be fair, anything that is not 'true' will result in 'false')

Rad, that takes care of the audio aspect of the alarm. On to the lights!

GLMR(the GLRM Light Manipulation Regulator) installed on a Raspberry Pi affectionately named "shitbird", will handle the light needs. However, after running some tests I quickly realized that I would need a quick and easy way to revert the lights to their "pre-alarm" state. A bit of code caking later and two new API paths were added to GLMR:

  1. HOST:PORT/color/previous
    set the LEDs to their previous set color
  2. HOST:PORT/mode/previous
    set the LEDs to their previous set mode

Booyah! Now it is simply a matter of creating an alarm for the Ruby Web Alarm project.

enter the shell script

#!/bin/sh
# call the API to play audio file with ID of 1
curl fruity:2876/audio/play/1
# set the looping to 'true'
curl fruity:2876/player/loop/true
#crank up the volume
curl fruity:2876/player/volume/100

#set the glmr mode to 'twinkle'
curl shitbird:4567/mode/twinkle
#set the LEDs to full red
curl shitbird:4567/color/ff0000

...And finally, there needs to be a way to turn off the alarm. To keep shit sweet, I decided to use the 'Cancel' button on the face of the toaster to run a 'cancel alarm' ruby script.

Enter the Ruby

#!/usr/bin/env ruby
require 'json'
require 'open-uri'

#get the status of muttonchop on fruity
url "http://fruity:2876/player/status"
openurl do |f|
  status JSON.parsef.read() )
  #is the machine playing an alert?
  if status['state']=="PLAYING" && status['album']=='Alert'
    #stop the muttonchop player
    open("http://fruity:2876/player/stop")
  end
end

#check the glmr status on shitbird
open("http://shitbird:4567/status"do |f|
  status JSON.parse(f.read() )
  # if the alarm is running
  if status['color']=='ff0000' && status['mode']=='twinkle'
    #revert the color
    open("http://shitbird:4567/color/previous")
    #revert the mode
    open("http://shitbird:4567/mode/previous")
  end
end

Alrighty! The alarm goes on, and the alarm goes off; but what does it look/sound like?

It may not be the greatest alarm ever, but it is highly effective. Now quite reading, and go set an alarm.

Comments
2013-08-05 Alison Chaiken:
Okay, I admit it's cooler than the Pebble watch.
Name:
not required
Email:
not required (will not be displayed)
Website:
not required (will link your name to your site)
Comment:
required
Please do not post HTML code or bbcode unless you want it to show up as code in your post. (or if you are a blog spammer, in which case, you probably aren't reading this anyway).
Prove you are human by solving a math problem! I'm sorry, but due to an increase of blog spam, I've had to implement a CAPTCHA.
Problem:
5 plus 8
Answer:
required
subscribe
 
2016
2015
2014
2013
2012
2011
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008