= Network Printing CUPS (Graphics Allowed) =
825gen2 has CUPS (Common Unix Printing System)
From a terminal type **/usr/sbin/lpinfo -v** to show printers that are detected on the network in additional to local USB printers.
{{{
card825gen2:~$ /usr/sbin/lpinfo -v
network socket
network lpd
network ipp
network http
direct usb://SANEI/SK1-311%20Presenter%20(STR-001)
network dnssd://Canon%20TX-3000._ipp._tcp.local/?uuid=00000000-0000-1000-8000-001832104e5a
network dnssd://Canon%20iPR%20Svr%20G250%20V2.1%20US(64%3A59%3AA5)._printer._tcp.local/
network dnssd://HP%20Designjet%20T520%2024in%20%5BD50233%5D._ipp._tcp.local/?uuid=abcd9e8e-4886-85c2-2167-b143d1c2344a
network dnssd://HP%20LaserJet%20P2055dn%20%5B82FCF4%5D._pdl-datastream._tcp.local/
network dnssd://Lexmark%20C2240._ipp._tcp.local/?uuid=584bdd81-d230-49f3-a210-d39ac56492d0
}}}
Many network printers support a protocol known as Bonjour. Bonjour is a combination of zero-configuration networking ("ZeroConf"), multicast DNS (mDNS), and DNS service discovery (DNS-SD) standards published by the Internet Engineering Task Force (IETF), the same group that defined TCP/IP and all of the networking we use today.
To just show only dnssd printers type **/usr/sbin/lpinfo --include-schemes dnssd -v**.
{{{
card825gen2:~$ /usr/sbin/lpinfo --include-schemes dnssd -v
network dnssd://Canon%20TX-3000._ipp._tcp.local/?uuid=00000000-0000-1000-8000-001832104e5a
network dnssd://Canon%20iPR%20Svr%20G250%20V2.1%20US(64%3A59%3AA5)._printer._tcp.local/
network dnssd://HP%20Designjet%20T520%2024in%20%5BD50233%5D._ipp._tcp.local/?uuid=abcd9e8e-4886-85c2-2167-b143d1c2344a
network dnssd://HP%20LaserJet%20P2055dn%20%5B82FCF4%5D._pdl-datastream._tcp.local/
network dnssd://Lexmark%20C2240._ipp._tcp.local/?uuid=584bdd81-d230-49f3-a210-d39ac56492d0
network dnssd://Lexmark%20C2240%20(3)._ipp._tcp.local/?uuid=925cc9ab-7f13-479a-9a82-d9d01aea2472
network dnssd://Lexmark%20C2240%20(4)._ipp._tcp.local/?uuid=1fb63094-a36c-42e5-885e-ce8ebf5c7e0d
network dnssd://Lexmark%20C2240%20(5)._ipp._tcp.local/?uuid=1cf2ae75-abe6-4bf3-b009-375e604a00a2
network dnssd://Lexmark%20C2240%20(6)._ipp._tcp.local/?uuid=04698d71-023d-4da8-a3f5-97d428aea12b
network dnssd://Lexmark%20C2240%20(7)._ipp._tcp.local/?uuid=1b72d98c-8ea0-4b33-a08d-78a89dc256e3
network dnssd://Lexmark%20M3150%20(2)._ipp._tcp.local/?uuid=4b9218da-71a9-42cb-858c-e478817ceb19
network dnssd://Lexmark%20M3250._ipp._tcp.local/?uuid=d672042b-7909-47a2-9077-968f58ad923b
network dnssd://Lexmark%20M3250%20(10)._ipp._tcp.local/?uuid=29fa91fd-eada-4cbe-bd5d-87fdb24dd92d
network dnssd://Lexmark%20M3250%20(14)._ipp._tcp.local/?uuid=67390cc9-aad3-4041-b32d-d5a235d89a39
network dnssd://Lexmark%20M3250%20(2)._ipp._tcp.local/?uuid=876e7e06-54ab-4ca6-a4a6-a80e70f602b5
network dnssd://Lexmark%20M3250%20(3)._ipp._tcp.local/?uuid=50249be5-e50d-4f1a-8739-38ee1f618bd8
network dnssd://Lexmark%20M3250%20(34)._ipp._tcp.local/?uuid=fd53b6a6-3442-4613-921c-2e439ce37d33
network dnssd://Lexmark%20M3250%20(4)._ipp._tcp.local/?uuid=86020859-dbe1-45ad-bdf7-e82dc489e1d5
network dnssd://Lexmark%20M3250%20(5)._ipp._tcp.local/?uuid=e9bc03ef-9a4c-4d84-ad46-8c627e414175
network dnssd://Lexmark%20M3250%20(6)._ipp._tcp.local/?uuid=802f250b-fa5b-43a3-a843-1e8ba23189fa
network dnssd://Lexmark%20M3250%20(8)._ipp._tcp.local/?uuid=b56cbbbe-2d78-4ef3-9b7a-297a6237f84d
network dnssd://Lexmark%20MS510dn._ipp._tcp.local/?uuid=badd5f81-578d-4e6e-8aa0-715bf8e224b3
network dnssd://Lexmark%20MS510dn%20(10)._ipp._tcp.local/?uuid=588460cb-d756-4d87-9239-9d8e910784e2
network dnssd://Lexmark%20MS510dn%20(12)._ipp._tcp.local/?uuid=22ef395a-2897-4d8d-87de-061f52436e50
network dnssd://Lexmark%20MS510dn%20(13)._ipp._tcp.local/?uuid=127f7806-f38e-497d-b053-f4e3137d11e0
network dnssd://Lexmark%20MS510dn%20(5)._ipp._tcp.local/?uuid=7736e5dc-2015-417e-a637-7bc3c023ebb5
network dnssd://Lexmark%20MS510dn%20(8)._ipp._tcp.local/?uuid=279c0534-9d92-4a33-afb5-8df038e3aa63
network dnssd://Lexmark%20MX811._ipp._tcp.local/?uuid=13ffc623-6864-4b67-8ab0-c8e8d827ebd8
network dnssd://Lexmark%20MX811%20(2)._ipp._tcp.local/?uuid=c9b81317-aa68-45b6-a702-09fab9d329d0
network dnssd://Lexmark%20XM3250%20(2)._ipp._tcp.local/?uuid=641a82cd-4fcf-4b91-9a7a-de09460059f7
network dnssd://Lexmark%20XM3250%20(3)._ipp._tcp.local/?uuid=c0bf69ec-fc3e-43e8-9b9c-61711fecbd34
network dnssd://Lexmark%20XM5365._ipp._tcp.local/?uuid=d0c8af1e-9fd8-4c37-8ba1-b9419d1087d0
network dnssd://SERVER-59A5._ipp._tcp.local/
network dnssd://SHARP%20MX-C304W%20(9300735300)._printer._tcp.local/
network dnssd://VS-300i%40RDG7F157A%20(92)._printer._tcp.local/
}}}
== CUPS management web pages ==
To allow access to the management pages on local network the cupsd.conf file must be edited.
{{{
nano /etc/cups/cupsd.conf
}}}
{{{
#
# Configuration file for the CUPS scheduler. See "man cupsd.conf" for a
# complete description of this file.
#
# Log general information in error_log - change "warn" to "debug"
# for troubleshooting...
LogLevel warn
PageLogFormat
# Specifies the maximum size of the log files before they are rotated. The value "0" disables log rotation.
MaxLogSize 1m
# Default error policy for printers
ErrorPolicy stop-printer
# Only listen for connections from the local machine.
#Listen localhost:631
Port 631
Listen /run/cups/cups.sock
# Show shared printers on the local network.
Browsing Yes
BrowseLocalProtocols dnssd
# Default authentication type, when authentication is required...
DefaultAuthType Basic
# Web interface setting...
WebInterface Yes
# Timeout after cupsd exits if idle (applied only if cupsd runs on-demand - with -l)
IdleExitTimeout 60
# Restrict access to the server...
Order allow,deny
Allow @local
# Restrict access to the admin pages...
Order allow,deny
Allow @local
# Restrict access to configuration files...
AuthType Default
Require user @SYSTEM
Order allow,deny
Allow @local
# Restrict access to log files...
AuthType Default
Require user @SYSTEM
Order allow,deny
Allow @local
# Set the default printer/job policies...
# Job/subscription privacy...
JobPrivateAccess default
JobPrivateValues default
SubscriptionPrivateAccess default
SubscriptionPrivateValues default
# Job-related operations must be done by the owner or an administrator...
Order deny,allow
Require user @OWNER @SYSTEM
Order deny,allow
# All administration operations require an administrator to authenticate...
AuthType Default
Require user @SYSTEM
Order deny,allow
# All printer operations require a printer operator to authenticate...
AuthType Default
Require user @SYSTEM
Order deny,allow
# Only the owner or an administrator can cancel or authenticate a job...
Require user @OWNER @SYSTEM
Order deny,allow
Order deny,allow
# Set the authenticated printer/job policies...
# Job/subscription privacy...
JobPrivateAccess default
JobPrivateValues default
SubscriptionPrivateAccess default
SubscriptionPrivateValues default
# Job-related operations must be done by the owner or an administrator...
AuthType Default
Order deny,allow
AuthType Default
Require user @OWNER @SYSTEM
Order deny,allow
# All administration operations require an administrator to authenticate...
AuthType Default
Require user @SYSTEM
Order deny,allow
# All printer operations require a printer operator to authenticate...
AuthType Default
Require user @SYSTEM
Order deny,allow
# Only the owner or an administrator can cancel or authenticate a job...
AuthType Default
Require user @OWNER @SYSTEM
Order deny,allow
Order deny,allow
# Set the kerberized printer/job policies...
# Job/subscription privacy...
JobPrivateAccess default
JobPrivateValues default
SubscriptionPrivateAccess default
SubscriptionPrivateValues default
# Job-related operations must be done by the owner or an administrator...
AuthType Negotiate
Order deny,allow
AuthType Negotiate
Require user @OWNER @SYSTEM
Order deny,allow
# All administration operations require an administrator to authenticate...
AuthType Default
Require user @SYSTEM
Order deny,allow
# All printer operations require a printer operator to authenticate...
AuthType Default
Require user @SYSTEM
Order deny,allow
# Only the owner or an administrator can cancel or authenticate a job...
AuthType Negotiate
Require user @OWNER @SYSTEM
Order deny,allow
Order deny,allow
}}}
The line '''localhost:631''' limits access so that only the page could only be accessed from the 825 itself. Commented this out be placing '''#''' in front and added line '''Port 631''' below it.
Added '''Allow @local''' just above each of the four '''''' lines.
Then restart the cups service
{{{
sudo systemctl restart cups
}}}
The cups management pages should appear at http://:631
It is showing "Not found" but it is shows "CUPS v2.4.2" so it seems the cups web server is running but some page information is missing.
Adding "/admin" to the url shows the administration page, but it is missing style information.
After some research it seems the Yocto recipe "cups-doc" is needed to provide the static page information such as index.html and cups.css. This was added in the 825 image build 2024-01-16. This fixed the problem.
[[Image(cups_mainpage.png)]]
Check a Windows PC that is already configured to use the desired network printer.
[[Image(windows_printer_properties.png)]]
This shows the IP address of the printer.
Click "Administration" on the 825 CUPS page.
[[Image(cups_admin.png)]]
Click "Add Printer."
[[Image(cups_sign_in.png)]]
Type the username and password. Click "Sign in".
[[Image(cups_add_printer1.png)]]
[[Image(cups_add_printer2.png)]]
[[Image(cups_add_printer3.png)]]
Select the printer that looks correct in the list and click "Continue".
[[Image(cups_add_printer_name.png)]]
Make sure the IP address shown matches. The name and description may be changed if desired. Click "Continue".
[[Image(cups_add_printer_model.png)]]
Select the "Model:" "driverless" and click "Add Printer".
[[Image(cups_set_printer_options.png)]]
Click "Set Default Options."
[[Image(cups_set_default_options_success.png)]]
The page should change to show "default options have been set successfully."
[[Image(cups_printer_info.png)]]
Select the maintenance drop down.
[[Image(cups_maintenance_dropdown.png)]]
Select "Print Test Page."
[[Image(cups_unable_to_print_test_page.png)]]
This feature does not currently work. Will investigate further.
Maybe printer test page is also part of cups-doc recipe.
{{{
card825gen2:~$ cat /home/admin/test.txt
test 123
}}}
{{{
card825gen2:~$ lp -d "Canon_iR-ADV_4545_4551_III_UFR_II" /home/admin/test.txt
request id is Canon_iR-ADV_4545_4551_III_UFR_II-31 (1 file(s))
}}}
Page printed with top line "test 123" successfully
[[Image(cups_jobs1.png)]]
{{{
card825gen2:~$ lp -d "Canon_iR-ADV_4545_4551_III_UFR_II" /usr/images/startup.png
request id is Canon_iR-ADV_4545_4551_III_UFR_II-32 (1 file(s))
}}}
The PNG file did not print.
{{{
card825gen2:~$ lp -d "Canon_iR-ADV_4545_4551_III_UFR_II" /usr/images/cardinal_logo.bmp
request id is Canon_iR-ADV_4545_4551_III_UFR_II-33 (1 file(s))
}}}
The cardinal_logo did print.
Maybe png files do not work, but bmp files do.
[[Image(cups_jobs2.png)]]
Printing from application code.
{{{
#include
#include
#include
#include
#include "cairobmp.h"
#define WIDTH 480
#define HEIGHT 500
int main(int argc, char **argv) {
int n;
char tmpFilepath[] = "/tmp/tktprtXXXXXX";
// mkstemp(tmpFilepath);
strcpy(tmpFilepath, "/tmp/tkt.bmp"); // TODO Easier name just for testing
printf("tmpFilename [%s]\n", tmpFilepath);
cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_A1, WIDTH, HEIGHT);
printf("after surface create %d\n", cairo_surface_get_type(surface));
cairo_t *context = cairo_create(surface);
LoadBMPToSurface("/usr/images/cardinal_logo.bmp", surface, 0, 0);
// draw some text
cairo_select_font_face(context, "Arial Black", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size(context, 30);
int x = 20;
int y = 140;
cairo_move_to(context, x, y);
cairo_show_text(context, "Item 1"); // the text we got as a parameter
y += 30;
cairo_move_to(context, x, y);
cairo_show_text(context, "Item 2"); // the text we got as a parameter
y += 30;
cairo_move_to(context, x, y);
cairo_show_text(context, "Item 3"); // the text we got as a parameter
// draw a dotted box
const double pattern[] = { 15.0, 10.0 };
cairo_set_dash(context, pattern, 2, 0);
cairo_set_line_width(context, 5);
cairo_rectangle(context, 5, 105, 400, 300);
cairo_stroke(context);
// finish up
cairo_show_page(context);
cairo_destroy(context);
cairo_surface_flush(surface);
CairoSurfaceToBMP(surface, tmpFilepath);
cairo_surface_destroy(surface);
const char *printerName = "STARSK1_311";
n = cupsPrintFile(printerName, tmpFilepath, "825 ticket", 0, NULL);
// return value is job ID
printf("cupsPrintFile result %d\n", n);
//unlink(tmpFilepath); // TODO This is commented to allow testing - after testing is done uncomment so after print the tmp file will be deleted
return 0;
}
}}}