nerves-project-attic/nerves_network

Support multiple WiFi networks for an interface

tmecklem opened this issue · 6 comments

Nerves.Network doesn't currently support configuring multiple ssids for an interface.

WPA supplicant supports multiple network entries with priority (where higher number is higher priority), where the interface scans for ssids and connects to the highest priority network, and Nerves.Network can be modified to accept and configure wpa_supplicant to do that.

POC code to add a configuration to wpa supplicant without removing other network configs (thanks to @GregMefford for working through this with me):

alias Nerves.WpaSupplicant
wlan_if = :"Nerves.WpaSupplicant.wlan0"

x = WpaSupplicant.request(wlan_if, :ADD_NETWORK)
WpaSupplicant.request(wlan_if, {:SET_NETWORK, x, :ssid, "My Network"})
WpaSupplicant.request(wlan_if, {:SET_NETWORK, x, :key_mgmt, :"WPA-PSK"})
WpaSupplicant.request(wlan_if, {:SET_NETWORK, x, :psk, "letmein"})
WpaSupplicant.request(wlan_if, {:SET_NETWORK, x, :priority, 10})
WpaSupplicant.request(wlan_if, {:ENABLE_NETWORK, x})

Although the wpa_cli documents that this causes a reassociation to the current network, in practice it causes the interface to rescan networks and connect to the highest priority available ssid:

WpaSupplicant.request(wlan_if, :REASSOCIATE)

Together these pieces can be used to add support to the Nerves.Network.setup function and the config.exs support for default network config so that multiple ssids can be supported at configuration or runtime.

I pushed a branch with working support for multiple networks to https://github.com/nerves-project/nerves_network/tree/multiple-wifi-networks. It maintains backwards compatibility with:

      Nerves.Network.setup "wlan0", ssid: "myssid", key_mgmt: :"WPA-PSK", psk: "secretsecret"

while adding support for multiple network config via:

      Nerves.Network.setup "wlan0", networks: [
        [ssid: "myssid", key_mgmt: :"WPA-PSK", psk: "secretsecret"],
        [ssid: "myotherssid", key_mgmt: :"WPA-PSK", psk: "othersecret", priority: 10]]

I'm not particularly attached to the :networks key or the nested list of keyword lists. I just wanted to push something forward and see where the discussion goes.

Testing changes from the multiple-wifi-networks branch out for a bit since I saw some crashes during development that gave me pause. They seemed to be unrelated but I want to be more certain before I open a PR.

Has there been upates to this issue?

I think we can close this with version 0.4.0 being released, right?

Also, thanks again @tmecklem ❤️

Whoops yep. Thought the PR would close it. Thanks @tmecklem!!