Weather forecast on a RaspberryPi printer – now with added Pi

Here’s how I get the weather printed on my RaspberryPi-powered GoFreeRange internet printer every morning at 6AM.

Daily weather forecast on my little printer

Overview

  • I made a GoFreeRange printer using a RaspberryPi instead of an Arduino.
  • I signed up for IFTTT and got it to send a local weather forecast sent as a text file to a folder in my DropBox account each day at 6am.
  • I wrote a shell script on the RaspberryPi which looks to see if there’s weather forecast in my DropBox account. If there is, it downloads it to the RaspberryPi. It then moves the remote DropBox copy of the forecast to another folder so it doesn’t get printed again. The script then calls a Python script to send the forecast to the GoFreeRange printer backend server so it prints out on my printer.
  • I scheduled this shell script to run every 5 minutes on the RaspberryPi using crontab.

 

Details

I know there’s a Printer Weather app for the GoFreeRange printer, but I can’t get it to work and, knowing nothing about Ruby, I don’t have a clue how to install it myself – but I still want a weather forecast to come out of my little printer first thing in the morning.

The first time I got this working, I had to have a Mac turned on, as this was running JD Harper’s Python script to poll DropBox for new files to print. Having to keep a Mac running was a bit of a drag, especially when my little printer is being run by a RaspberryPi that just loves to run Python scripts.

The problem is that although there’s a Linux version of DropBox, it doesn’t work on the Pi’s ARM processor, and you need to have a DropBox folder mounted or sync’d locally on the Pi for the script to work.

Then I discovered Andrea Farbrizi’s Dropbox-Uploader shell script. This doesn’t mount or sync a DropBox folder by itself, but it does allow you to upload and download files to and from DropBox on a RaspberryPi. Amazingly useful! So I installed it on my Pi and got it working.

I also installed JD Harper’s Python script on the RaspberryPi – amazingly this pretty much worked first time, much easier than it had been to get running on my old iMac.

I put everything in a folder called /home/pi/dropbox/gfr/ on the Pi including a directory called txt for the downloaded weather text files, with 2 sub-directories, one called ToPrint and another called Printed.

I had hours of fun making sure all the files were accessed by absolute paths and filenames so when the scripts were run by cron, cron would know where to find everything. (Cron’s not very good at looking for things, you really have to point things out to it. It must be a man.)

My IFTTT recipe looks rather like this, except I’ve changed it so the resulting file is always called ‘weather.txt’ – this just makes the coding a bit easier on the Pi:
Using IFTTT to print daily weather forecast on my little printer

Here’s what my shell script weather.sh looks like:


#!/usr/bin/env bash

# bash script by Giles Booth www.suppertime.co.uk/blogmywiki
# (c) 2013 Giles Booth
# for printing daily weather report on my Go Free Range printer
# using Andrea Fabrizi's Dropbox-Uploader shell script
# and JD Harper's printtxt.py python script to poll local
# folders and send text files to the GoFreeRange backend print server

# put a directory listing of Dropbox ToPrint folder in a text file
/home/pi/dropbox/gfr/dropbox_uploader.sh list txt/ToPrint > /home/pi/dropbox/gfr/ToPrint.txt

# if there's a remote file called weather.txt download it and move
# remote copy to 'Printed' folder in my DropBox

if grep -R "weather.txt" /home/pi/dropbox/gfr/ToPrint.txt
then
/home/pi/dropbox/gfr/dropbox_uploader.sh download txt/ToPrint/weather.txt /home/pi/dropbox/gfr/txt/ToPrint/weather.txt
/home/pi/dropbox/gfr/dropbox_uploader.sh upload /home/pi/dropbox/gfr/txt/ToPrint/weather.txt txt/Printed/weather.txt
/home/pi/dropbox/gfr/dropbox_uploader.sh delete txt/ToPrint/weather.txt
else
echo "no weather found"
fi

# clean up list of files to print
rm /home/pi/dropbox/gfr/ToPrint.txt

# now run the python script to print local text files
python /home/pi/dropbox/gfr/printtxt.py

And here’s what my crontab.txt looks like:

*/5 * * * * /home/pi/dropbox/gfr/weather.sh > /home/pi/dropbox/gfr/tempfile.txt 2>&1

This runs weather.sh every 5 minutes and writes a log file called tempfile.txt so I can see what’s been going wrong, if anything. I loaded the crontab with the
crontab crontab.txt
command. I still need to get this cron task to load up when the Pi is first switched on, though.

The other thing on my ‘To do’ list is to get the Pi to print any file in my DropBox ‘ToPrint’ folder, not just one named weather.txt

Daily weather forecast on my printer - rain, of course

Posted in computers, internet, Linux, Raspberry Pi, Raspbian | Tagged , , , , | Leave a comment

Daily weather forecast on my little internet printer

weather on my printer - rain, of course
Rain, of course

I want the weather forecast waiting for me on my little Raspberry Pi-powered internet printer in the morning. I tried signing up for the Printer Weather forecast app but it never worked – maybe it’s not running at the moment. I couldn’t work out how to install it myself, so I was a bit stuck.

Then I had an idea. I use IFTTT to email myself a weather forecast every morning. IFTTT stands for If This, Then That (or is it ‘If That, Then This’?). It glues together different web sites and services like Gmail, Flickr and Twitter in ways that can be incredibly useful. I had an idea to use the weather service on IFTTT combined with JD Harper’s really neat idea for using Dropbox text files as a way of printing to a GoFreeRange printer.

His insanely clever idea is to use a Python script to poll a Dropbox folder for text files – as new ones appear, his script reformats them as HTML, sends them off to the GFR backend print server with your printer’s URL, so the text prints. It then moves the text files to another folder so they don’t get printed twice.

Like JDHarper, I have a Mac, but I had a few issues getting his Python script to work. I had to install ‘elementtree’ and update the Mac’s version of Python from 2.4.4 to 2.7.7 as getcode() wasn’t supported in Python 2.4.4

I then used crontab to get the Mac to run the Python script every minute. (There’s another really useful guide to scheduling tasks with cron in MacOS X here.) My crontab.txt file looked a bit like this:
* * * * * cd /Users/gilesbooth/RaspPi/printer/ ; python printtxt.py
The first bit changes the directory the folder where JD Harper’s Python code lives, and the second bit runs it.
I loaded it by typing
crontab crontab.txt
at the command line.

It worked! I could now drop a text file, anywhere in the world, into one of my Dropbox folders, and (as long as my Mac is turned on) it prints on my little printer, wherever the printer may be.

This is where IFTTT comes in, and things get really tasty. Instead of getting the weather emailed to me, I changed my IFTTT recipe to send it as a text file at 6am each day straight into the Dropbox folder which is polled by the Python script on the iMac. I added a bit of HTML to the forecast to make it easier to read, but it works!

Using IFTTT to print daily weather forecast on my little printer

Obviously, having to have my iMac turned on sucks rather. So the next thing to do is to get the RaspberryPi to do the work of the iMac, if it’s possible to get the Pi to poll Dropbox folders… and some pictures would be nice. I might also re-write the Python script to make the formatting prettier.

Daily weather forecast on my little printer
looking brighter

Post-script

I have now managed to get it all running on a Raspberry Pi, with no need to have an Mac running to get files from DropBox to the GFR print server. Details to follow in a new post here.

Posted in computers, internet, Linux, Raspberry Pi, Raspbian | Tagged , , , , , , | Leave a comment

Root my Nook!

With apologies to any Australian readers – although if I break it, that may be an appropriate usage of the word ‘root’.

Nook on the hook

The Barnes & Noble Nook Simple Touch has been on sale for £29. £29! At that price, it would be rude not to buy one, especially when it can be hacked to run extra apps. You can pay $30 for a tiny e-Ink test screen for an Arduino, so £29 for a larger screen with a computer glued to the back seems like an amazing bargain.

The Common Reader
Nook Simple Touch side-by-side with my old 3G Kindle. The Kindle has sound capabilities but the Nook has a touch-screen. And it was £29.

The £29 Simple Touch as shipped is a perfectly decent eReader, black & white e-Ink display, no backlight, but it does have a touch screen – it doesn’t allow you to add any extra apps, though, even though under the hood it’s running Android. This means you can turn it into a simple, very very cheap, Android tablet computer.

This is where rooting comes in. You just need a micro SD card (I used a 2GB one I found in an old phone), a USB reader for said card and a computer you can use to write a disk image to the SD card.

I activated my Nook using a Nook account, updated the firmware to 1.2.1 from the uk.nook.com site (the update on the US site didn’t seem to work) and then I followed these instructions: http://www.babblingengineer.com/how-to/how-i-turned-my-nook-into-an-e-reader-monster/

Scary...

Rooting my Nook

followed by these to get the Google apps installed: http://forum.xda-developers.com/showthread.php?t=2086582

Rooting my Nook

I was able to get Gmail and the GoogleMarket working, but have had no luck with Google Chat. I tried using the Amazon Marketplace, but it said that it didn’t work in my country (the UK), so you need another way of installing apps. I managed to get a few apps installed using the Google Market app (such as Goodreads and Dropbox), but there’s a snag – you can’t search it, so installing SearchMarket is pretty essential. If you’re an avid reader, you may find Goodreads reason enough to root your Nook, along with the Kindle software. It does seem a bit perverse, but then I have quite a lot of books ‘on Kindle’. It’s supposed to be hard to get the Kindle software to work, but I managed to read an archived book ok:

Reading a Kindle book on a Nook

The default web-browser is pretty crashy, though Opera Mobile seems to be much more stable. Gmail is also a bit crashy if I’m honest, but maybe that’s because I’ve removed the SD card. Importantly, though, the Nook still works as an e-Reader, and all the Barnes & Noble software remains.

Gmail on my rooted Nook

There are some recommended apps and tips here: http://lifehacker.com/5926798/turn-your-rooted-nook-into-the-ultimate-ereader-with-these-10-apps

Here’s a screengrab of the app screen after I’d installed a few more:

shot_000001

which is oddly in colour – in fact, it looks more like this:

shot_000001bw

This is my first Android device. Wow, they made taking screenshots hard, didn’t they, compared with iOS? I guess Apple made it easy on iOS by way of apology for making it so impossible to remember in OS X. Cmd, shift, alt, option, cross fingers, 4 is it?

Post-script

I’ve found another work-around for the search box not working in the Android Market app – you can use a web-browser on your computer, log into Google, go to play.google.com and send apps to your ‘phone’ (i.e. Nook), and they then appear under ‘My apps’ in the Market app, so you can install them.

Posted in Android, computers, hardware, Linux, thrift | Tagged , , , , | Leave a comment

Adding an LED to the internet printer

Adding an LED to my little Internet printer

Sometimes I’m not sure if my little Raspberry Pi-powered GoFreeRange internet printer is actually working or not – the Raspberry Pi is hidden inside the box, and you can’t usually see the onboard LEDs. Today I thought my printer had been quiet – it turned out the mains plug had fallen out. So I decided to add an LED that lights up when the Python script that makes the printer work starts running, and which can be fitted to the top of the soap box. (I know there are lights, and even a button, on the original Arduino-powered GFR printer, but I’m not sure what they do).

I connected the GND pin (pin 6) on the Raspberry Pi to a breadboard (via the black wire in the photo), so the GND pin can be shared by the thermal printer and the LED. I connected GND back to the printer (with the orange wire).

I connected the GND rail on the breadboard to a 330 ohm resistor (all I had) to the short leg of an LED.

Then I connected the long leg of the LED to a GPIO pin on the Raspberry Pi – pin 7 (GPIO 4) – that’s the red wire in this photo.

I added this code near the top of the printer.py Python script, just after all the other import commands:

import RPi.GPIO as GPIO
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output channel
GPIO.setup(7, GPIO.OUT)
GPIO.output(7,GPIO.HIGH)

This then lights an LED when the Python script starts running. It doesn’t, of course, necessarily tell me it’s stopped running, but at least I know there’s power to the Pi and the script has started at least once since it booted up.

This probably commits all kinds of crimes against coding and electronics – advice and suggestions for improvements are most welcome!

The next step is to get an LED to light when it polls for new stuff to print, or when stuff is incoming – perhaps a different colour LED for incoming data? Though stuff coming out of the printer is usually a pretty big clue that there’s incoming data, so I’m not sure exactly how useful that would be. I might also see if I can get the button to shut the Pi down so it can be safely unplugged.

Polling blinking

Here’s how I got the LED to blink when the code is polling for new content. I added the following lines near the top of the printer.py script:

import RPi.GPIO as GPIO
# to use Raspberry Pi board pin numbers
GPIO.setmode(GPIO.BOARD)
# set up GPIO output channel
GPIO.setup(7, GPIO.OUT)
GPIO.output(7,GPIO.LOW)

The last line isn’t probably necessary, but it was useful for me when testing to get the script to turn the light off when it started up.

I then modified the last section of the printer.py code so it read like this:

while(True):
GPIO.output(7,GPIO.HIGH)
checkForDownload()
GPIO.output(7,GPIO.LOW)
time.sleep(pollingTimeoutSecs)

This causes the LED to blink momentarily when it polls for new data, so I know the script is running.

Posted in computers, ICT, Linux, Raspberry Pi, Raspbian | Tagged , , , | Leave a comment

Making a GoFreeRange internet printer with a Raspberry Pi

I love the idea of the Berg Little Printer, but it’s expensive: a self-contained box that lets you rip & read internetty stuff such as weather, messages, diary events, travel news, whatever anyone can think of. I already have a thermal printer I used for my Little Box of Poems, so I decided to make an open source GoFreeRange internet printer instead. The GoFreeRange printer normally uses an Arduino, but as I have the wrong kind of Arduino, I wanted to use a Raspberry Pi instead.

You can read more about little thermal internet printers in this Wired article from 2012.

Untitled

Here’s roughly how I did it (more details to follow):

  • I made a fresh Raspberry Pi SD card using the normal default Raspbian Wheezy disk image: http://www.raspberrypi.org/downloads
  • I got the Raspberry Pi on t’internet using a wifi dongle, setting it up using the GUI wifi tool on the desktop, and enabled SSH using the raspi-config tool so I could log into it from a computer with no keyboard or mouse connected to the Pi. I also used the raspi-config tool to expand the disk image to fill the SD card and update the system software. I did not get the Pi to boot into the graphical environment at startup, as I was going to be running it ‘headless’.
  • I powered up my thermal printer and connected it to the Raspberry Pi in the same way I did with The Little Box of Poems. I put the Raspberry Pi and printer in an old washing tablet box.
  • I followed Andrew Nicolaou’s instructions: https://github.com/andrewn/raspi-printer#readme - I changed the baud rate in cmdline.txt – this causes the Raspberry Pi to send its Linux boot messages to the printer as well as the video output. It’s a bit verbose – I got a yard of nerdy gubbins spewing out of my printer, but it worked. (You can disable this if you like, see below).
    Raspberry Pi boot screen text coming out of printer
  • Then, following Andrew’s instructions, I installed the python-serial library. I was a bit thrown about the bit where he says to save a file with your unique printer ID. I didn’t have one, and I didn’t know how to get one. It seemed like a bit of a catch-22, so eventually I just ran his printer.py script anyway.
  • I then went to this page on my desktop computer and made a note of the printer URL: http://printer.gofreerange.com/my-printer – somehow the file with my unique printer ID seemed to get made in the process. I did a test print – it worked!
  • Untitled

  • Then, having saved my printer URL in a notepad, I signed up for Printer Mail – http://printer-mail.herokuapp.com/. This means people can send messages to my printer by filling in a simple form on a web page. Brilliant!

I had a couple of kernel panics – the Pi rebooted itself without warning. Not sure why, need to investigate. I’d like to make the boot-up text a bit less verbose too.

As I’m running the printer script manually, I need to follow Andrew’s instructions on getting it to run automatically when you boot the Pi up, and get all the gubbins in a self-contained box.

People sending my printer messages from anywhere they can get on the internet all over the world is pretty damn cool, but other possible uses include waking up to a daily printed weather report and printing paper bookmarks customised for the book you’re reading. Or print out anything you star in Google Reader. What’s that you say? Oh well, you get the idea.

The Raspberry Pi version of the GoFreeRange printer doesn’t have a button – it just prints anything that’s sent it. I have a big red shiny button in my printer box that’s going spare, but I quite like the idea that no human intervention is required, it just squirts out… stuff.

I’ve been away from my printer all day, working a late shift. Quite excited to see what might be on it when I get home…

What’s next?! Excited… very excited.


I also signed up for the Printer Paint app – so you can draw me a picture on your computer and send it to my little printer. I love pictures appearing on my printer – send me one! http://printer-paint.herokuapp.com/send/blogmywiki

Incoming message from His Dudeness

Addendum:

I’ve now disabled serial port login on the Pi, to see if that helps with stability – following the instructions here: http://www.hobbytronics.co.uk/raspberry-pi-serial-port. I did this when I made the Little Box of Poems, and it seems like a good idea. You just comment out the last line of /etc/inittab, the one that reads
T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100
by putting a # (hash) at the start of the line. There are also instructions there on how to stop the printer spewing out all the Linux boot-up info when you turn the Pi on.

Post-script to the addendum

I had trouble getting the Python script to run at startup. This is quite important, because I want my little printer to just start working – and stay working – when I plug it in. I don’t want to have to log in by SSH to start the script running.

I couldn’t get the update-rc.d method to work, so instead I edited /etc/rc.local by typing
sudo nano /etc/rc.local
and adding the line
sudo python /home/pi/raspi-printer/printer.py
to it. This seems to work.

I've got pandas on my printer

Posted in Linux, Raspberry Pi | Tagged , , | 11 Comments