Here’s how I get the weather printed on my RaspberryPi-powered GoFreeRange internet printer every morning at 6AM.
- 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 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 remote DropBox 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.
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. Incredibly 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.)
Here’s what my shell script weather.sh looks like:
# 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
/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
echo "no weather found"
# clean up list of files to print
# now run the python script to print local text files
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
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