Change or delete preset Wi-Fi settings?

How do I rewrite Wi-Fi information remotely using balena console?

Thank you :wink:

Hi,

BalenaOS uses Network Manager to manage it’s network connections. When you connect to the host OS of the balena device, you can use the nmcli command to update/rewrite network configurations. But be aware when doing this remotely, that if it does not work out as expected, you might not be able to connect to the device again. Depending on your use case https://github.com/balena-io/wifi-connect might also be interesting to you. This tool can create a local AP, that allows to configure Wi-Fi credentials for the the device via a web interface.

1 Like

Hi @afitzek

I have confirmed that it is possible to change Wi-Fi settings remotely with nmcli.

However, when resin-wifi-01 exists, it was restored to the original WiFi setting by restarting.

The following method was used to solve this.

  1. remove resin-wifi-01
$ rm /mnt/boot/system-connections/resin-wifi-01
  1. delete SSID by nmcli
$ nmcli connection delete [WIFI_SSID]

Thanks for your answer.

3 Likes

Hey @kazuph,

I have had to do this in the field a few times and wanted to add my experience. Note to other readers that what @afitzek is all very true. It is dangerous to do this kind of thing because if interrupted at the wrong time you might be saying goodbye to your device forever. Network manager in my experience is terrible at picking between multiple connections.

So @kazuph is doing more or less the same thing but there are some differences. Anyways this is how I replace wifi settings in the field.
I echo in a new connection like this:

echo "[connection]
id=NAME_OF_CON
type=wifi

[wifi]
mode=infrastructure
ssid=YOUR-SSID-HERE

[ipv4]
method=auto

[ipv6]
addr-gen-mode=stable-privacy
method=auto

[wifi-security
]auth-alg=open
key-mgmt=wpa-psk
psk=PASS-KEY-STUFF-HERE
" > /mnt/boot/system-connections/NAME_OF_CON

Then I confirm it with:

cat /mnt/boot/system-connections/NAME_OF_CON

Then I deleted the old connection from the two places you need to:
rm /mnt/boot/system-connections/resin-wifi-01
rm /mnt/state/root-overlay/etc/NetworkManager/system-connections/resin-wifi-01

Note the top one is the one that persists between boots and OS upgrades, and the bottom is bound to NM here: /etc/NetworkManager/system-connections/ so it delete thing here as well

Then I restart the device and that makes NM forget the old connection and the /mnt/boot file get moved to the right spots by balenaOS. I like this process because it ensures the replacement connection is there before you delete the old one. You could also put the new connection in both those places we removed the old one from and test it with nmcli c up YOUR_CON_NAME because if it fails it will probably try the old one again and let you back in.

Good luck to anyone that has to do this. I don’t do this with our fleet anymore because I wrote a python network manager supervisor that does all this for me and fills in some of network managers weak points for my fleet.

-Thomas

2 Likes