- There is no pre-requisite technical understanding to working through this tutorial
Time to Complete
- This tutorial should not take more than half an hour to complete.
Who Should Read This Document
This tutorial is suitable for anyone wishing to demonstrate printing over the web as a basis for Internet of Things and/or Internet of People applications. This document also serves to complete the simple web-printing application spanning the introductory tutorials Simple Web-Printing Pre-requisites and Sending a Print-Job to the Web.
Although this is a primitive implementation, it is quick, simple to understand and portable between web hosting companies. This is not necessarily the most robust nor secure implementation, so please be aware of these limitations and DO NOT use this as the basis for anything other than a demonstration system!
- It is expected that you have a fully-working, web-connected Raspberry Pi and Pipsta
You should have the following settings from your web hosting company by having followed the introductory tutorial Simple Web Printing – Pre-requisites:
- Host IP address
- Database name
You should have completed Sending a Print-Job to the Web and have a print job record waiting to be printed
Retrieving Data from Your Database
1) On the Pi, navigate to /home/pi/pipsta/Examples/2_Web_Print
2) In LXTerminal, enter:
3) Locating the following DB_CONFIG block, now enter the you details you used in the previous two tutorials (including the password for the database), e.g.:
4) Save and exit nano in the usual way, i.e. [CTRL]+[X], [Y], [return]
5) Now, in LXTerminal, enter:
cd .. python server.py start
6) If all is well, you should see the message(s) stored as print-job records for your printer printed to the paper roll now.
7) If all is not well, first check ALL of the details: user, password, host, db and port. Then check your internet connection is okay.
8) Once you have found the success message, go to FreeHostia, log-in, and in phpMyAdmin look at the printdata table by clicking on the printdata hyperlink:
9) Within the table, you should now see that the record(s) you inspected during PIPSTA011 have been modified as follows:
10) Note that the printer_id has been cleared.
python server.py stop
to stop the server when you are finished.
How it Works
- The script server.py runs as a daemon (i.e. a program that runs in the background), and will periodically launch WebPrint.py.
- WebPrint.py: This script connects to, and checks the database to see if there are any jobs pending for a printer of that serial number. Note that the serial number is queried by the Pi using a special command issued to the printer.
- The job_id is used to uniquely identify that job, so –if a job is found— it is printed, and the job_id index is then used to identify the record just printed to clear the printer_id, preventing the job from being printed again the next time the database is polled.
You have now successfully used a daemon server to retrieve and print data from your database on the web.
Extending the Tutorial
- Now run WebSend.py and the server simultaneously to see data going to the web and being retrieved.
- Swap serial numbers with a friend and have hard-copy ‘chats’
- Discuss how the use of ASCII-encoded hex would permit the transmission of graphical data over the web, to print banners, QR-Codes etc.
Shutting Pipsta Down Safely
Whilst the printer is resilient when it comes to powering down, the Raspberry Pi must undergo a strict shutdown process to avoid corrupting the Micro SD card. The most straightforward method of doing this is to double-click the ‘Shutdown’ icon on the desktop.
If you are already in LXTerminal, type sudo shutdown –h now to shut-down the Raspberry Pi immediately.
Always make sure ALL activity on the Raspberry Pi’s green LED (the LED on the right) has stopped before removing the power!
End of Document