You can mount the SD card on a laptop/desktop and create the /boot/wifi.yml file. /boot/wifi.yml looks something like:
networks:
- ssid: Home
psk: wheretheheartis
priority: 100
- ssid: Work
psk: gettinstuffdone
priority: 99
On boot, the Nerves application looks for the wifi config and copies it over to a place that won't be overwritten on a firmware upgrade, and then uses it to configure the wifi.
Starter code (not quite tested in the unit or battle sense)
def start_network do
maybe_config = Path.join("/boot", "wifi.yml")
if File.exists?(maybe_config) do
with {:ok, _config} <- YamlElixir.read_from_file(maybe_config),
:ok <- File.cp(maybe_config, "/root/wifi.yml") do
File.rm(maybe_config)
end
end
config = "/root/wifi.yml"
if File.exists?(config) do
{:ok, wifi} = YamlElixir.read_from_file(config)
networks =
wifi["networks"]
|> Enum.map(fn(network) ->
[
ssid: network["ssid"],
psk: network["psk"],
priority: Map.get(network, "priority", 1),
key_mgmt: Map.get(network, "key_mgmt", "WPA-PSK") |> String.to_atom()
]
end)
settings = [networks: networks]
Nerves.Network.setup("wlan0", settings)
end
end