Amazon Kindle is well suited to be upcycled as a fridge messaging display due to its low power consumption.

Share Messages via Kindle on Fridge

The main idea is explained here and below are all the technical details:

Share Messages via Kindle on Fridge

All the source code below is in this repository.

Step 1: Send Email to myfridge@gmail.com

First you need to create a new email account for your fridge kindle on gmail.com, e.g., myfridge@gmail.com. Whoever sends an email to myfridge@gmail.com will get his email displayed on your fridge.

Step 2: Email Arrives into myfridge@gmail.com Inbox

There is not much to explain here, all the hard work is done by the google team :)

Step 3a: Install Dependencies on Raspberry Pi

You can use any server you have, many people have a Raspberry Pi running on their home network. Our webserver app to fetch emails and render them to html is written in Ruby.

First we install ruby and its gems (libraries):

$ apt-get install ruby
$ gem install gmail
$ gem install sinatra

and we checkout the server app source code (alternatively you can just wget this file):

$ git clone https://github.com/petervojtek/email-to-kindle-on-fridge.git
$ cd email-to-kindle-on-fridge

Step 3b: Fetch Last Email to Raspberry Pi

Steps 3b and 3c only explain in detail the what is inside email-to-kindle-webserver.rb. If you are not interested in details you can jump to step 3d to run the webserver.

We are about to gather last email from myfridge@gmail.com inbox.

We use ruby-gmail gem which is designed to interact with gmail inbox via IMAP.

require 'gmail'

We establish connection with our gmail account:

# note that only 'myfridge' is provided instead of 'myfridge@gmail.com'
gmail = Gmail.new 'myfridge', 'some_password'

and gather the last email:

last_email = gmail.inbox.emails.last

Step 3c: Render Last Email as Webpage on Raspberry Pi Webserver

We use sinatra ruby gem to help our ruby script act as webserver. We want to achieve that when we visit in web browser http://rpi_ip_address:1212/email we will see the last email.

require 'gmail'
require 'sinatra'
require 'base64'

# we don't want the actual login and password to be stored in this source code file
gmail_login = ARGV[0]
gmail_password = ARGV[1]
$gmail = Gmail.new gmail_login, gmail_password

# we want to remember uid of the last email to know if newer email has arrived
$last_email_uid = nil

def fetch_last_email
  email = $gmail.inbox.emails.last
  if email.uid == $last_email_uid
    return # we already see the latest email
  end
   
  $last_email_uid = email.uid
  $sender = Mail::Encodings.value_decode email.sender.first.name
  $subject = Mail::Encodings.value_decode email.subject
  $received_at = email.envelope.date
  $image = nil
  if email.attachments.size > 0 
    $image = email.attachments.first.decoded
  end
end

set :port, 1212 # run the webserver on port 1212
set :bind, '0.0.0.0'

get '/email' do # html below is rendered in your browser when you visit http://rpi_ip_address:1212/email
  fetch_last_email
  
  <<STRING
<html>
  <body>
    <!-- display who has sent the email and when -->
    <p><b>#{$sender}</b>, #{$received_at}</p> 

    <!-- email subject -->
    <h1>#{$subject}</h1> 

    <!-- first image attachment from email -->
    <img src="data:image/jpg;base64,#{Base64.encode64($image) if $image}" style="width:100%;"> 

    <!-- javascript will periodically check whether newer email has arrived -->
    <script> 
        lastEmailChangedCheck = function(){
          ajaxGetRequest('should_we_reload?rendered_email_uid=#{$last_email_uid}', function(xhr) {	
            if(xhr.responseText == 'yes')
                location.reload();
          });
          setTimeout(lastEmailChangedCheck, 10000) // every 10 seconds
        }

        lastEmailChangedCheck();

    </script>
  </body>
</html>
STRING
end

# javascript in your browser will periodically make an ajax request to this sinatra action
get '/should_we_reload' do
  fetch_last_email
  (params['rendered_email_uid'].to_i == $last_email_uid) ? 'no' : 'yes'
end

Step 3d: Run the Webserver on Raspberry Pi

Now we launch the webserver on our Raspberry Pi. Webserver’s source code is stored in file email-to-kindle-webserver.rb. For debugging purposes we can run it as following:

$ ruby email-to-kindle-webserver.rb myfridge password

Once all tested, you rather want to start the webserver automatically (e.g., after RPi reboot). You can use supervisord to automatically start the webserver by putting following content into /etc/supervisor/conf.d/email-to-kindle-webserver.conf:

[program:email-to-kindle-webserver]
command=ruby email-to-kindle-webserver.rb myfridge password
autostart=true
startsecs=1
startretries=1
user=your_rpi_login_name
directory=/path/to/email-to-kindle/repo

Step 4: Display Last Email on Kindle

First we to connect kindle via wifi to the same network where Raspberry Pi is running.

Next we disable kindle’s screensaver as kindle will automatically enter sleep mode after 10 minutes:

  1. Press the Home button to go the the Kindle home screen
  2. Press the keyboard button to display the virtual keyboard
  3. Type following string: ;debugOn and press Enter button (not the Done button)
  4. Type following string: ~disableScreensaver and press Enter.

Now we launch kindle’s web browser by pressing Menu > Experimental > Web Browser.

You have to enter the url address http://rpi_ip_address:1212/email. I advise you to save the address immediately as a bookmark to prevent entering the address in future which is painful on the kindle’s virtual keyboard.

That’s all. The webpage will detect new email arrival via ajax and javascript and will reload itself.

Step 5: Add Custom Paper Stripe

It seems is is not possible to enter fullscreen on the kindle’s web browser. To hide Kindle’s top system bar and web browser address bar we cut a stripe from paper using a blade cutter machine. In my case the headline /etc/motd refers to unix’s Message of the day.

Additional Notes

  • you can use IFTTT recipes to integrate services like weather forecast to send messages to your kindle (you may need to adjust the rendered html content).
  • I put this magnetic Self Adhesive Magnetic Strip on backside of kindle to keep it attached to the fridge.
  • You may be tempted to use native Gmail API to check emails instead of using IMAP, but the official Gmail API is super overengineered and overcomplicated and you will probably spend few hours trying to achieve the same you can do in five minutes with IMAP.
  • I received a suggestion to allow browsing the arrived emails instead of displaying newest email only. Unfortunately, the large next page/previous page buttons on Kindle 4 emit no signal to web browser and thus cannot be used to easily switch between email messages. I guess the touchscreen kindle’s are better suited for this purpose.
  • It seems to be useless to install Duokan OS for the purpose of this project – Duokan has no web browser (at least in v2013 for Kindle 4).

Credits

  • Andrew Jones