Android and Linux

Monday, September 19, 2011

Camera weather display

I'm sorry I haven't posted much in a while. To tell the truth, I haven't done much worth sharing. My daughter started kindergarten and I think her school is harder for the parents than the kids, and being a single dad makes it all the more tough. The only time I have for myself is a couple hours after she goes to bed and the housework ain't doin' itself during that time.

Oh well, I did come up with something pretty cool that will probably be of no use to anyone unless they have the same gadgets as me. It may inspire someone to do something similar with other gadgets though.

Taking my Foscam and Roku scripts and a Roku app, I made a little automated camera/weather display for my TV.

The Roku app is MyMedia which allows you to play files from your computer on your TV. It's two parts, a simple server for your computer and an app on the Roku. The server shares Music, Photo and Video folders to your local network where the MyMedia app on the Roku can pick them up. There are other Roku apps which do the same thing, but this one fit my needs.

Once that is set up, the ID for that channel is 2542, so using my Roku script, you can use the command roku go 2542 to load that channel. Once it loads, you can use the script again to navigate to different folders using left/right and select commands. You can, of course, do this with the Roku remote control, but it's a lot cooler to automate it.

Let me back up and first post the script then walk through everything that is happening in 4 steps.
#! /bin/sh

cam snap

WX=$(links -dump 'URL' | grep -A 6 'Weather:' | sed -e 's/^[ \t]*//')

convert /sdcard/cam.jpg -fill white -gravity South -pointsize 25 -stroke '#000C' -strokewidth 2 -annotate 0 "$WX" -stroke none -fill white -annotate 0 "$WX" /sdcard/cam.jpg

roku right
roku go 2542; sleep 7
roku str right right select; sleep 1
roku select


Step 1: cam snap
Using the Foscam script, just run cam snap and a jpg will be saved wherever you have the script set up to save it. On my computer, I actually made a /sdcard directory so I could more easily write scripts that would work on both the computer and Android phone, so /sdcard/cam.jpg in this post is on the computer, not the phone.

Step 2: WX=$(links -dump...
Links is a command line Linux browser which can dump the text of a webpage. Lynx is another which is often interchangeable with Links, and both have the same -dump option so either could be used here. This sets the WX variable to the output of the links command. I used the weather conditions from the weather.gov mobile site. Click that, put in your zip code, click go, then click current conditions. Copy the URL of the current conditions page and use it to replace URL in this command in order to grab everything from Weather to Visibility then align the text properly. This is just an example, you could get the weather from anywhere.

Step 3: convert...
"convert" is part of Imagemagick, a powerful command line image manipulation program which is installed on most Linux distributions. In this case, I'm using it to write the weather from the WX variable on the image.

Step 4: roku...
All the Roku commands use my Roku script to navigate to the MyMedia channel and select the image. The first command is used to wake the Roku up in case the screen saver is on, the second selects the channel and waits for it to load, which usually only takes 3-4 seconds, and the rest navigate and select the image. I don't have any other images to display so when I navigate to the Photos folder and click "select", it automatically opens the image I want since it's the only one. If you have other photos, you may want to use a subdirectory and a couple extra commands to navigate to it.

Here is the end result:



I pointed the camera at a wall because the normal view would show part of my neighbor's house, and I would feel awkward about that. It's also dark, it looks much better pointed over my yard with the daytime sky in view. The image itself is mediocre on a computer, but looks great stretched out on a wide screen TV.

So, what use was all this? Well, I have a cron job scheduled to run at the same time my alarm goes off in the morning. It turns on a couple lights that are controlled with X10 automation, sends the weather forecast to my phone, and a couple other odd jobs. I added this to the schedule, so I can roll over, look at the TV and see what it looks like outside as well as the current weather conditions.

I also set up a Tasker task to ssh in to my home computer and run the first three steps, copy the resulting file to my phone, then display it, in case I'm interested in seeing this image and info while I'm away.

While this trick is pretty specific to my setup, maybe it will inspire someone with other gadgets to do something cool with whatever they have.

Followers