dgibbons.net Yet another tech blog
Using Blink1 To Automate Skype Phone Status
Ever have someone come by and start a conversation while you’re on a phonecall?
I recently got a Blink(1) LED from ThingM and wanted to to see if I could use it to notify those around me to my status of a call on skype.
How I implemented it
First I strugged with getting access to the skype objects that everyone was referencing on the internet, it turns out they’re only available within in the 32bit version of powershell.
I then wrapped that in a batch file to make it easier to call.
if ($env:Processor_Architecture -ne "x86")
{
&"$env:windir\syswow64\windowspowershell\v1.0\powershell.exe" -noninteractive -noprofile -ExecutionPolicy Bypass -file $myinvocation.Mycommand.path
exit
}
$skype = New-Object -ComObject Skype4Com.Skype
while($true)
{
Start-Sleep -s 15
if ([string]::IsNullOrEmpty($skype.ActiveCalls)) {
c:\tools\blink1-tool.exe --green -q
} else {
c:\tools\blink1-tool.exe --red -q
}
}
I then saved this someplace easy to access and wrote a small batchfile to call it, although making a shortcut would have probably also worked:
Powershell.exe -File "C:\Users\dgibbons\Downloads\skype.ps1" -executionpolicy bypass
Results
What this does is sit in the background and every 15 seconds, checks the status of $skype.ActiveCalls, if it’s not empty, it sets the blink1 LED red, otherwise it sets it green. This just can live and run in the background and keeps my skype status visible to my officemates around me. I checked the performance from the Task Manager and while it does put a tiny bit of load on the system, it’s like 1% or so.
Getting Started With Swarm And Docker Machine On Aws
set some shell variables
$ export AWS_ACCESS_KEY_ID=YOUR_ACCESS_KEY_HERE
$ export AWS_SECRET_ACCESS_KEY=YOUR_SECRET_KEY_HERE
$ export AWS_DEFAULT_REGION=us-west-2
Use a local docker container to generate a swarm token
$ docker run swarm create
This will return a hash as the output e.g.:
fe0cc96a72cf04dba8c1c4aa79536ec3
Set this as a shell env var:
$ export SWARM_TOKEN=fe0cc...
Launch the swarm manager in AWS:
$ docker-machine create \
-d amazonec2 \
--swarm \
--swarm-master \
--swarm-discovery token://$SWARM_TOKEN \
swarm-master
Launch a few nodes:
$ docker-machine create \
-d amazonec2 \
--swarm \
--swarm-discovery token://$SWARM_TOKEN \
swarm-agent-01
$ docker-machine create \
-d amazonec2 \
--swarm \
--swarm-discovery token://$SWARM_TOKEN \
swarm-agent-00
Change the active docker server to the swarm manager:
$ eval $(docker-machine env swarm-manager)
Look at the swarm:
$ docker info
run a docker container on the swarm:
$ docker run hello-world
A further test, I started up a minecraft server:
$ docker run -e EULA=TRUE -d -p 25565:25565 itzg/minecraft-server
4baa76223f7c4b8a99aa7fe9201a4cfeb03e2a870fda70c213e7c356d4c82a7f
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4baa76223f7c itzg/minecraft-server "/start" 6 seconds ago Up 6 seconds 52.26.250.197:25565->25565/tcp swarm-agent-01/backstabbing_fermi
This was basically following the guide on: http://docs.docker.com/swarm/install-w-machine/
also using this blog post: http://networkstatic.net/docker-machine-provisioning-on-aws/
Running A Raspberry Pi Twitter Display
Building a Raspberry Pi based Twitter Display
History
One of the first projects I found when I first started playing around with the raspberry pi was a two way Portal mirror. This used a simple display + camera to show a remote location of another “paired” device. This got me thinking about other small frame-based uses for a micro-computer. I realized that there were a few projects for turning a raspberry pi into a picture frame, and I wanted to do something similiar.
Research
The first challenge I had was exploring solutions for displaying text cleanly at potentially low resolution on a raspberry pi. I had previously explored running an X session and chrome browser for a dashboard I built for work. This had some flaws, specifically the results often ran out of memory, it took a lot of heavy processes and a window manager for what really didn’t require it. I started to explore instead ways to use the framebuffer without a lot of heavy graphics work. From there I found the Pygame library and some tutorials that showed easy usage of the framebuffer for displaying text. Perfect!
Design
Graphics
The end result is a gutted Pygame class that instantiates a empty rectagle based on the framebuffer size. We then grab some text to render, word wrap it as appropriate and display on the screen.
Network
I ended up wanting to make the program show it’s ip address on startup so we could address the device if there was any problms. At first I wrote a function that would grab specifically the ip address of eth0. When I expanded the device to use a wifi adapter this solution fell apart. I found another solution that instead tells the code to use the networking stack to connect to a public address and then grabs the local results of that socket connection. This appears to more dynamically grab the RIGHT adapter.
I explored the python-twitter module. This was really straight forward to do searches and parse the results. There are so many options for twitter libraries, I can’t say this one is the best but it worked well for my needs. I think when this fails is where my code is missing the most exception handling. If I look up a twitter user and it doesn’t exist, I’m not catching and handling that situation yet.
Results
The end result is this small display that sits on my desk, every 30 seconds it displays a new ‘tweet’, altering the color and source from a yaml list thats pulled in on load. I’ve attempted to have it often re-read the yaml file but I don’t know that it’s working. Auto-reloading the configuration file seemed like a easy way to allow dynamic updates. I also considered polling from a twitter account, but that doesn’t work for topics only for users to follow. I could possibly change it to search for the results of a tweet as if it was a topic, and the users followed by an account for users to follow, although removing topics would not be straightforward. Dynamic configuration data seems to be the biggest challenge with the display. I also considered setting up a small torando server that you could post an api request to for configuration changes. But I don’t think thats actually easier than the current method where I can do a git pull.