Roll your own Google Cloud Print, Today, Using Your Zipit Z2 (or anything that can run python), in 5 Minutes
When I read about Google's new strategy for cloud printing, I thought "hey that's great!, wish I could use it before 2011!". Thankfully, I run linux on damn near everything. As I don't have an android (which would be a pretty ideal running platform for this...), I've used the Z2 as my "drop in" cloud print server. Doesn't seem like it'll take the manufacturing companies long to integrate this into new product lines, as it's pretty simple. Instructions and source code links below!

So here's the plan. We're going to configure our Z2 to periodically check an email address for emails with attachments. When it finds an email with an attachment, it prints the attachment and archives the email. As you can see from the photo, I place a little notecard on the Z2 which states "Email __EMAILREDACTED___ to print to this printer". If you want to print to this device "from the cloud", just email to it. Pretty simple
, and the arm in the Z2 takes up a fairly low wattage overhead as a cloud monitor/print server.
- First, we'll want to connect the Zipit to an existing printer. As I've got a network printer at work (fairly common situation), I'll use that as the example case. Using one of the linux (I'm going the debian (easy) route) Z2 distros that's popular, boot your Z2 up and get it connected to the net/up to a state where it can update via apt get. Then
apt-get install cupsfor printing., andapt-get install gmail-notifyto install all the relevant pre-reqs for python. That's one thing that's great about python on embedded, if you know another popular python program uses all your libraries, just install that first and you've got your prerequisites covered...or at least all the ones I can remember
You can set up cups to handle various filetypes for printing, but it should come with postscript by default and that's enough for me - Next, we'll configure the Z2 to print to a network printer. This will be your "drop target". You can either use one of the gui printing configuration tools (select IP Printer from the drop-down list), or the cups command line or web tools. From the debian wiki, cups runs a web daemon locally than can be used to configure new printers. After installing cups, you can
elinks http://localhost:631/to get to an administration website. From here it's pretty trivial to print, as your apt-get should have pre-configured a lot of cups for you i.e. samba, workgroups info, etc (interactively in my case). - As this'll be an open source solution, there's no need to re-invent the wheel. Suresh Kumar wrote an imap attachment handler in python that's fairly compact, we can use that as an excellent base to write our script. It's PSF licensed, so you know it jives with our GPL sensibilities.
- Now in this script it stores all attachments into their own hierarchical directory structure. You can remove this if you like, but I kind of like having a print backup, at least for a few weeks. This is the write_file() function. Wherever this is called you can add your own os.system call to print the file. For the lazy, if your printer is named "JACKBAUER" at the end of this function just add
sysCommand = "lpr –P JACKBAUER –#1" + filename. This fills a string buffer named sysCommand with our command to print using the lpr function (cups standard printing function). Follow this line withos.system(sysCommand) - Now that your python script is finished, create a script to execute the attdownload.py with the proper variables (username, server, etc perhaps make it a background process with nohup etc). Make the script executable, and you're good to go. Either add it to your rc.local so it runs on startup or add it to your bash.rc so it loads on login. Congrats! You live in a world with email capable printers
April 20th, 2010 - 05:52
Very nice. i’ll have to try to get python working again in IZ2S. I had it working for a couple of weeks but I broke my build environment and couldn’t get it to build again.
April 20th, 2010 - 06:09
Hey rkD,
I pulled from the debian repo, but I recall bitbaking the python libraries only took a few hours back before the debian image days
Good luck!
April 20th, 2010 - 06:20
yes debian and oe are a hell of alot easier to get stuff for but i’m stubborn and using my own variant of IZ2S these days which is great for most stuff you could want to use your zipit for but building stuff is a right PITA as alot of the flashy build tools SCons, CMake either just can’t be built or suck
— i’ll try your stuff on my u-booted oe/br zipit though and finally get around to unbricking my .29 debian zipit i think. i’ve been printing from my zipit too but only text and using a really convoluted method because i have a silly All in One Network printer that is crippled so was dumping to a linux box and printing from that, your method is much neater.
April 20th, 2010 - 06:22
Sounds like an interesting setup, I’ll be curious to know how it turns out!
April 20th, 2010 - 07:39
Just built python for z2shell’ed,IZ2S’d or IZ2s(enhanced) zipit’s — the interpreter runs but there are some problems with libraries (using and installing, marshal mostly it looks like), but i got some weird types errors when it was building but it got further than it did last time I tried it. maybe I can track down the errors (probably uClibc related) and see if I can get it working again.
April 21st, 2010 - 09:50
Interesting on the type errors… yes probably related to uClibc. Very cool though, that it almost works on IZ2s, that’ll make the python folks that don’t like flashing very happy
Great work, and good luck finishing the compile
April 21st, 2010 - 16:57
I think that instead of polling for mail, direct delivery and a procmail handler would work nicer. But, nice setup enyway
April 21st, 2010 - 17:05
Thanks, and yea I think that’d be a bit nicer on the battery for sure.
April 21st, 2010 - 17:06
I previously thought about rolling a .py webserver that you can upload files to, but it seemed overkill
August 2nd, 2010 - 14:18
by the way the type errors I was getting in most of my builds are because when building something /designed/ for x86 you need to -fsigned-char when building for ARM as ARM gcc defaults to unsigned chars whereas x86 gcc defaults to signed chars. I’ve now built python for a stock zipit but I had to upgrade uClibc too so it isn’t compatable with current versions of IZ2S, IZ2Se or EZ2S at the moment.
August 3rd, 2010 - 13:45
Hey RK,
That’s good info, thanks! Sorry for the lack of updates, I should be posting up some embedded dev. stuff sometime soon. Thanks for the info!