Hey folks,
I wanted to chime in with a solution for programmatically switching from wifi to cellular (or vice versa) via NetworkManager’s DBUS API using Python dbus (though you could use any dbus binding).
FYI, we (@alexanderkjones and I) are using an Quectel EC25 modem on a fin.
Here’s the code:
import dbus
# Get the system bus
bus = dbus.SystemBus()
# Get the top-level NetworkManager proxy object
nm = bus.get_object('org.freedesktop.NetworkManager', '/org/freedesktop/NetworkManager')
# Get a property interface to use on the NetworkManager object
props = dbus.Interface(nm, 'org.freedesktop.DBus.Properties')
# Disable wifi (Wireless) and enable cellular (Wwan)
props.Set('org.freedesktop.NetworkManager', 'WirelessEnabled', False)
props.Set('org.freedesktop.NetworkManager', 'WwanEnabled', True)
# Disable cellular (Wwan) and enable wifi (Wireless)
props.Set('org.freedesktop.NetworkManager', 'WwanEnabled', False)
props.Set('org.freedesktop.NetworkManager', 'WirelessEnabled', True)
Also, the container needs a couple of settings to utilize DBUS:
mycontainer:
build: ./mycontainer
environment:
- 'DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host/run/dbus/system_bus_socket'
labels:
io.balena.features.dbus: '1'
The NetworkManager DBUS API is extensive and could be leveraged for many networking related tasks but for our needs this code has sufficed.
Hope that helps!
Elliot