[LINUX] USB over ethernet using Raspberry pi

Introduction

A cohesive article on how to share ** multiple ** USB devices over a network using USB / IP (universal serial bus extension over IP network) ** for free ** (without paying license fees) I didn't have it, so I wrote it.

However, it is a personal memo, so I would appreciate it if you could see it for reference.

Image of what you want to do

Connect a device such as a USB memory to the Raspberry Pi and exchange the information with other PCs via a wired LAN.

Similar technique

Similar methods include ** VirtualHere ** and IO-DATA ** net.USB **. ** Virtual Here ** can be used simultaneously up to 1 device in the free version. To connect to the network additionally, you cannot bind multiple devices without paying a license fee of nearly $ 50 per device. It's very easy to set up, so if you only have one device to share, this is fine. ** net.USB ** is a product for network sharing, so it naturally costs money to install and is not compatible with linux.

So, this time, I tried with ** free and open technology that doesn't cost money **.

environment

server | Raspberry Pi 3 Model B, Raspbian GUN/Linux 10 client | Ubuntu 18.04.05 LTS Communication is performed via a router and a wired LAN.

What is usb / ip

The result of a project to share USB devices over IP networks. It was developed by NAIST around 2007 and was merged into the kernel in Linux 2.6.38.

The USB / IP project aims to develop a general purpose USB device sharing system over IP networks. To share USB devices between computers, USB / IP encapsulates "USB I / O messages" in TCP / IP payloads and communicates between computers. ArchWiki

Please read the reference URL for details.

How to use

To connect the device, bind with server (raspi) and then attach with client (ubuntu). To remove it, detach it on the client and then unbind it on the server.

Explanation of terms

It may not be accurate because it is my image. ** bind ** | To be able to share on the server side. When viewed from the server, binding makes the device appear to be disconnected. ** attach ** | Mount a device that is in a sharable state (bind) on the client side. ** detach ** | To unmount the attached device. For the device to be detached, check the port and specify the port (the method will be described later).


setup

You only need to run it the first time.

Setting up server on Raspberry pi

Settings that should be done with Raspberry Pi. The setting on the raspberry pi side is fixed IP,

$ sudo apt install usbip

It's pretty easy to do by hitting or googled, so omit it. I plan to add it soon.

Client setup on ubuntu 18.04

Settings to be done on ubuntu. For USB / IP, it is necessary to open port 3240 in advance. Open the port using ufw.

$ sudo ufw allow 3240/tcp 
$ sudo ufw enable
$ sudo ufw reload

USP / IP is in a package called linux-tools-generic, so install it using apt.

$ sudo apt install hwdata linux-tools-generic

Commands that you usually use on the server

The commands that need to be executed on the raspberry pi side are shown below. This time, the ip of raspberry pi used in the experiment is fixed at 192.168.0.161. bind Allow sharing on the server side. When viewed from the server, binding makes the device appear to be disconnected.

$ ​sudo modprobe usbip_host
$ usbip list -l

// Check the kernel module load and the busy (= ?????) of the device you want to bind

$ sudo usbip bind -b ?????(ex.1-1.2)
$ sudo usbipd -D

// Specify the bus id and bind, and start the daemon. unbind Detach (described later) on the client and then unbind.

$ sudo usbip unbind -b ?????(ex.1-1.2)

Commands usually used by client

The commands that need to be executed on the ubuntu (main PC) side are shown below. attach Mount the device that is in a sharable state (bind) on the client side.

$ sudo modprobe vhci-hcd
$ /usr/lib/linux-tools/$(uname -r)/usbip list -r 192.168.0.161(This IP is from Raspberry Pi)

// Check the loading of the kernel module and the busy (= ?????) of the device you want to bind. // You can enter $ (uname -r) in path with tab completion.

$ sudo /usr/lib/linux-tools/$(uname -r)/usbip attach -r 192.168.0.161 -b ?????(ex.1-1.2)

detach Unmount the attached device. For the device to be detached, check the port and specify the port.

$ /usr/lib/linux-tools/$(uname -r)/usbip port

// Find out the port (= ??) of the device you want to detach

$ sudo /usr/lib/linux-tools/$(uname -r)/usbip detach -p ??(ex.00)

// Specify port and perform detach.


The approximate usage is like this. By the way, the part up to / usr / lib .... / usbip may be easier to use if you devise a symbolic link.

reference

Recommended Posts

USB over ethernet using Raspberry pi
Indoor monitoring using Raspberry Pi
Try using ArUco on Raspberry Pi
Using a webcam with Raspberry Pi
Connect two USB cameras to Raspberry Pi 4
Detect "brightness" using python on Raspberry Pi 3!
USB boot on Raspberry Pi 4 Model B
Make Raspberry Pi speak Japanese using OpenJtalk
Run servomotor on Raspberry Pi 3 using python
Detect temperature using python on Raspberry Pi 3!
Raspberry Pi backup
Detect slide switches using python on Raspberry Pi 3!
Try using a QR code on a Raspberry Pi
Detect magnet switches using python on Raspberry Pi 3!
Automatic launch of Raspberry Pi programs using Systemd
Send data from Raspberry Pi using AWS IOT
Sound the buzzer using python on Raspberry Pi 3!
Create a visitor notification system using Raspberry Pi
Connect your Raspberry Pi to your smartphone using Blynk
Machine learning with Raspberry Pi 4 and Coral USB Accelerator
Build an OpenCV4 environment on Raspberry Pi using Poetry
Create a color sensor using a Raspberry Pi and a camera
Using the digital illuminance sensor TSL2561 with Raspberry Pi
What is Raspberry Pi?
GPGPU with Raspberry Pi
Using Akizuki Denshi's 4WD car FT-MC-004 with Raspberry Pi
Monitor temperature using Raspberry Pi + Alibaba cloud IoT platform
pigpio on Raspberry pi
Try using the temperature sensor (LM75B) on the Raspberry Pi.
Raspberry Pi video camera
Raspberry Pi Bad Knowledge
Let's do Raspberry Pi?
USB boot with Raspberry Pi 4 Model B (3) LVM edition
Control power on / off of USB port of Raspberry Pi
DigitalSignage with Raspberry Pi
Raspberry Pi 4 setup memo
Output to "7-segment LED" using python on Raspberry Pi 3!
Cython on Raspberry Pi
Display USB camera video with Python OpenCV with Raspberry Pi
Raspberry Pi system monitoring
Cross-compiling for Raspberry Pi Zero on Debian-Try using shared libraries
Detect "temperature (using A / D converter)" using python on Raspberry Pi 3!
Access google spreadsheet using python on raspberry pi (for myself)
I tried using the DS18B20 temperature sensor with Raspberry Pi
I tried to automate [a certain task] using Raspberry Pi
Check! Let's develop Raspberry Pi Zero remotely-Try using Arafruit WebIDE
How to get temperature from switchBot thermo-hygrometer using raspberry Pi
Construction of Cortex-M development environment for TOPPERS using Raspberry Pi
Get the weather using the API and let the Raspberry Pi speak!
Introduced python3-OpenCV3 to Raspberry Pi
Mutter plants with Raspberry Pi
Install Raspberry Pi OS (Raspbian)
I talked to Raspberry Pi
Introducing PyMySQL to raspberry pi3
Raspberry Pi + Python + OpenGL memo
Raspbian initial settings (Raspberry Pi 4)
raspberry pi 1 model b, python
Introduced pyenv on Raspberry Pi
Use NeoPixel on Raspberry Pi
Install OpenCV4 on Raspberry Pi 3
Install TensorFlow 1.15.0 on Raspberry Pi