Configure WiFi


Configure WiFi

  {:vintage_net_wifi, "~> 0.11"}

Finding access points

Nerves uses vintage_net_wifi to configure WiFi networking. This notebook uses the quick_ functions to simplify common tasks. If you’re trying to connect to an enterprise network, this may not work for you.

Step 1 is to see what WiFi networks are available. VintageNetWiFi.quick_scan/0 returns a lot of information, so lets filter it to get a list of SSIDs (rerun if your network doesn’t should up in time):

networks =
  |> %{ssid: ssid, signal_percent: signal_percent} ->
    %{ssid: ssid, signal_percent: signal_percent}
  |> Enum.sort(&(&1.signal_percent >= &2.signal_percent))
  |> Enum.uniq_by(& &1.ssid)

Connect to a network

Next, lets connect to one of the WiFi networks. Select the SSID and enter the password.

selectable_networks =
  [{"", "SSIDs:"}] ++, fn network -> {network.ssid, network.ssid} end)

selected_network ="Select WiFi Network", selectable_networks)
  |> Kino.render()

psk_input = Kino.Input.password("Enter WiFi password")

Verify that the information is correct and then evaluate the following code block to set it.

ssid = |> String.trim()
psk = |> String.trim()

if ssid != "" do
  VintageNetWiFi.quick_configure(ssid, psk)
  IO.puts("Skipping WiFi configuration.")

Check the connection

The final step is to check whether everything worked. is an easy way of checking overall network connectivity on a device, so run it. Hopefully, you’ll see a section for "wlan0" and a connection status of :internet. You may need to scroll down.

Next up…

See VintageNet to learn more about networking in Nerves.