Sharing USB Devices over Wifi using Arduino Yún


In this tutorial, we show how to use the Arduino Yún to connect a USB device through Wifi to your Linux based computer. We rely on the USB/IP project that allows USB device sharing over IP networks. This utility is really useful and has many applications. A simple one is to turn a plain USB webcam into one that you can access remotely through Wifi. But, it can apply to virtually any USB device and make it available remotely, paving the way to the Internet of things.


.



Server Side (Yún)
1) First and foremost, you need to ensure that you have an up to date version of the OpenWrt-Yún. If you acquired your Yún prior to september 2014, you likely need to upgrade it.

2) Assuming that the Yún is up and running, you need to change the Wifi setup. Your board should access a Wifi network that is connected to the Internet.

3) To install on the Yún usbip we’ll be using the opkg package manager. The opkg utility allows to download and install OpenWrt packages. Login through SSH as explained in our previous post. Then, update the list of available packages by evaluating the following command line in your terminal:

opkg update

As a result, you should be notified about downloaded and configurations as shown below:

Downloading http://downloads.arduino.cc/openwrtyun/1/packages/Packages.gz.
Updated list of available packages in /var/opkg-lists/attitude_adjustment.
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/Packages.sig.
Signature check passed.

4) Install the usbip-server package that provides utilities for USB forwarding over IP:

opkg install usbip-server

The result should be a series of messages informing you about the ongoing installation. They should look like the following:


Installing usbip-server (1.1.1-2) to root...
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/usbip-server_1.1.1-2_ar71xx.ipk.
Installing usbip (1.1.1-2) to root...
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/usbip_1.1.1-2_ar71xx.ipk.
Installing libsysfs (2.1.0-2) to root...
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/libsysfs_2.1.0-2_ar71xx.ipk.
Installing libwrap (7.6-1) to root...
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/libwrap_7.6-1_ar71xx.ipk.
Installing kmod-usbip (3.3.8-1) to root...
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/kmod-usbip_3.3.8-1_ar71xx.ipk.
Installing usbip-client (1.1.1-2) to root...
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/usbip-client_1.1.1-2_ar71xx.ipk.
Installing glib2 (2.28.8-1) to root...
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/glib2_2.28.8-1_ar71xx.ipk.
Installing kmod-usbip-client (3.3.8-1) to root...
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/kmod-usbip-client_3.3.8-1_ar71xx.ipk.
Installing kmod-usbip-server (3.3.8-1) to root...
Downloading http://downloads.arduino.cc/openwrtyun/1/packages/kmod-usbip-server_3.3.8-1_ar71xx.ipk.
Configuring kmod-usbip.
Configuring libsysfs.
Configuring libwrap.
Configuring usbip.
Configuring glib2.
Configuring kmod-usbip-client.
Configuring usbip-client.
Configuring kmod-usbip-server.
Configuring usbip-server.

5) To provides USB/IP clients access to exported USB devices, start usbipd on the Yún by evaluating:

usbipd -D &

We use the -D option to make usbipd run as a deamon process. For the curious, the daemon accepts connections from USB/IP clients on TCP port 3240.

6) Now, we can share a USB device connected to the Yún. But, prior to plugin it, list usb devices embedded on your board by evaluating the following command. This will make our life easier to identify the ID of the device later.

usbip list -l

The list should ressemble the following:

Local USB devices
=================
- busid 1-1 (058f:6254)
1-1:1.0 -> hub

- busid 1-1.4 (058f:6366)
1-1.4:1.0 -> usb-storage

7) Plug your device to the USB host port of the Yún and list again USB devices (usbip list -l). You see that a new device shows up. In our example below, it is marked as unknown, and appears at the second position. The important information you are looking for is the bus ID, which is in our case 1-1.1.


Local USB devices
=================
- busid 1-1 (058f:6254)
1-1:1.0 -> hub

- busid 1-1.1 (1267:0201)
1-1.1:1.0 -> unknown

- busid 1-1.4 (058f:6366)
1-1.4:1.0 -> usb-storage

8) Time to share the USB device using the following command:

usbip bind -b 1-1.1

If everything goes well, you’ll get the answer that the binding was successful:

bind device on busid 1-1.1: complete

9) Now, if you list again devices using usbip list -l you’ll see that your device is bound to usbip.

Local USB devices
=================
- busid 1-1 (058f:6254)
1-1:1.0 -> hub

- busid 1-1.1 (1267:0201)
1-1.1:1.0 -> usbip-host

- busid 1-1.4 (058f:6366)


Client Side (Computer Running Linux)
A) Now you should be able to connect to USB device from your computer. A compatible version of usbip package should be installed. In our experiment, we work with Ubuntu 14.04LTS. The usbip package need to be installed. Unfortunately, the one available from Ubuntu repositories if outdated: it’s the very old version 0.1.7. A workaround is to install a Debian package. Ignore version 1.1.1 of usbip. It has a bug that forbids detaching. We definitely recommend usbip 2.0, which is available for Debian Sid. Beside fixing the detaching bug, it has also the port command that allows listing virtual ports in use. Once you have downloaded the usbip debian package, install it by evaluating the following command line:

sudo dpkg -i usbip_2.0+3.16-2_i386.deb

B) Now you can use your linux box as usbip client. To do so, you need to get the IP address of your Yún. Just open the http://arduino.local url in your browser and connect to display the network info of the board as explained in step 2 of our previous tutorial. The IP of your board should be there. In our experiment, it shows: 192.168.1.39

C) On your computer list usb devices shared by the Yún board by evaluating:

usbip list -r 192.168.1.39

Since we shared only one device on the Yún, there should only one displayed. In our experiment we used a USB mouse, and indeed, it’s there.


Exportable USB devices
======================
- 192.168.1.39
1-1.1: Logic3 / SpectraVideo plc : A4Tech SWOP-3 Mouse (1267:0201)
: /sys/devices/platform/ehci-platform/usb1/1-1/1-1.1
: (Defined at Interface level) (00/00/00)
: 0 - Human Interface Device / Boot Interface Subclass / Mouse (03/01/02)

D) Before connecting to the remote USB device, ensure that the kernel module that supports virtual usb ports (Virtual Host Controller Interface) is loaded by evaluating:

sudo modprobe vhci-hcd

E) Now, we can perform the actual connection by evaluating the following command line. The first parameter is the IP of the Yún. The second parameter is the ID of the bus related to our USB device. We had obtained it at step 7 on the server side (Yún).

sudo usbip attach -r 192.168.1.39 -b 1-1.1

Et voilà, you can start using your device. In our example, it’s a mouse. So, we can use it to control the GUI of our computer. Isn’t it cool! :-).


Cleaning Up the Client Side (Computer Running Linux)
Once you are done with your USB device, you can “unplug” it from the virtual USB port of your computer. This is a two step operation.

1) First, evaluate the following to get the port number used to connect to the remote USB device.

sudo usbip port

You’ll see that your device in a list, with the assigned port number 0.


Imported USB devices
====================
Port 00: <Port in Use> at Low Speed(1.5Mbps)
unknown vendor : unknown product (1267:0201)
3-1 -> usbip://192.168.1.39:3240/1-1.1
-> remote bus/dev 001/003


.

2) Now, you can use the port number as a parameter of the following command line to actually stop using the shared USB device.

sudo usbip detach -p 0

If you list again used port numbers (sudo usbip port) the list should be empty.


Imported USB devices
====================


Cleaning Up the Server Side (Yún)
If you want stop sharing the device on the Yún, simply evaluate the following command line. The parameter (1-1.1) is the ID of the bus of the USB device.

usbip unbind -b 1-1.1

If you don’t want to share any other device, don’t forget to stop the usbipd server launched at step 5 of the server side procedure.

4 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top