USB OTG Eth gadget

Hi There,

I’ve got two Pi zeros plugged into a Pi2. The one with vanilla Raspbian is talking nicely to t’interwebs as a USB OTG ethernet gadget through the Pi2. The Volumio zero has the same boot file modifications and interfaces config, but won’t show up.

Does anyone know if this is possible under volumio? Is my Pimoroni phat DAC causing problems? A few posts here suggest that budget DACs might affect USB performance. Any hints?

Cheers

As often happens… solved it myself. Heads up anyone who wants to use USB OTG for networking - don’t forget that the second gadget uses usb1!

For those other non-technicals like me who want a quick reference on how to do it…

To set up your zeros, follow the superb guide at http://blog.gbaman.info/?p=791 to change the two files in your boot directory. You can run:

sudo service --status-all | grep avahi

to check for
" [ + ] avahi-daemon "
to verify the USB gadget service is up.

I have two zeros hanging off one Pi2.

On the host (my Pi2), add this into your /etc/networking/interfaces file:

allow-hotplug usb0
iface usb0 inet static
    address 192.168.2.1
    netmask 255.255.255.0

allow-hotplug usb1
iface usb1 inet static
    address 192.168.2.2
    netmask 255.255.255.0

(continue with usb2 and usb3 for other connections as necessary)

You may also need to allow the zeros to NAT through the device. Assuming you’re sharing a wired connection and no pre-existing iptables policies:

sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

On the first zero, add this into your /etc/networking/interfaces file:

allow-hotplug usb0
iface usb0 inet static
    address 192.168.2.5
    netmask 255.255.255.0
    gateway 192.168.2.1
    dns-nameservers 8.8.8.8

On the next zero, add this into your /etc/networking/interfaces file:

allow-hotplug usb0
iface usb0 inet static
    address 192.168.2.6
    netmask 255.255.255.0
    gateway 192.168.2.2
    dns-nameservers 8.8.8.8

…and repeat for other zeros. Note that usb0 stays as usb0 for each of the zeros, but the gateway matches the USB port on the host Pi.

Make sure you’re matching the correct USB port with the correct usb0/usb1/…

Finally, you will have to forward a port to your Volumio for the web interface. The NAT will allow it to go out and get your tunes/artwork, but you need to be able to control it via port 80.

sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination 192.168.2.6:80

Note that my volumio zero is the one on 192.168.1.6! Also, if your host is already running a server, pick a random port number for --dport and use that.

This allows me to have my Pi2 doing security camera and garage door opener with too much on the GPIO for hats; to connect out to my music player and dismounted parking sensor.

Interesting indeed.
Is Volumio running on the PiZero under usb0 interface?
I was wondering if Volumio would fully work as it seems code is referencing eth0 and wlan0 only as possible network interfaces.
For sure setting config manually into /etc/network/interfaces solves the major part, but you may want to track journalctl and see if there are no important network interface related errors.

Ideally Volumio network manager should enumerate available network interface rather than hard-reference assumed ones.

EDIT: in the meantime you could try renaming usb0 into eth0 following this. This may allow to fully use Volumio network manager probably! :stuck_out_tongue:

I have a terrible confession to make… I ran into a problem and had to switch to the darkside.

https://volumio.org/forum/partial-web-interface-load-t5520.html
I was hitting problems with the interface and - as you point out, usb0 and usb1 did not play well. I ended up exporting the config and using r******io (pardon my blasphemy there!) which worked with all the steps above.

Thanks for the link though - I’m a big fan of volumio and I’ll be swapping the SD card back in to give it a go. Simple but inspired solution to change the interface name.

Cheers