Skip to content

Networking with Windows over USB

fijam edited this page Jul 5, 2021 · 1 revision

This page is for devices which do not feature WiFi such as Raspberry Pi Zero (non-W edition).

Since the script works over a RESTful API we need to be in a network with the computer running the music player with beefweb. Fortunately, this can be achieved with a RNDIS Gadget module, which essentially provides Ethernet over USB.

Briefly:

  1. In /boot/config.txt add dtoverlay=dwc2
  2. In /boot/cmdline.txt add modules-load=dwc2,g_multi
  3. In /etc/modprobe.d/g_multi.conf add options g_multi host_addr=11:22:33:11:22:33 (change the MAC to what you want)
  4. Might as well enable SSH service while we are at it systemctl enable ssh

Now, if you plug in the data USB into your PC a new RNDIS device will pop up in Device Manager. It won't automatically install drivers (possible, but needs extra setup) so just select them manually through 'Browse my computer for drivers - Let me pick from a list - Network Adapters - Microsoft - Remote NDIS Compatible Device'. A new network connection will pop up. At this point you should be able to SSH into your Pi at raspberrypi.local thanks to some avahi magic. Check if you can ping both ways.

Now you might be thinking 'hey this wasn't too bad' but we are not done yet. The RNDIS network connection is automatically set as a public network, and you can't seem change that in the UI because Microsoft is bad at computers. You have two options.

  1. Rename the RNDIS network (e.g. to PiZero) and add is as a private network from PowerShell: Set-NetConnectionProfile -InterfaceAlias "PiZero" -NetworkCategory Private You have to do this every time the network is reconnected, even after suspend/resume.

or

  1. Allow incoming traffic to the beefweb plugin on the public networks from PowerShell: New-NetFirewallRule -DisplayName 'Foobar-beefweb' -Profile 'Public' -Direction Inbound -Action Allow -Protocol TCP -LocalPort 8880

Now check if you can access the API endpoint from Raspberry Pi with curl 192.168.137.1:8880/api/player (or whatever the IP of the Windows host is).