Saturday 14 May 2016

Kindle weather display with RF temperature sensor

I've seen projects on the web about:
  1. Turning old kindles into internet data weather displays.
  2. Using RF temperature sensors on a Raspberry Pi and displaying the data on a Pi served web page or simple LCD display.
Combining these two projects seemed like a great project idea to learn about the Pi and electronics. I haven't seen this particular combination published on the web yet.

To explain what the kindle display shows:

  1. 'House Temperature Sensor' Section: 
    • Inside temperature as measured by a DHT22 sensor attached to the Pi
    • Outside temperature as measured by a remote RF temperature sensor.
  2. 'Local Weather Forecast' - API call to to show 7 day descriptive forecast and graphs of local temperature, wind, cloud cover, and rain chance.  

Or to put it in a more visio kinda way:

Full tutorials take a lot of time to write, plus it's no fun following cut and paste steps. The real fun of tinkering is reading stuff, trying stuff and adapting it to your own needs. So here are some basic tips and pointers for anyone interested.


1) Raspberry Pi. 
I got a version 3. There is a slight hack to get the Uart pins working the same way as the Pi2 as the slice of radio expects.
     sudo nano /boot/config.txt
and add
     #  Change device tree to enable slice of radio
(Thanks goes to this site )

2) RF receiver (Slice of Radio) and remote temperature sensor
This remote temperature sensor is good as it doesn't require any configuration over serial port (unlike xbee devices). The bad news is that you have to solder the components together yourself. Price is good, you can buy the receiver and sensor as part of one kit.

3) Local temperature sensor. 

Any local temperature sensor would work. I got a Adafruit DHT22 but lots of others would do the same thing. You could also buy another RF remote sensor and just use that indoors too.

SQLite database

There's tons of tutorials and info and how to create databases and use insert and select statements.
The only things I would add is

use 'detect_types=sqlite3.PARSE_DECLTYPES' in your sqlite3.connect command. This makes python convert the millisecond values directly into python datetime objects.
e.g. "conn = sqlite3.connect('/home/pi/yourDB.sqlite',detect_types=sqlite3.PARSE_DECLTYPES)"

install iceweasel on your pi (which is firefox) and add the addon SQLiteManager. Managing your DB just got a whole lot easier.

Saving sensor data to a SQLite database

The adafruit local sensor comes with its own library and examples. Create a cronjob for every 5 minutes to poll the sensor and insert it into the database.

The Slice of Radio works differently in that a bash script needs to be running all the time to capture incoming serial messages. Again use the example code provided with it and modify it to insert the data into the DB.

Setting up the Apache webserver and CGI scripts

This website is a great resource for CGI scripts, SQLite and Apache.

He also has a excellent full tutorial on reading temperature sensors and displaying this via a google charts webpage. I ended up using flot charts in my project as they have the shading capability which I use to denote night times.

Flot charts

This site is a great tutorial on logging temperature sensors to a Pi database and then displaying this via a webpage using flot charts. Especially useful is his code to create shaded areas on the graph to denote weekends, I adapted this code to denote nightime areas on my graphs.

Converting the webpage to PNG

The kindle needs a small PNG file to display, it can't show a webpage.
wkhtmltoimage with a javascript delay of 2000ms will create your PNG file
pngcrush will compress the file to a size agreeable with the kindle.


This site will give you all you need to know about hacking the kindle.

  1. Jailbreak
  2. Install KUAL - this give you a nice menu where you can disable your screensaver and turn on usbnet
  3. Install USBnet - this allows you to access the kindle over putty. Your read about some kindles not needing this but do it anyway, my kindle technically didn't need it but I had problems running cron without connecting via usbnet. 
  4. setup a cron job to call your bash script every 5 minutes (more on this script below)

Some tutorials out there setup much more (e.g. functionality for enabling/disabling the cron job) but I didn't bother with that.

Weather display script

This site is one of the first internet resources on create a kindle weather display using internet forecast data.
I used his bash script. This is the file that is executed by the cron job on the kindle. The commands fetches the PNG file served from the Pi and display it on the kindle.

Internet Weather Forecast

Weather Underground provide free access to weather forecast via API calls and JSON responses.

No comments:

Post a Comment