Thursday, December 19, 2013

A Better Cloud Printer I

Continue from my last post: Looking for a better cloud receipt printer.

A Better Cloud Printer I

So this is my ideal cloud thermal printer:
  • Small form factor. (takes little desktop space)
  • Connects on Lan/Wifi/3G
  • Easy to use API to print things.
  • Provide server infrastructure at very low recurring charge. (Just like Twilio)
  • And the printer sells for under $100

Cost

My initial thought was to attach a Raspberry Pi to a regular thermal printer.  The total cost would be roughly $100.
  • $50 Thermal printer
  • $40 Raspberry Pi
  • $10 SD card
  • Adding 3G connectivity would require $50 extra 3G dongle
Sounds simple enough, and I got my Raspberry Pi right away from a local electronics store.

However, the search for a $50 thermal printer took me to an unexpected journey. You can read the experiences on my other blog posts. (Post 1),(Post 2).  Long story short, now I have a working Thermal Printer attached to the Raspberry Pi, the rest is software.

Software

Then the problem becomes how to implement a software stack to control printer from remote server.
  • Communication between printer and server
    • All China-made GPRS printers uses some custom TCP Socks protocol.  This requires me to implement all server structure and error checking mechanism.  (Not great)
    • TCP Socks will have problem behind firewall/proxy.(Not great)
    • I favor XMPP protocol for its ability to fallback to HTTP if Socks fail.
    • XMPP servers already implemented off-line message and presence etc.
    • Downside is: XMPP uses more bandwidth than custom TCP Socks.
  • The actual print out
    • This is simple, just issue ESC/POS command to serial port.
  • API interface for issuing printing command, managing printer.
    • The server must have a XMPP master node to oversee all printers.
    • Upon every API request, the master node talks to printer and returns result to caller.
    • API return data in JSON form.
  • Server Software
    • RPi runs archlinux because I wish to use the latest software.
      • Final product should run a more stable distro.
    • Prosody as XMPP server.  Fast, small memory footprint.
    • Nginx/PHP-fpm as web server.
  • Programming landuage
    • It appears that Python has better resources to work on Raspberry Pi as XMPP client.
    • PHP for API, easy to use.  Small resource foot print.

Software II

Upon some initial discovery, the solution lead to even more problems:
  • Gracious shutdown (fixed, Jan 2014)
    • File System corruption. The printer is turned off arbitrarily. However, default Linux filesystems are not designed to handle that. 
    • Need to fit Archlinux onto live-CD or something similar.
    • Also need the client to be able to update itself.  Therefore it takes a little more than live-CD.
  •  XMPP master node (fixed, Jan 2014)
    • At every API request, I need to initialize the master node in PHP.  Is there a way to have a long-running master-node?
    • What if the long-running master-node fails? How do I fail-over to a second node?
    • It is possible for printer to initial the communication when coming online; how do I feedback to the server?
  • Remote Configuration
    • Since the printer is suppose to "just work" for end user, I need something to config the printer's wifi/network remotely.
      • what if I need to config WIFI when the printer is not connected?
These problems are important for a production-ready product, however they do not get in the way of building my very first demo unit.  I will come back and fix them soon.

Next post: A Better Cloud Printer II - API definition





1 comment:

  1. Hello I m seeking to hire someone who can help me with making a cloud print solution

    Essentially having a wireless thermal printer automatically print from a SMS (via a gateway like Twilio).
    We can use raspberry pi or if there is thermal printer with sm card that would be even better
    Please help me
    Eagleofny@yahoo.com

    ReplyDelete