Connecting a Balena RPi Zero through a Balena RPI4 (!)

Hi,

I have a project which for “reasons” I think would work well with a Raspberry Pi Zero running Balena powered from the USB of a Raspberry Pi 4 running Balena (PoE).

My RPi4 is running fine. What I would like to do is configure the Pi Zero as an RNDIS gadget and then bridge/NAT/other the internet connection through the Raspberry Pi 4.

I am fairly au fait with gadgets and can probably work out bridging/NAT somehow but I wondered if anybody had already done this or there was a project I might leverage?

Cheers!

Alex

This is definitely possible as NetworkManager can take care of this. Once you setup the RPi Zero in Ethernet gadget mode and the usb0 interface appears on the RPi 4, you can add the following connection profile:

[connection]
id=usb
interface-name=usb0
type=ethernet

[ipv4]
method=shared

[ipv6]
method=ignore

The ipv4.method shared will provide Internet connectivity to the RPi Zero through the RPi 4.

For more information on how to enable this connection profile please check our Networking document: https://www.balena.io/docs/reference/OS/network/2.x/

2 Likes

Awesome - will give it a go. Thanks!

I’ve been wading through a bunch of weird stuff here so though I’d note down for when I need to do this again…

  • I got the USB gadget up fine by adding dwc2 and g_ether modules
  • The usb0 device doesn’t come up though
  • I added auto usb0 and settings into /etc/network/interfaces but it doesn’t seem to be used any more(!)
  • I saw that the gadget is explicitly unmanaged in /lib/udev/rules.d/85-nm-unmanaged.rules so NM should leave it alone for ifupdown but I suspect the service to manage this is no longer present or running so interfacesdefinitions aren’t being handled
  • Instead I modified the rules to make the gadget managed and added the following system connection
[connection]
id=usb0
uuid=ca3e68f2-c84c-4286-9714-7725b4495149
type=ethernet
interface-name=usb0
permissions=
autoconnect=true

[ethernet]
mac-address-blacklist=

[ipv4]
dns-search=
method=manual
address1=192.168.7.2/24
gateway=192.168.7.1

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=link-local

[proxy]

This seems to get usb0 up and configured for me but it doesn’t co-exist with the WiFi on my RPi0

Next I needed to comment out this on Ubuntu to stop the usb network interface being renamed

/lib/udev/rules.d/80-net-setup-link.rules

Hi Alex,

It sounds like you’re using the RPi WiFi as an access point and a WiFi connection for the RPi4, correct? For example, you don’t have a second wired or wireless network on the RPi 4, just the one? Sounds like you’ve put together a good solution.

John

1 Like

Hey @jtonello - actually that’s not what I am doing :slight_smile:

This system is in a bee hive and we wanted to try to avoid WiFi as it might upset the bees. We also need to power the system anyway so I decided to use a Power-over-Ethernet hat on the Raspberry Pi 4.

So there’s no WiFI and power and internet access is coming into the RPi4.

Then next I thought it would be interesting to chain off another Raspbery Pi Zero (not the ‘W’ - this Zero has no WiFI) with the Pimoroni EnviroPlus on it. This Pi Zero enumerates as a gadget RNDIS ethernet device to the Raspberry Pi 4 host. Thus the Raspberry Pi 4 is then providing power and internet connection sharing to the Raspberry Pi Zero through the Power Over Ethernet.

Neat eh :slight_smile:

Hey Alex

This is an interesting use case (TIL bees and WiFi don’t go well together!) - and looks like you have found a great solution by using PoE and the USB gadget mode for Pi0! Keep the posts coming - this is an interesting setup and debugging process you’ve got going :D!

1 Like

Thanks for the interest! Everything is (of course) OpenSource and updated here

2 Likes