nerves_network v0.3.1 Nerves.Network

The Nerves.Network application handles the low level details of connecting to WiFi networks. To quickly get started, create a new Nerves project and add the following line someplace early on in your program:

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

When you boot your Nerves image, Nerves.Network monitors for an interface called “wlan0” to be created. This occurs when you plug in a USB WiFi dongle. If you plug in more than one WiFi dongle, each one will be given a name like “wlan1”, etc. Those may be setup as well.

When not connected, Nerves.Network continually scans for the desired access point. Once found, it associates and runs DHCP to acquire an IP address.

IMPORTANT: This module is called Nerves.Network for a reason. Some functionality is missing or awaiting refactoring. The largest pending change is to change how events are handled, and that mostly affects how things work internally. Externally, the event change will allow you to receive notifications of when connections occur or are broken. This doesn’t mean that it’s unusable, though. If you have fixes that make this work better for your setup, please consider sharing them.

Link to this section Summary

Functions

If ifname is a wireless LAN, scan for access points

Change the regulatory domain for wireless operations. This must be set to the two character alpha2 code for the country where this device is operating. See http://git.kernel.org/cgit/linux/kernel/git/sforshee/wireless-regdb.git/tree/db.txt for the latest database and the frequencies allowed per country

Configure the specified interface. Settings contains one or more of the following

Return a map with the current configuration and interface status

Stop all control of ifname

Link to this section Functions

If ifname is a wireless LAN, scan for access points.

Link to this function set_regulatory_domain(country)

Change the regulatory domain for wireless operations. This must be set to the two character alpha2 code for the country where this device is operating. See http://git.kernel.org/cgit/linux/kernel/git/sforshee/wireless-regdb.git/tree/db.txt for the latest database and the frequencies allowed per country.

The default is to use the world regulatory domain (00).

You may also configure the regulatory domain in your app’s config/config.exs:

config :nerves_network,
  regulatory_domain: "US"
Link to this function setup(ifname, settings \\ [])

Configure the specified interface. Settings contains one or more of the following:

  • :ipv4_address_method - :dhcp, :static, or :linklocal
  • :ipv4_address - e.g., “192.168.1.5” (specify when :ipv4_address_method = :static)
  • :ipv4_subnet_mask - e.g., “255.255.255.0” (specify when :ipv4_address_method = :static)
  • :domain - e.g., “mycompany.com” (specify when :ipv4_address_method = :static)
  • :nameservers - e.g., [“8.8.8.8”, “8.8.4.4”] (specify when :ipv4_address_method = :static)
  • :ssid - “My WiFi AP” (specify if this is a wireless interface)
  • :key_mgmt - e.g., :"WPA-PSK" or :NONE
  • :psk - e.g., “my-secret-wlan-key”

Return a map with the current configuration and interface status.

Link to this function teardown(ifname)

Stop all control of ifname