前言
最近基地的打印机突然又好起来了。
因为基地的打印机型号比较老——HP LaserJet 1020,没有无线打印的功能。所以之前一位学长1 用树莓派配置了打印机的无线打印功能,但是后来发现有一些问题,有时候发送打印请求树莓派无法接收,而且不知道为何,学长之前用的是树莓派自己创建WiFi,连接对应WiFi才能打印,但是这个显然不是最优的解决办法。
考虑到之间已经配置好基地WiFi,我决定重新配置一下打印功能,使其连接基地WiFi即可实现局域网打印。
配置过程
查看树莓派内容
通过ssh连接树莓派,发现里面除了Github上的一个开源项目create_ap ,就没有什么其他的内容了,连接屏幕后发现没有任何图像信号,无从下手,因此考虑重新刷机。
对树莓派进行刷机
把数据备份了一下,看了一下树莓派版本是2015年生产的 Raspberry Pi 3 model B V1.2
,是老古董了。
去官网看了一下,因为我对Ubuntu比较熟悉,我计划安装一个 Ubuntu20.04版本的,考虑到版本比较老,就装了server版本的,相比与desktop版本负担更小一些。
其实就是下一个官方的软件,Raspberry Pi Imager
,直接用读卡器对树莓派的存储卡刷机即可。
配置网络相关
Ubuntu的server版本有个比较蛋疼的问题就是上网比较困难,如果是用的学校网线,必须要PPPOE拨号才能上网,但是server版本居然没有 net-tools
和 network-manager
,连接WiFi啥的试了很多办法但还是没有什么作用。
解决办法:用网线直接连接树莓派和有网的路由器,安装 net-tools
和 network-manager
,执行
$ sudo nmtui
选择 Activate a connect
连接无线的WiFi,执行
$ sudo ifconfig
查看WiFi对应的IP,至此,树莓派可以摆脱屏幕,我们可以使用电脑进行使用 ssh
连接。
这里也可以使用网线进行连接,具体操作如下
1. 用网线连接树莓派和自己的电脑。
2. 在树莓派的利用 nmtui
选择 Edit a connection
,Add一个Ethernet connect,对IPv4 CONFIGURATION进行设置,首先讲 Automatic
设置为 Manual
,设置 Address
为 静态IP 如 192.168.3.2
,Gateway
设置为 192.168.3.1
。
3. 在自己电脑利用 nmtui
同上不过设置 Address
为 192.168.3.3
,只要是位于同一网段即可。
4. 这时候就可以通过网线进行 ssh
连接了。
配置cups
以下大多参考:如何正确地用树莓派共享打印机
大佬言:
其实,这一步的工作量非常少,因为软件包 CUPS 就是为共享打印机而生。我们要做的只是将打印机用 USB 线缆连接树莓派,然后安装并配置 CUPS。
然而,事实并非如此。
换源
在安装之前需要换源,如果不换源的话,安装会十分缓慢,具体的流程可以看上面的blog,因为我们基地的WiFi自带代理,因此这一步我没有做。
安装驱动及打印程序
- 首先更新源并安装Hp的打印机驱动
hplip
$ sudo apt update
$ sudo apt install hplip
- 然后安装Apple开源的远程打印工具
cups
,并配置相应权限
$ sudo apt install cups # Install cups package
$ sudo usermod -aG lpadmin pi # Add user to lpadmin group,pi is your user name
$ sudo cupsctl --remote-any # open remote access
- 然后使用在同一局域网的电脑,访问
https://树莓派IP:631
,可以进入如下界面,按照下图设置右侧的Server Settings
- 连接打印机和树莓派,点击Add Printer添加打印机,在弹出的窗口中输入对应的用户信息,使用在上一步中用户组中添加的用户
- 然后按着一步步的指引,选择HP LaserJet 1020打印机,然后按照提示,选择和名称对应的驱动,我们会发现 LaserJet 1020 对应驱动会提示:HP laserjet requires proprietary plugin,也就是我们不仅需要这个通用的驱动,而且需要一些额外的插件,打印机才能正常工作。
查阅资料发现:HP官方已经给出了说明,我们需要查看hplip版本,然后安装对应的驱动插件。
- 首先我们查看一下版本,发现是3.20.3版本
$ sudo apt show hplip Package: hplip Version: 3.20.3+dfsg0-2 Priority: optional Section: utils Origin: Ubuntu Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Original-Maintainer: Debian Printing Team <debian-printing@lists.debian.org> Bugs: https://bugs.launchpad.net/ubuntu/+filebug Installed-Size: 518 kB
- 然后在 插件列表 中找到 3.20.3 对应的
hplip-3.20.3-plugin.run
和hplip-3.20.3-plugin.run.asc
,使用wget下载到树莓派本地。 - 运行
hp-setup -i
使用命令行进行安装,按照提示命令,进行插件的安装。
这里建议提前下好安装,而不是直接联网下载,速度较快,指定路径需要为绝对路径- 至此,我们可以尝试使用手机或者电脑搜索打印机来进行打印测试,没有其他意外的话,可以发现打印成功!
结语
其实这个配置过程远没有这么简单,期间还有很多小问题,但是大致的流程大概就是如上述所示,全写出来可能太啰嗦,大家如果配置过程中遇到更多的疑问,可以在下方评论一起探讨~
9 条评论
博主好,我的打印机是1007,也想用树莓派实现无线共享,但是安装了几次都是按照好但是不能打印,可能就是因为缺少插件的原因?你这个方法,1007也可以吗?
赵同学您好,我刚看了一下,HP Laserjet P1007 Printer好像也是需要插件的
https://developers.hp.com/hp-laserjet-p1007-printer
https://support.hp.com/us-en/drivers/selfservice/hp-laserjet-p1007-printer/3435678
这是我找的几个链接,您可以看一下
大佬能不能帮我看一下这个是什么意思?安装不起来啊。
root@ubuntu:~# sudo apt install hplip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
acl avahi-daemon colord colord-data cups cups-browsed cups-client cups-common cups-core-drivers cups-daemon cups-filters cups-filters-core-drivers
cups-ipp-utils cups-ppdc cups-server-common fontconfig-config fonts-dejavu-core fonts-droid-fallback fonts-noto-mono fonts-urw-base35 ghostscript hplip-data
libavahi-client3 libavahi-common-data libavahi-common3 libavahi-core7 libavahi-glib1 libcairo2 libcolord2 libcolorhug2 libcups2 libcupsfilters1 libdaemon0
libexif12 libfontconfig1 libfontembed1 libfreetype6 libgd3 libgphoto2-6 libgphoto2-l10n libgphoto2-port12 libgs9 libgs9-common libhpmud0 libieee1284-3
libijs-0.35 libimagequant0 libjbig0 libjbig2dec0 libjpeg-turbo8 libjpeg8 liblcms2-2 liblouis-data liblouis20 liblouisutdml-bin liblouisutdml-data
liblouisutdml9 libmysqlclient21 libnss-mdns libopenjp2-7 libpaper-utils libpaper1 libpixman-1-0 libpoppler-cpp0v5 libpoppler97 libqpdf26 libsane
libsane-common libsane-hpaio libsensors-config libsensors5 libsnmp-base libsnmp35 libtiff5 libwebp6 libwebpdemux2 libwebpmux3 libxcb-render0 libxcb-shm0
libxpm4 libxrender1 mysql-common poppler-data poppler-utils printer-driver-hpcups printer-driver-postscript-hp python3-olefile python3-pil python3-renderpm
python3-reportlab python3-reportlab-accel sane-utils ssl-cert update-inetd
Suggested packages:
avahi-autoipd colord-sensor-argyll cups-bsd foomatic-db-compressed-ppds | foomatic-db cups-pdf smbclient antiword docx2txt imagemagick fonts-noto
fonts-freefont-otf | fonts-freefont-ttf fonts-texgyre ghostscript-x hplip-doc hplip-gui python3-notify2 system-config-printer libgd-tools gphoto2
liblcms2-utils ooo2dbk rtf2xml avahi-autoipd | zeroconf lm-sensors snmp-mibs-downloader fonts-japanese-mincho | fonts-ipafont-mincho fonts-japanese-gothic
| fonts-ipafont-gothic fonts-arphic-ukai fonts-arphic-uming fonts-nanum python-pil-doc python3-pil-dbg python3-renderpm-dbg pdf-viewer
python3-egenix-mxtexttools python-reportlab-doc unpaper openssl-blacklist
The following NEW packages will be installed:
acl avahi-daemon colord colord-data cups cups-browsed cups-client cups-common cups-core-drivers cups-daemon cups-filters cups-filters-core-drivers
cups-ipp-utils cups-ppdc cups-server-common fontconfig-config fonts-dejavu-core fonts-droid-fallback fonts-noto-mono fonts-urw-base35 ghostscript hplip
hplip-data libavahi-client3 libavahi-common-data libavahi-common3 libavahi-core7 libavahi-glib1 libcairo2 libcolord2 libcolorhug2 libcups2 libcupsfilters1
libdaemon0 libexif12 libfontconfig1 libfontembed1 libfreetype6 libgd3 libgphoto2-6 libgphoto2-l10n libgphoto2-port12 libgs9 libgs9-common libhpmud0
libieee1284-3 libijs-0.35 libimagequant0 libjbig0 libjbig2dec0 libjpeg-turbo8 libjpeg8 liblcms2-2 liblouis-data liblouis20 liblouisutdml-bin
liblouisutdml-data liblouisutdml9 libmysqlclient21 libnss-mdns libopenjp2-7 libpaper-utils libpaper1 libpixman-1-0 libpoppler-cpp0v5 libpoppler97 libqpdf26
libsane libsane-common libsane-hpaio libsensors-config libsensors5 libsnmp-base libsnmp35 libtiff5 libwebp6 libwebpdemux2 libwebpmux3 libxcb-render0
libxcb-shm0 libxpm4 libxrender1 mysql-common poppler-data poppler-utils printer-driver-hpcups printer-driver-postscript-hp python3-olefile python3-pil
python3-renderpm python3-reportlab python3-reportlab-accel sane-utils ssl-cert update-inetd
0 upgraded, 95 newly installed, 0 to remove and 0 not upgraded.
Need to get 4102 kB/38.2 MB of archives.
After this operation, 148 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Ign:1 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 libtiff5 arm64 4.1.0+git191117-2ubuntu0.20.04.1
Ign:2 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 libmysqlclient21 arm64 8.0.26-0ubuntu0.20.04.2
Ign:3 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 libgs9-common all 9.50~dfsg-5ubuntu4.2
Ign:4 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 libgs9 arm64 9.50~dfsg-5ubuntu4.2
Ign:5 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 ghostscript arm64 9.50~dfsg-5ubuntu4.2
Err:1 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 libtiff5 arm64 4.1.0+git191117-2ubuntu0.20.04.1
404 Not Found [IP: 91.189.88.152 80]
Err:2 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 libmysqlclient21 arm64 8.0.26-0ubuntu0.20.04.2
404 Not Found [IP: 91.189.88.152 80]
Err:3 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 libgs9-common all 9.50~dfsg-5ubuntu4.2
404 Not Found [IP: 91.189.88.152 80]
Err:4 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 libgs9 arm64 9.50~dfsg-5ubuntu4.2
404 Not Found [IP: 91.189.88.152 80]
Err:5 http://ports.ubuntu.com/ubuntu-ports focal-updates/main arm64 ghostscript arm64 9.50~dfsg-5ubuntu4.2
404 Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/pool/main/t/tiff/libtiff5_4.1.0+git191117-2ubuntu0.20.04.1_arm64.deb 404 Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/pool/main/m/mysql-8.0/libmysqlclient21_8.0.26-0ubuntu0.20.04.2_arm64.deb 404 Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/pool/main/g/ghostscript/libgs9-common_9.50~dfsg-5ubuntu4.2_all.deb 404 Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/pool/main/g/ghostscript/libgs9_9.50~dfsg-5ubuntu4.2_arm64.deb 404 Not Found [IP: 91.189.88.152 80]
E: Failed to fetch http://ports.ubuntu.com/ubuntu-ports/pool/main/g/ghostscript/ghostscript_9.50~dfsg-5ubuntu4.2_arm64.deb 404 Not Found [IP: 91.189.88.152 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
root@ubuntu:~#
执行一下 sudo apt update
这样好像没啥效率,同学加一下QQ详聊吧,反馈迅速一些,2459958352
已经搞定了,谢谢大佬,最后换了树莓派os,按照你的方法安装成功了,前面安装了好几次都无法打印,感谢感谢!
好耶!
感谢
照着博主的教程,我把我家的打印机也配好了,写得很不错
博主写的东西很实用,受教了