Up until now, the Kindle Weather Display has looked like the above with the forecast as:
Today
Tomorrow
next day (day of the week)
day after that (day of the week)

This works wonderfully until you hit about 7pm. At 7pm the forecast flips from giving you the current day's forecast to the next day's forecast. This is because the information from NOAA being pulled is based on UTC and not a local time zone. So to eliminate any confusion in the evening, I thought it would be nice to add the name of the day of the week for the Today and Tomorrow forecasts.
The change was pretty easy. I just needed to add a few lines to the python code. in the Insert days of the week section I simply added a DAY_ONE and DAY_TWO variable. Here is what it looks like:

one_day = datetime.timedelta(days=1)
days_of_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
output = output.replace('DAY_ONE',days_of_week[(day_one + 0*one_day).weekday()]).replace('DAY_TWO',days_of_week[(day_one + 1*one_day).weekday()]).replace('DAY_THREE',days_of_week[(day_one + 2*one_day).weekday()]).replace('DAY_FOUR',days_of_week[(day_one + 3*one_day).weekday()])


I'm not 100% sure that's the most efficient way to do it, but it works. 
Next was to tweak the SVG file. I simply replaced Today with DAY_ONE and Tomorrow with DAY_TWO.

I also noticed the DAY_ONE day was being cut off when the actual day of the week was being inserted so I had to play around a bit with the x axis placement. I also opted for a left anchor as well which pulled the day over a little. I might play around and move it some more if it bothers me, but for now I'm happy with the placement.
Anyway, as you an see, we now have all the days of the week listed. Here's tomorrow's forecast as of 8pm tonight!

Original post with tutorial:Kindle Weather Display


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

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

Doesn't that look worlds better than yesterday's display?

I fiddled around a little this evening and made some progress. I learned just enough about shell scripts and pngcrush to edit a file and end up with the correct display. I even modified the python file so that it finally reflect the proper longitude and latitude for where I live.

Now, the reason I say tomorrow's forecast is because the Kindle currently thinks it is 1:40am, which means Tuesday's forecast is under today, Wednesday under tomorrow and so on. There is no option to set the time in the device settings. My options are to register the Kindle with Amazon or edit the time from the command line. I don't really want to register a second Kindle device to my account because I don't have any intention of using this as an eReader and I don't want to accidentally send books to it. I've already done that with the tablet and the Kindle. It sounds silly but I'm really just trying to avoid clutter in my Amazon account. So edit via the command line is the likely course of action.

This may not be the perfect Kindle Weather Display yet, it's getting there. Plus I'm learning all sorts of new things along the way.

Next I'll have to edit the refresh time on the web server and the Kindle with the use of cron. There are a few other tweaks I'd like to make after that, but I think once I have the refresh times set up I should be in good shape. I may end up running the web server (currently running the python code and converting SVG files to PNG files) on a Raspberry Pi until I figure out how to move everything to the Kindle.

And yes, I'll eventually blog about something other than the Kindle. I just figured this might be marginally more interesting than reading about playing the Lost Shores content recently added to Guild Wars 2, which I've played a lot of.

After all the reading yesterday and a little more today, I felt reasonably confident that I could get the USBNet hack to work, thus allowing me access to the Kindle file system.
The whole process turned out to be less painful than I had anticipated and I was logged into the Kindle in no time.
The basic steps I took are as follows:
  1. Install the network drivers for the Kindle on your machine. I had difficulty installing the ini file from the wiki, so for Windows 7 I did this while in the diagnostics menu
      • Go to Device Manager in Windows
      • Choose the unrecognized device from the list
      • Choose update driver/install driver
      • Choose "Let me pick from a list..."
      • Choose Network Adapter
      • Choose Microsoft Corporation
      • Choose Remote NDIS based Internet Sharing Device
  2. Next is determining if SSH is on the device or not. The wiki has a good tutorial here
If you determine that SSH is not running on your device, like I did, you'll need to do the USBNet hack. The file can be downloaded from this forum post (kindle-usbnetwork-0.XX.N where XX is the latest version number).

Read the README.txt for instructions and details. These steps are outlined in the README. The README also has more detail on what you need to do than what is below. The basics steps are:
  1. Plug Kindle into computer, place the appropriate update .bin file onto your Kindle.
      • Note: If you don't know your root password, write down your Kindle Serial Number found under the 2nd page under Device Info (Menu-->Settings). Input that serial into Kindle root password tool, and it will give you a list of few possible passwords.
  2. Eject the Kindle and install the usbnetwork update (Menu-->Settings-->Menu-->Update Your Kindle).
  3. Wait for the update to install and for the Kindle to reboot (took just a few minutes for mine to install and reboot).
  4. Review the config file on the Kindle under src\usbnet\etc and make any changes as necessary. As noted in the config file, this MUST be done in a UNIX/Linux environment and not Windows. (Line endings). 
      • Aside from adjusting USE_VOLUMD to true for the Kindle 4, I would recommend leaving the default settings for now to ensure that everything is working properly before editing the config file.
  5. Make sure the Kindle is not plugged into your PC. If it is, eject the device. 
  6. On the Kindle keyboard (you can use the keyboard key on the Kindle 4) type: 
      • ";debugOn" (with no quotes). Choose "search my items" to enter this information into the Kindle. You will see no changes. 
      • Next type "~usbNetwork". Choose "search my items" again. 
        • Side note: I noticed after typing the last command that the battery icon at the top of the Kindle has a lightning bolt through it (the charging symbol) appears. I'm not sure if this is an indicator on all Kindle versions, but it did indicate on my K4 that it was now in "usbnetworking mode". 
  7. Plug the Kindle into your computer. It should be recognized by your OS as a Network Adapter.
  8. Set the IP address on your computer to the address defined under "HOST_IP" in the config file. Subnet should be 255.255.255.0. Everything else can be blank. 
      • NOTE: When you plug the Kindle into your computer you should see two network adapters. You are changing the IP address for your Kindle network connection and not your regular ethernet/wifi connection.
  9. Launch your preferred SSH application (ex Putty). Type in the IP address that was listed under KINDLE_IP in the config file.
  10. You should now see the login screen. Login! 
      • If you enabled SSH over Wifi or made some changes other options, you will need to know your password for root. This is where your Kindle Serial Number comes in handy. If you didn't retrieve your password earlier, simply visit the Kindle root password tool, and it will give you a list of few possible passwords.