Skip to content

Commit

Permalink
Update docs for clarity (h/t @jschneck on Slack)
Browse files Browse the repository at this point in the history
[@fhunleth - removed :nerves_network from extra_applications]
  • Loading branch information
derekkraan authored and fhunleth committed Aug 27, 2017
1 parent b2adf2e commit eff203c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 53 deletions.
31 changes: 31 additions & 0 deletions OLD_NERVES_RUNTIME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Loading WiFi kernel module (unnecessary for newer versions of `nerves_runtime`)

**Note**
If you are using `nerves_runtime` >= `0.3.0` the kernel module will be auto
loaded by default, and this step is not necessary.

Before WiFi will work, you will need to load any modules for your device if they
aren't loaded already. Here's an example for Raspberry Pi 0 and Raspberry Pi 3:

``` elixir
defmodule MyApplication do
use Application

def start(_type, _args) do
import Supervisor.Spec, warn: false

children = [
worker(Task, [fn -> init_kernel_modules() end], restart: :transient, id: Nerves.Init.KernelModules)
]

opts = [strategy: :one_for_one, name: MyApplication.Supervisor]
Supervisor.start_link(children, opts)
end

def init_kernel_modules() do
{_, 0} = System.cmd("modprobe", ["brcmfmac"])
end
end

```

71 changes: 18 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ def deps(target) do
[ system(target),
{:nerves_network, "~> 0.3"}
]
end
```

# WiFi Networking

## Installation
## Installation & Setup

You'll first need to set the regulatory domain in your `config.exs` to your ISO
3166-1 alpha-2 country code. In theory this is optional, but you'll get the
Expand All @@ -29,37 +30,22 @@ config :nerves_network,
regulatory_domain: "US"
```

## Setup

**Note**
If you are using `nerves_runtime` >= `0.3.0` the kernel module will be auto
loaded by default, and this step is not necessary.

Before WiFi will work, you will need to load any modules for your device if they
aren't loaded already. Here's an example for Raspberry Pi 0 and Raspberry Pi 3:

``` elixir
defmodule MyApplication do
use Application

def start(_type, _args) do
import Supervisor.Spec, warn: false

children = [
worker(Task, [fn -> init_kernel_modules() end], restart: :transient, id: Nerves.Init.KernelModules)
]

opts = [strategy: :one_for_one, name: MyApplication.Supervisor]
Supervisor.start_link(children, opts)
end

def init_kernel_modules() do
{_, 0} = System.cmd("modprobe", ["brcmfmac"])
end
end
The easiest way to get up and running is by statically setting your WiFi (and possibly ethernet) configuration in `config.exs`:

```elixir
config :nerves_network, :default,
wlan0: [
ssid: System.get_env("NERVES_NETWORK_SSID"),
psk: System.get_env("NERVES_NETWORK_PSK"),
key_mgmt: String.to_atom(key_mgmt)
],
eth0: [
ipv4_address_method: :dhcp
]
```

If you are using an older version (`< 0.3.0`) of `nerves_runtime` then you'll need to do some additional setup to load the correct kernel module for WiFi. See [this page](OLD_NERVES_RUNTIME.md) for more information.

## Scanning

You can scan by running:
Expand All @@ -81,7 +67,7 @@ iex> Nerves.Network.scan "wlan0"
level: -43, noise: 0, qual: 0, ssid: "dlink", tsf: 580587711245}]
```

## Running
## Runtime WiFi network setup

Setup your network connection by running:

Expand Down Expand Up @@ -115,37 +101,16 @@ Nerves.Network.setup "eth0", ipv4_address_method: :static,
Nerves.Network.setup "usb0", ipv4_address_method: :linklocal
```

# Configuring Defaults
# Using `nerves_network` with `bootloader`

`nerves_network` allows default network interface settings to be set using
application configuration. This can be helpful when using `nerves_network` with
[`bootloader`](https://github.com/nerves-project/bootloader).

Configuring `bootloader` to start `nerves_network`:
Set default network interface settings as described above. Then you can use [`bootloader`](https://github.com/nerves-project/bootloader) to start `nerves_network`:

```elixir
config :bootloader,
init: [:nerves_network],
app: :your_app
```

The following example will pull WiFi network settings from the system
environment variables and configure the interface's IP address using DHCP:

```elixir
key_mgmt = System.get_env("NERVES_NETWORK_KEY_MGMT") || "WPA-PSK"

config :nerves_network, :default,
wlan0: [
ssid: System.get_env("NERVES_NETWORK_SSID"),
psk: System.get_env("NERVES_NETWORK_PSK"),
key_mgmt: String.to_atom(key_mgmt)
],
eth0: [
ipv4_address_method: :dhcp
]
```

## Limitations

Currently, only IPv4 is supported. The library is incredibly verbose in its
Expand Down

0 comments on commit eff203c

Please sign in to comment.