Permalink
Browse files

Remove old nerves_network hacks

  • Loading branch information...
ConnorRigby committed Jan 10, 2019
1 parent 9220b26 commit b9ffa06df8878e59b5d3cec34eab50e7c8e75f2b
@@ -51,7 +51,7 @@
"nerves_hub_core": {:hex, :nerves_hub_core, "0.1.0", "85564bdccd7eac928b4ddf0d8eacac505072a4147a41c84873119e7310dcc9e3", [:mix], [{:hackney, "~> 1.9", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:tesla, "~> 1.2.1 or ~> 1.3", [hex: :tesla, repo: "hexpm", optional: false]}, {:x509, "~> 0.3", [hex: :x509, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_init_gadget": {:hex, :nerves_init_gadget, "0.5.1", "07f3eeb9acb3f919b3b34b36f552bb38d70f2d29ace63f3f23f33eee6a1ca693", [:mix], [{:mdns, "~> 1.0", [hex: :mdns, repo: "hexpm", optional: false]}, {:nerves_firmware_ssh, "~> 0.2", [hex: :nerves_firmware_ssh, repo: "hexpm", optional: false]}, {:nerves_network, "~> 0.3", [hex: :nerves_network, repo: "hexpm", optional: false]}, {:nerves_runtime, "~> 0.3", [hex: :nerves_runtime, repo: "hexpm", optional: false]}, {:one_dhcpd, "~> 0.1", [hex: :one_dhcpd, repo: "hexpm", optional: false]}, {:ring_logger, "~> 0.4", [hex: :ring_logger, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_leds": {:hex, :nerves_leds, "0.8.0", "193692767dca1a201b09113d242648493b9be0087bab83ebee99c3b0a254f5e1", [:mix], [], "hexpm"},
"nerves_network": {:git, "https://github.com/nerves-project/nerves_network.git", "7dc94609760d7e663718840423143cd35bb69edc", [branch: "teardown-fix"]},
"nerves_network": {:git, "https://github.com/nerves-project/nerves_network.git", "4310d09574fca10fc0cf083202a46de4083452d1", [branch: "teardown-fix"]},
"nerves_network_interface": {:hex, :nerves_network_interface, "0.4.4", "200b1a84bc1a7fdeaf3a1e0e2d4e9b33e240b034e73f39372768d43f8690bae0", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_runtime": {:hex, :nerves_runtime, "0.8.0", "9657810438a346122a15762deafc4a7adda4aeb545c57681b5aed0fb0f635617", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:system_registry, "~> 0.5", [hex: :system_registry, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_system_br": {:hex, :nerves_system_br, "1.5.3", "97272ae67c6b4d480d0083e4a07851c98c6a2f56cafd4e90aea30eae7c9c1f23", [:mix], [], "hexpm"},
@@ -47,19 +47,12 @@ defmodule Farmbot.Target.Bootstrap.Configurator.CaptivePortal do
nil
end

wpa_pid = wait_for_wpa()
Nerves.WpaSupplicant.request(wpa_pid, {:AP_SCAN, 2})
Farmbot.Leds.blue(:slow_blink)
init_mdns(@mdns_domain)
update_mdns(@address)
{:ok, %{dhcp_server: dhcp_server, dnsmasq: dnsmasq}}
end

defp wait_for_wpa do
name = :"Nerves.WpaSupplicant.#{@interface}"
GenServer.whereis(name) || wait_for_wpa()
end

def terminate(_, state) do
Logger.busy 3, "Stopping captive portal GenServer."

@@ -132,9 +132,11 @@ defmodule Farmbot.Target.Bootstrap.Configurator.Router do
ifname = conn.params["ifname"] || raise(MissingField, field: "ifname", message: "ifname not provided", redir: "/network")
ssid = conn.params["ssid"] |> remove_empty_string()
security = conn.params["security"] |> remove_empty_string()
identity = conn.params["identity"] |> remove_empty_string()
password = conn.params["password"] |> remove_empty_string()
psk = conn.params["psk"] |> remove_empty_string()
domain = conn.params["domain"] |> remove_empty_string()
name_servers = conn.params["name_servers"] |> remove_empty_string()
name_servers = conn.params["name_servers"] |> remove_empty_string()
ipv4_method = conn.params["ipv4_method"] |> remove_empty_string()
ipv4_address = conn.params["ipv4_address"] |> remove_empty_string()
ipv4_gateway = conn.params["ipv4_gateway"] |> remove_empty_string()
@@ -169,6 +171,8 @@ defmodule Farmbot.Target.Bootstrap.Configurator.Router do
ssid: ssid, security: security, psk: psk,
type: if(ssid, do: "wireless", else: "wired"),
domain: domain,
identity: identity,
password: password,
name_servers: name_servers,
ipv4_method: ipv4_method,
ipv4_address: ipv4_address,
@@ -34,8 +34,6 @@ defmodule Farmbot.Target.Network.Manager do
end

def init({interface, opts} = args) do
Application.stop(:nerves_network)
{:ok, _} = Application.ensure_all_started(:nerves_network)
Logger.busy(3, "Waiting for interface #{interface} up.")

unless interface in Nerves.NetworkInterface.interfaces() do
@@ -49,14 +47,7 @@ defmodule Farmbot.Target.Network.Manager do
Nerves.Time.set_ntp_servers([s1, s2])
maybe_hack_tzdata()

settings = Enum.map(opts, fn({key, value}) ->
case key do
:key_mgmt -> {key, String.to_atom(value)}
_ -> {key, value}
end
end)
Nerves.Network.IFSupervisor.setup(interface, settings)

Nerves.Network.setup(interface, opts)
{:ok, _} = Elixir.Registry.register(Nerves.NetworkInterface, interface, [])
{:ok, _} = Elixir.Registry.register(Nerves.Udhcpc, interface, [])
{:ok, _} = Elixir.Registry.register(Nerves.WpaSupplicant, interface, [])
@@ -67,7 +58,7 @@ defmodule Farmbot.Target.Network.Manager do
# These won't change
mdns_domain: domain,
interface: interface,
opts: settings,
opts: opts,

# These change based on
# Events from timers and other processes.
@@ -228,13 +219,8 @@ defmodule Farmbot.Target.Network.Manager do
end

defp restart_connection_timer(state) do
# TODO(Connor) - 2018-08-15 There is a bug in Nerves.Network
# Where `Nerves.Network.teardown(ifname)` doesn't actually do anything.
cancel_timer(state.reconnect_timer)
Nerves.Network.IFSupervisor.teardown(state.interface)
Nerves.NetworkInterface.ifdown(state.interface)
Process.sleep(5000)
Nerves.NetworkInterface.ifup(state.interface)
Nerves.Network.teardown(state.interface)
Process.sleep(5000)
Nerves.Network.setup(state.interface, state.opts)
Process.send_after(self(), :reconnect_timer, 30_000)

0 comments on commit b9ffa06

Please sign in to comment.