View Source VintageNetWiFi (vintage_net_wifi v0.11.6)

WiFi support for VintageNet

Configurations for this technology are maps with a :type field set to VintageNetWiFi. The following additional fields are supported:

  • :vintage_net_wifi - WiFi options
  • :ipv4 - IPv4 options. See VintageNet.IP.IPv4Config.

To scan for WiFi networks it's sufficient to use an empty configuration and call the VintageNet.scan("wlan0"):

%{type: VintageNetWiFi}

Here's a typical configuration for connecting to a WPA2-protected Wi-Fi network:

%{
  type: VintageNetWiFi,
  vintage_net_wifi: %{
    mode: :infrastructure,
    networks: [%{ssid: "my_network_ssid", key_mgmt: :wpa_psk, psk: "a_passphrase_or_psk"}]
  },
  ipv4: %{method: :dhcp}
}

If your Wi-Fi adapter or module has support for running as an Access Point, then the following configuration puts it in AP mode, assigns a static IP address of 192.168.0.1 and gives clients IP addresses from 192.168.0.30 to 192.168.0.254.

%{
  type: VintageNetWiFi,
  vintage_net_wifi: %{
    mode: :ap,
    networks: [
      %{
        ssid: "test ssid",
        key_mgmt: :none
      }
    ]
  },
  ipv4: %{
    method: :static,
    address: {192, 168, 0, 1},
    prefix_length: 24
  },
  dhcpd: %{
    start: {192, 168, 0, 30},
    end: {192, 168, 0, 254}
  }
}

To enable verbose log messages from the wpa_supplicant, add verbose: true to the configuration.

Summary

Functions

Configure WiFi using the most common settings

Convenience function to scan for access points

Quick way to receive WiFi credentials via WPS PBC

Functions

Link to this function

quick_configure(ssid, passphrase \\ nil)

View Source
@spec quick_configure(String.t(), String.t() | nil) :: :ok | {:error, term()}

Configure WiFi using the most common settings

If your network requires a password (WPA PSK networks):

iex> VintageNetWiFi.quick_configure("ssid", "password")
:ok

If you're connecting to an open network, don't pass the password. Keep in mind that if you're at a cafe or other location that has a captive portal, VintageNetWiFi isn't smart enough to bypass it.

iex> VintageNetWiFi.quick_configure("open_wifi_ssid")
:ok

Then run VintageNet.info to see when the network connects. If you're writing a program, run VintageNet.get(["interface", "wlan0", "connection"]) to get the connection status or subscribe to that property for change notifications.

If you're on an enterprise network or use static IP addresses or need any other special configuration handling, you'll need to call VintageNet.configure/3 instead. See VintageNetWiFi.Cookbook for help with creating configurations or manually construct the configuration map.

Link to this function

quick_scan(wait_time_ms \\ 2000)

View Source
@spec quick_scan(non_neg_integer()) :: [VintageNetWiFi.AccessPoint.t()]

Convenience function to scan for access points

This function initiates a scan, waits, and then returns all of the discovered access points. It's intended for quickly seeing what's around.

If you'd like to use this in a program, but want to display access point options as they're found, here's how to do it:

VintageNet.subscribe(["interface", "wlan0", "wifi", "access_points"])
VintageNet.scan("wlan0")

Then wait for messages. They'll be of the form:

{VintageNet, ["interface", "wlan0", "wifi", "access_points"], old_value, new_value, meta}

Both old_value and new_value will be lists of access points. You'll need call VintageNet.scan/1 every 30 seconds or so to repeat the scan across all WiFi channels.

Link to this function

quick_wps(timeout \\ 60000)

View Source
@spec quick_wps(non_neg_integer()) :: {:ok, map()} | {:error, String.t()}

Quick way to receive WiFi credentials via WPS PBC

Call this function with a long enough timeout for you to press the WPS button on your access point. The WiFi gets configured as soon as the WPS credentials are received.

VintageNetWiFi.quick_wps(60_000)
# Press WPS button on AP
:ok