So I've been working on and off trying to get the Kindle weather display to work properly between a web server and the Kindle. This morning at around 12:15 am I finally got everything working properly.

How It Works
On the web server a shell script (weather-script.sh) runs at certain intervals (via a cronjob) and triggers the following:
  • step 1: python script on web server pulls latest weather data from NOAA
  • step 2: python script replaces placeholder tags on the preprocess.svg with data from NOAA and saves it as weather-script-output.svg
  • step 3: shell script converts the new svg file to a png file (the Kindle can only read png files, not svg)
  • step 4: shell script compresses the png file to make it a smaller file size
Then on the Kindle with the display file (weather-display.sh) running:

  • step 5: Kindle looks at the web server. If the png file is available, display it.
  • step 6: update the display by replacing the png file at intervals defined on Kindle (via cron)

The whole thing has been a fantastic exercise. While I didn't create the graphics or write the python script (I can't code in python, but I'm certainly teaching myself because it looks fascinating), I've learned enough along the way to know how to tweak things and see a potential for changes and future projects.

In fact, the first thing was to add a date. The Kindle Weather Display as created by Matthew Petroff doesn't include a date. If you trust everything you're doing and you're looking for the cleanest possible display, there'd be no reason to clutter it with a date.

I don't trust me and I wanted a date.
Chris helped me work out placement with the date since he has more experience working with SVG files. We added a small line (called DATE_VALPLACE) in the weather-script-preprocess.svg file. This creates a place holder for date and time.
The whole thing is only 12 pixels high so it's very small, as you can see.

To accommodate the space for the date, we did shrink down the size of the high and low temperature displays on the bottom row (to 48px from 58) and move them up slightly (about 10 points on the y axis).

After that just a few lines had to be added to the python script to actually calculate the date and time.
Now we have a weather display that shows the date and time of the last update.

If this is something you're interested in setting up, I'd recommend reading the original Kindle Weather Display blogpost and downloading the files Matthew Petroff has available.
Because I didn't already have a web server running I used this as an exercise to learn more about both Linux web servers and general Kindle hacking. I've listed the steps I took below. Here are the modified files on github or if, if you prefer, dropbox. These are what I'm using to run the display with date and time on my Raspberry Pi server.

Before Beginning You Must Have
  1. A Kindle (examples below are for Kindle 4 with software version 4.1.0)
  2. Jailbreak
  3. Ability to SSH into the Kindle (this is how I set up USBNetworking)
  4. Access to a Linux server (this may work on OS X or Windows with some modifications to the shell scripts)

I'd also recommend knowledge working in the linux command line and working with vi editor.


Installing Kite on Kindle 4
Kite is an application launcher that allows you to launch apps from the Kindle home screen. This is what will be used to launch the weather display on the Kindle.

NOTE: once this is running, you cannot exit it. The Kindle will need to be rebooted to get back into the menu. To reboot the kindle hold the power button for 20 seconds. 
  1. Grab Kite  
    • There have been posts about people unable to install from the update .bin file on the Kindle 4 so I used "installation of kite as script" which was the kite.gz download.
  2. Plug the Kindle into your PC and drop kite.gz onto the Kindle
  3. unmount and SSH into the Kindle
  4. mount the Kindle file system 
    • type: mntroot rw
  5. move into /mnt/us 
    • type: cd /mnt/us
  6. Unzip the kite.gz file
    • type:
      • gzip -d kite.gz
      • sh kite
  7. Kite should now be installed. When you restart your kindle you will see a kite pdf (delete me). Simply delete the file.
  8. Next is to add files to the kite folder. Plug the Kindle into your PC and create a folder called kite (you may need to move a file called kite into another folder first)
  9. Create a folder called ondrop within the kite folder.
  10. Drop the relevant files into kite/ondrop
  11. Reboot kindle, select "Kite" from the menu to launch the file in the kite/ondrop folder
Setting the Clock on the Kindle
If you have not registered the Kindle with Amazon, it will probably not be displaying the correct date. Ensuring that the clock is right (or that you are at least aware of the time on the Kindle) is crucial to scheduling cron jobs. Here’s how to change the time on the Kindle if you haven’t registered it with Amazon and downloaded the correct time. This is taken from this blogpost.
  1. SSH into the Kindle
    • type: date MMDDHHMMYYYY
      • example: date 112316102012 (this will set the Kindle to November 23 2012, 4:10pm
  2. Permanently store the time on the Kindle
    • type: hwclock -w
Editing cron on the Kindle
The Kindle does not allow for custom jobs to be created as is typically done in linux. The file system needed is temporary and removed after a reboot. All cron scheduling MUST be done in the root cron file under: /etc/crontab/root

If you're unfamiliar with cron, I recommend starting with here first.
  • SSH into Kindle and mount the file system
    • type: mntroot rw
  • Edit CRON file in vi (http://en.wikipedia.org/wiki/Vi) 
    • type: vi /etc/crontab/root
  • A list of jobs in the root cron file should appear 
*/60 * * * * /usr/sbin/loginfo tmpfs
*/60 * * * * /usr/sbin/loginfo localVars
*/60 * * * * /usr/sbin/loginfo memusedump
*/15 * * * * /usr/sbin/loginfo powerdcheck
*/5  * * * * /mnt/us/weather/display-weather.sh

Your cron file will look like the above, minus the line highlighted in yellow. Simply add a line to run your script as often as you would like. In this example the display-weather.sh file is scheduled to run every 5 minutes. I used this interval for testing purposes to ensure the server and kindle were working properly and updating.

NOTE: I DO NOT RECOMMENDED SETTING THIS TO A LOWER INTERVAL FOR TESTING PURPOSES. As soon as you restart cron (either rebooting the Kindle or from the command line) The display launches at the designated time. If you set this too low (for example 1 or 2 minutes) and reboot the kindle, you will be unable to access the cron and adjust the time. This is because a reboot causes you to lose access to SSH (requiring the ;debug command to be re-entered). If the script is set to run every minute or 2 minutes, that is likely not enough time for you to enter the command, SSH into the device, and edit cron.  

Now, my web server is set to pull the weather every 2 hours so I set the cron on the Kindle to update ever 2 hours at the 5 minute mark. That means the Kindle will now look for an update at 2:05, 4:05, 6:05, etc. That is a full 5 minutes after the server has pulled the weather and processed the data.

Here is the line I added: 

5  */2 * * * /mnt/us/weather/display-weather.sh
  • reboot cron 
    • type: /etc/init.d/cron restart
    • cron restart will look like this:
      • system: I cron:def:stopping crond
      • system: I cron:def:starting crond
  • the script will now run at the designated time. You can launch it manually from Kite on the home screen or wait for the interval to pass in cron and it will launch it automatically.
Notes For Setting Up Your Linux Web Server
  • You must have Python installed (version 2.7.3 will work. I have not tested the script in Python3).
  • You will need rsvg-convert or imagemagick to convert the SVG file to PNG (the Kindle cannot read SVG files).
  • You need pngcrush installed to compress the PNG file. If you use the file as provided on the Kindle Weather Display website, you will need version 1.7.22. Pngcrush should be available in your distro repository. 
NOTE: Ubuntu doesn't support the latest version and I couldn't get it to install properly from the command line so I used pngcrush 1.7.0 and modified the shell script to get the properly formatted file. Here is how I modified it:  

#!/bin/sh 
cd "$(dirname "$0")" 
python2 weather-script.py

rsvg-convert --background-color=white -o weather-script-output-new.png weather-script-output.svgpngcrush -c 0 -nofilecheck weather-script-output-new.png weather-script-output.pngcp -f weather-script-output.png /path/to/web/server/directory/weather-script-output-new.png


Raspberry Pi Special Note: 
If you're setting this up on a Raspberry Pi running Raspbian, as I have, there are a few extra notes to be aware of.
  • Used imagemagick instead of rsvg-convert (I could not find the library for rsvg-convert available on Raspbian)
  • Had to use pngcrush version 1.7.9
  • Had to ensure full paths are included in the custom cronjob because it wouldn't run the weather-script.sh file properly.
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
m h  dom mon dow   command  
* * * * * /YOUR/WEBSERVER/FILEPATH/HERE/weather-script.sh
  • Had to set weather-script.sh file as executable (chmod 755 weather-script.sh)
    • OR add your user (default: pi) to the crontab group in /etc/group (type nano /etc/group)
  • Had to correct the Python name in the shell script from python 2 to python2.7:
#!/bin/sh

cd "$(dirname "$0")"

python2.7 weather-script.py 
convert weather-script-output.svg weather-script-output-new.png
pngcrush -c 0 nofilecheck weather-script-output-new weather-script-output.png
cp -f weather-script-output.png /path/to/web/server/directory/weather-script-output-new.png

I've enjoyed this project quite a bit and I'm already thinking about changes and modifications to the project. Some of them are:
  • Modify the display to post the current temperature OR just the low temperature after the sun sets
  • Write a script to display news and information based on RSS feeds
  • Modify the files so that they will work on the Kindle as a stand alone without the web server. Similar to the Kobo Weather Display.
I hope these notes help if you're looking to set one of these up. If you have any questions or something doesn't make sense, leave a comment or send me a tweet (@shatteredhaven) and I'll get back to you as soon as possible.

Downloads:
Kindle Weather Display Github Repository
Or if you prefer, download directly from dropbox

UPDATE 12/27/2012: I tweaked the SVG to reflect all the days of the week instead of today, tomorrow, etc. Details can be found here: Kindle Weather Display: Days For All Forecasts

14 comments:

Spectacular instructions, Jennifer!! Thanks for taking the time to write all that out!

Thanks! I hope they were helpful!

I wrote my own version of the server, In case you want to check it out:

http://origami.phys.rpi.edu/~jimenc/public/pjs/weather_kindle/server2/weather.php

Hi do you have any advise how I may get this work with a UK location? I notice that when I change the Lat and Lon co-ordinates, the script errors out when calling the .PY script at line 43.

Unfortunately, the python sript is looking at NOAA, which is just for North America.

I believe you could swap the xml link for one from Wunderground, which should cover the UK for weather updates.

If you do that, you'd have to change some additional values in python file. For example you'd have to change:
- line 23 is looking for the value of 'temperature'
- line 27 is looking for the value of 'maximum'
- line 31 is looking for the value of 'minimum'

I hope that helps!

Many thanks I'll give that a try.

FYI librsvg2-bin is available in the debian repositories for rsvg.

Great blog Jennifer. Liking the update time field, we think the same way!

One thing i found on Debian, might be useful for others - is that pngcrush is a bit funny with the bit depth.

I tried "pngcrush -bit_depth 8..." but it stretched the image. The solution was to do it in the svg conversion step with "convert -depth 8..."

Wow, this project looks great...

Q: Any luck getting this project to work on the Kindle as a stand alone without the web server?

How about just getting a date/time to show up in big fonts without a server call?

Thanks again for the great blog post.

Fabian - I do not believe there is a way to get this to work strictly on the Kindle. So far as I know, the Kindle doesn't have the ability to run the necessary software to convert an SVG, create output, etc.

Even if you removed the images and went strictly text, the Kindle wouldn't be able to run the necessary python script.

You might have better luck with the Kobo. I *think* you can actually load Python directly on it, so you might have more success with that.

http://www.mobileread.com/forums/showthread.php?t=194376

Hey Jennifer,

I'm trying to download/install your dropbox 'Kindle Weather Display.rar' to my Raspberry Pi. I tried installing unrar-free but it apparently does not handle your .rar because it has multiple files within. Is there some reason to use .rar vs. something more common like .zip or .gz?

It's possible to do a Kindle weather display without USB networking, ssh, or Linux commands. Kite can issue all the commands necessary. I have a writeup at http://www.galacticstudios.org/kindle-weather-display/

These instructions are great! But unfortunately I fell over at "gzip -d kite.gz". It gives me the errors:

/etc/rc5.d/S62kite: No such file or directory

and

/etc/rc3.d/K07kite: No such file or directory

Does that mean I have to load kite some other way? Or will Kite just not work for my Kindle 4? Is there some other way to run shell scripts on a jailbroken kindle?

Thanks a lot,
Alex

An interesting discussion may be valued at comment. I do believe that you ought to write on this topic, may well certainly be a taboo subject but usually individuals are not enough to communicate on such topics. To a higher. Cheers mm romance novella

Post a Comment