Simple Kindle Temperature Display 
Thursday, February 7, 2013, 15:41
Posted by Administrator
I've been wanting to make an e-paper temperature display ever since seeing the beautiful weather forecast display that Matthew Petroff put together but as is my style I wanted to do something much simpler and easier to get running. My main self imposed requirement was to make something that would work on an unrooted device. With my kindle touch laying around mostly unused the last few weeks I finally got determined to put it to some better use around the apartment.

I started off with my old weather grabbing script to pull the current temperature information from Wunderground. Wunderground claims to be phasing out their API that I like, but it shouldn't be difficult to scrape another site once they finally can it. I cut out a lot of the extra information I had been grabbing before since I wanted to dedicate this display to just temperature information.

The revised bash script follows below:

#!/bin/bash
# Temperature Grabbing Bash Script From Wunderground
# Created by Spike Snell 2013

# Make sure there is an argument which could have a zip
if [ $# -lt 1 ] ; then
echo "Please include a zipcode as an argument such as: ./weather.sh 72703"
exit 1
fi

# Grab the Zipcode from the command line argument
zip=$1

url="http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=$zip"

# Grab the content from the Wunderground API
weather_wget=`wget -q $url -O -`
weather_xml=`echo "$weather_wget" | sed 's/<current_observation>.*//'`
weather=`echo "$weather_xml" | sed 's/></>\n</g'`

# Get the temperature in C
temp=`echo "$weather" | grep -e '<temp_c>' | \
sed -e 's/\t\t<temp_c>//' -e 's/<\/temp_c>//'`

# Print out all the information
echo $temp

# Write it to a gif
echo $temp | convert -pointsize 555 text:- n.gif


The biggest change in the code from the old one is that I'm now using imagemagick to do a convert on the temperature text into a gif file. This is because I found that the kindle's experimental web browser was very iffy about displaying very large fonts, it would work about 1/10th of the time. It was able to display a large picture great though.

This whole project was made much simpler than Matthew's by driving the process with the kindle's built in web browser. I have a server running a lamp stack that I like to use and put the previous shell script and the following php code up on.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="refresh" content="360" charset=UTF-8">
<META NAME="DESCRIPTION" CONTENT="A small temperature indicator to run as an art piece displaying degrees C.">
<META NAME="KEYWORDS" CONTENT="temperature,art,large,tool">
<title>Current Local Temperature Indicator</title>
</head>
<body bgcolor="#FFFFFF">
<h1>
<?php
$z = 72703;
if (isset($_GET['z'])) {
$z = $_GET['z'];
};
$t = `./t.sh $z`;
# convert to F
$f = $t*9/5+32;
echo $f;
?>
</h1>
<img src="n.gif">
</body>
</html>


All that was left to do was to point the kindle's browser towards the php file, this triggers the bash script, writes the image and does a simple conversion of C -> F degrees to display above the large C readout. Voila! A temperature readout, self updating every 6 minutes with a meta refresh. So now everything is finished, except the kindle has one last gotcha, it blanks the screen and displays a screensaver after about a 15 minute inactivity period. Luckily this can be easily disabled. At the home screen of the kindle you can enter "~ds". This will disable the screensaver until the device is restarted.

Now some glamour shots of the kindle temperature display in operation, along with a closeup of my tacky wall-mounting job.

Image Removed


Image Removed
add comment ( 3091 views )   |  permalink   |  $star_image$star_image$star_image$star_image$star_image ( 3 / 3067 )
Ascii Snow and Rain 
Wednesday, December 26, 2012, 15:39
Posted by Administrator
My favorite twitter feed at the moment is climagic. He posts an assortment of great little scripts and other cli tips and tweaks at least a few times a week. One of the neatest things things he posted in a long while is his bash ascii snow simulator.

The code for it is below:

c=$(tput cols);clear;while :;do echo $(tput lines) $c $(($RANDOM%$c));sleep 0.1;done|gawk '{a[$3]=0;for(x in a){o=a[x];a[x]=a[x]+1;printf"\033[%s;%sH ",o,x;printf"\033[%s;%sH*\033[0;0H",a[x],x;}}'


I've modified it a very little bit and made a rainy windsheild simulator as well:

c=$(tput cols);clear;while :;do echo $(tput lines) $c $(($RANDOM%$c));sleep 0.1;done|gawk '{a[$3]=0;for(x in a){o=a[x];a[x]=a[x+1]+1;printf"\033[%s;%sH ",o,x;printf"\033[%s;%sH.\033[0;0H",a[x],x;}}'


The most interesting part of these to me is how few characters it takes to generate something so visually interesting. These scripts can be shortened a bit if you are running them from the command line by removing the c variable for columns, but when running from a script this variable isn't passed so I've left it in.

Particularly fun has been running the snow simulator on an old-style television with a Raspberry Pi with the font size way way up.
add comment ( 16032 views )   |  permalink   |  $star_image$star_image$star_image$star_image$star_image ( 3 / 2624 )
Improved Strobe 
Monday, July 2, 2012, 14:33
Posted by Administrator
It has been much too long since I made an entry here! I keep meaning to post but had been very busy with classes and graduating and now working full time but things are finally starting to settle down into a nice routine and I'm able to find time on the weekends and at nights lately.

I've made some additions to that strobelight Javascript that I put together quite a while back. By adding some nice cross browser event handling code provided by the nice folks over at OpenJs I was able to easily add key commands to control the flash rate and colours used by the strobe as well as throbbing effect.

The left and right arrow keys decrease and increase the flash rate respectively, and the up and down arrows switch out the first and second flash colour. For the black and white throb hit the Ctrl key, and to turn it off press Alt.

I'd eventually like to add the throb to work with any of the other colour settings but this is going to take some more thought. I don't want to define separate arrays for all of the combinations, but how to manage to increment the saturation of a RGB hex code in a generic way is eluding me currently. Perhaps I could mask the value somehow after shifting off the pound sign so that I just hit the right values.

Or another possible feature I see would be to have it just generate a random similar shade in an incremental pseudo-random path.

Here is the current page code I have developed:

<html>
<head>
<title>strobe - arrow keys change settings + ctrl + alt</title>
<script type="text/javascript" src="shortcut.js"></script>
<script>

var colors = new Array("#000000","#FFFFFF","#FF0000","#FFFF00","#FF00FF","00FFFF","#0000FF","00FF00");
var bwthrob = new Array("#000000","#111111","#222222","#333333","#444444","555555","#666666","777777","#888888","#999999","#AAAAAA","#BBBBBB","#CCCCCC","#DDDDDD","#EEEEEE","#FFFFFF","#EEEEEE","#DDDDDD","#CCCCCC","#BBBBBB","#AAAAAA","#999999","#888888","#777777","#666666","#555555","#444444","#333333","#222222","#111111");

var c1 = "0";
var c2 = "1";
var speed = "80.00";
var i = 0;

shortcut.add("Ctrl", function() {
i = 1;
});

shortcut.add("Alt", function() {
i = 0;
});

shortcut.add("Up", function() {
c1 = (c1 + 1) % colors.length;
});

shortcut.add("Down", function() {
c2 = (c2 + 1) % colors.length;
});

shortcut.add("Left", function() {
speed = speed + 10;
});

shortcut.add("Right", function() {
speed = speed - 10;
});

function strobe() {

if ( i == 0 ) {
document.bgColor = document.bgColor == colors[c2] ? colors[c1] : colors[c2];
}

else {
document.bgColor = bwthrob[i%bwthrob.length];
i++;
}

setTimeout('strobe()', speed);

}
</script>

</head>
<body onload='strobe();'>
</body>
</html>


You play with the strobe through the link below. Enjoy :D.

--> The Strobe <--

add comment ( 16493 views )   |  permalink   |  $star_image$star_image$star_image$star_image$star_image ( 3 / 2989 )

<<First <Back | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Next> Last>>