I recently received a pi5 (through an Auvik trial), and I’ve had great fun getting it setup. Right now I have it running CUPS and pihole, but I decided that I want to turbocharge CUPS - we have a Brother DCP-7040 USB printer/scanner, and while CUPS lets me print over the network, I really want to be able to access the scanner over the network. Otherwise, I have to disconnect the device from the Pi everytime I want to scan, then hook it back up again afterwards. Ugh!
I discovered that what I want is USB-over-IP capability, so I found a github project that will install a client portion on my Pi, and a client on my Windows 11 laptop: https://github.com/vadimgrn/usbip-win2
Let’s get to installing! First of all, make sure that the printer is attached to the pi and turned on.
Install required packages for Raspberry Pi:
greg@pi5:~ $ sudo apt install usbip hwdata usbutils
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
usbutils is already the newest version (1:014-1+deb12u1).
The following NEW packages will be installed:
hwdata usb.ids usbip
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,205 kB of archives.
After this operation, 1,978 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bookworm/main arm64 usb.ids all 2024.07.04-0+deb12u1 [208 kB]
Get:2 http://deb.debian.org/debian bookworm/main arm64 hwdata all 0.368-1 [26.5 kB]
Get:3 http://archive.raspberrypi.com/debian bookworm/main arm64 usbip arm64 1:2.0+6.12.25-1+rpt1 [970 kB]
Fetched 1,205 kB in 1s (1,217 kB/s)
Selecting previously unselected package usb.ids.
(Reading database ... 58667 files and directories currently installed.)
Preparing to unpack .../usb.ids_2024.07.04-0+deb12u1_all.deb ...
Unpacking usb.ids (2024.07.04-0+deb12u1) ...
Selecting previously unselected package hwdata.
Preparing to unpack .../hwdata_0.368-1_all.deb ...
Unpacking hwdata (0.368-1) ...
Selecting previously unselected package usbip.
Preparing to unpack .../usbip_1%3a2.0+6.12.25-1+rpt1_arm64.deb ...
Unpacking usbip (1:2.0+6.12.25-1+rpt1) ...
Setting up usb.ids (2024.07.04-0+deb12u1) ...
Setting up usbip (1:2.0+6.12.25-1+rpt1) ...
Setting up hwdata (0.368-1) ...
Processing triggers for man-db (2.11.2-2) ...
Load modules and run the daemon:
greg@pi5:~ $ sudo modprobe -a usbip-core usbip-host
greg@pi5:~ $ sudo usbipd -D
List attached USB devices:
greg@pi5:~ $ lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 004: ID 04f9:01e9 Brother Industries, Ltd DCP-7040
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
greg@pi5:~ $ usbip list -l
- busid 3-2 (04f9:01e9)
Brother Industries, Ltd : DCP-7040 (04f9:01e9)
Bind to the printer:
greg@pi5:~ $ sudo usbip bind -b 3-2
usbip: info: bind device on busid 3-2: complete
Now, configure my Windows 11 laptop!
Download and install the latest client 0.9.7.2
List the USB-over-IP devices available on the Pi:
C:\Users\Greg>usbip list -r pi5
Exportable USB devices
======================
3-2 : Brother Industries, Ltd : DCP-7040 (04f9:01e9)
: /sys/devices/platform/axi/1000120000.pcie/1f00300000.usb/xhci-hcd.1/usb3/3-2
: (Defined at Interface level) (00/00/00)
Finally, attach the remote device to your computer. The USB-over-IP driver will make it look like a local device attached to a USB port:
C:\Users\Greg>usbip.exe attach -r pi5 -b 3-2
succesfully attached to port 1
Of course, the problem is that whenever the printer is powered off, the device obviously is unreachable, but when it’s powered back on, Linux doesn’t automatically bind it again. Fortunately, we can use udev
to run an action whenever it detects the printer.
First, use dmesg to find out where the printer is connected:
greg@pi5:~ $ dmesg
...
[708387.363296] veth50c9534 (unregistering): left promiscuous mode
[708387.363299] docker0: port 1(veth50c9534) entered disabled state
[708430.656914] usb 3-2: new full-speed USB device number 6 using xhci-hcd
[708430.809591] usb 3-2: New USB device found, idVendor=04f9, idProduct=01e9, bcdDevice= 1.00
[708430.809596] usb 3-2: New USB device strings: Mfr=0, Product=0, SerialNumber=3
[708430.809599] usb 3-2: SerialNumber: 000F8N333004
[708430.814635] usblp 3-2:1.0: usblp0: USB Bidirectional printer dev 6 if 0 alt 0 proto 2 vid 0x04F9 pid 0x01E9
[708447.412092] docker0: port 1(veth353fe11) entered blocking state
...
My printer is connected to /dev/usb/lp0
, so let’s grab some information from that device. I’ll find the serial number that it’s reporting, which I’ll use to create a rule.
greg@pi5:~ $ udevadm info -a -p $(udevadm info -q path -n /dev/usb/lp0) | grep serial
ATTRS{serial}=="000F8N333004"
ATTRS{serial}=="xhci-hcd.1"
The serial number is 000F8N333004
. Let’s see which udev rules exist on my Pi already:
greg@pi5:~ $ ls /etc/udev/rules.d -al
total 16
drwxr-xr-x 2 root root 4096 May 22 15:58 .
drwxr-xr-x 4 root root 4096 May 6 09:23 ..
-rw-r--r-- 1 root root 2535 Apr 23 09:09 99-com.rules
Only a rule with ID #99. I’ll create a rule to run before Rule 99: sudo nano /etc/udev/rules.d/20-brother.rules
I only need 1 line for the rule: ACTION=="add", ATTRS{serial}=="000F8N333004", RUN+="/bin/sh -c 'sudo usbip bind -b 3-2'"
Basically, everytime udev sees that a device with Serial=000F8N333004 is ADDed, run the command ‘sudo usbip bind -b 3-2’, which will use usbip to bind to busid 3-2. I tested this a couple of times by turning the printer off, then on, and it’s properly bound each time.
Now, I pair this with a powershell script on my laptop that runs every few minutes via. Task Scheduler. The only hiccup that I’ve found is that full-screen applications (like DOSBox or Dawn Of War) exit full-screen mode when the script runs.
$output = & "C:\Program Files\USBip\usbip.exe" list -r pi5
$targetLine = " 3-2 : Brother Industries, Ltd : DCP-7040 (04f9:01e9)"
foreach ($line in $output) {
if ($line -eq $targetLine) {& "C:\Program Files\USBip\usbip.exe" attach -r pi5 -b 3-2 ; break }
}
Whenever the printer is turned on, within 5 minutes my laptop will attach it and it’ll appear as a directly-connected USB printer/scanner.
C:\Users\Greg\OneDrive>usbip port
Imported USB devices
====================
Port 01: device in use at Full Speed(12Mbps)
Brother Industries, Ltd : DCP-7040 (04f9:01e9)
-> usbip://pi5:3240/3-2
-> remote bus/dev 003/011
References
An article I referenced when figuring this out was: