that took so much debugging

pull/363/head
connor rigby 2017-10-23 11:09:00 -07:00
parent c2bc4f60fe
commit 8c8b89426e
8 changed files with 43 additions and 12 deletions

View File

@ -12,6 +12,8 @@ config :farmbot, Farmbot.System.ConfigStorage,
adapter: Sqlite.Ecto2,
database: "/root/config-#{Mix.env()}.sqlite3"
config :farmbot, ecto_repos: [Farmbot.Repo.A, Farmbot.Repo.B, Farmbot.System.ConfigStorage]
config :farmbot, data_path: "/root"
# Configure your our init system.
@ -32,7 +34,7 @@ config :farmbot, :init, [
# Transports.
config :farmbot, :transport, [
Farmbot.BotState.Transport.GenMqtt
# Farmbot.BotState.Transport.GenMqtt
]
# Configure Farmbot Behaviours.

View File

@ -97,7 +97,7 @@ defmodule Farmbot.Mixfile do
{:ex_doc, "~> 0.14", only: :dev},
{:excoveralls, "~> 0.6", only: :test},
{:mock, "~> 0.2.0", only: :test},
{:postgrex, "~> 0.13.3", only: :test}
{:postgrex, "~> 0.13.3", only: :test},
]
end
@ -106,7 +106,7 @@ defmodule Farmbot.Mixfile do
[
{:bootloader, "~> 0.1"},
{:nerves_runtime, "~> 0.4"},
{:nerves_network, github: "nerves-project/nerves_network", override: true},
{:nerves_network, path: "/home/connor/oss/elixir/nerves/nerves_network", override: true},
{:nerves_firmware_ssh, "~> 0.2"},
{:dhcp_server, "~> 0.1.3"}
]

View File

@ -32,7 +32,7 @@
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [], [], "hexpm"},
"mock": {:hex, :mock, "0.2.1", "bfdba786903e77f9c18772dee472d020ceb8ef000783e737725a4c8f54ad28ec", [], [{:meck, "~> 0.8.2", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"},
"nerves": {:hex, :nerves, "0.7.5", "3aa6a336b2ad6c1c9589cc2b577511b3c4c375c1ba6c533ab9f88adb8c21f0c3", [], [{:distillery, "~> 1.4", [hex: :distillery, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_network": {:hex, :nerves_network, "0.3.4", "c50a36b8263cda2bee18f408287d0f4474f8367702d170864325abbd5d424e4d", [], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:nerves_network_interface, "~> 0.4.0", [hex: :nerves_network_interface, repo: "hexpm", optional: false]}, {:nerves_wpa_supplicant, "~> 0.3.0", [hex: :nerves_wpa_supplicant, repo: "hexpm", optional: false]}, {:system_registry, "~> 0.4", [hex: :system_registry, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_network": {:git, "https://github.com/nerves-project/nerves_network.git", "a4c4e11c8f8663bed36e1bc0f45ac57a1b9eee9a", []},
"nerves_network_interface": {:hex, :nerves_network_interface, "0.4.2", "7a3663a07803f2f9f1e37146714d24ccec1e9349268586e4ed8c41f38641d837", [], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_uart": {:hex, :nerves_uart, "0.1.2", "4310dbb1721a5a007b8e5c416cf81754415bde6b7e2c9aa65a059886b85e637c", [], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_wpa_supplicant": {:hex, :nerves_wpa_supplicant, "0.3.2", "19dc7e1248336e7f542b11b2b857ceb5b088d3eb41a6ca75b7b76628dcf67aad", [], [{:elixir_make, "~> 0.3", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},

View File

@ -26,7 +26,7 @@
"nerves": {:hex, :nerves, "0.7.5", "3aa6a336b2ad6c1c9589cc2b577511b3c4c375c1ba6c533ab9f88adb8c21f0c3", [], [{:distillery, "~> 1.4", [hex: :distillery, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_firmware_ssh": {:hex, :nerves_firmware_ssh, "0.2.2", "a876f4e44ccc02606b923d7097b64dc7793384d716583cfca756b7f0dff9d441", [], [{:nerves_runtime, "~> 0.4", [hex: :nerves_runtime, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_init_gadget": {:hex, :nerves_init_gadget, "0.2.1", "20f36dd062fb00e2be8817ddff1b9ced9762877cfe23f6ec1d5936a37e3fc2c8", [], [{:mdns, "~> 0.1", [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]}], "hexpm"},
"nerves_network": {:hex, :nerves_network, "0.3.4", "c50a36b8263cda2bee18f408287d0f4474f8367702d170864325abbd5d424e4d", [], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:nerves_network_interface, "~> 0.4.0", [hex: :nerves_network_interface, repo: "hexpm", optional: false]}, {:nerves_wpa_supplicant, "~> 0.3.0", [hex: :nerves_wpa_supplicant, repo: "hexpm", optional: false]}, {:system_registry, "~> 0.4", [hex: :system_registry, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_network": {:git, "https://github.com/nerves-project/nerves_network.git", "a4c4e11c8f8663bed36e1bc0f45ac57a1b9eee9a", []},
"nerves_network_interface": {:hex, :nerves_network_interface, "0.4.2", "7a3663a07803f2f9f1e37146714d24ccec1e9349268586e4ed8c41f38641d837", [], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_runtime": {:hex, :nerves_runtime, "0.4.4", "26034bc7d13dbd46aab2f429f988656621a4d91872ccf5fa748c16630bd65016", [], [{: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, "0.13.8", "bca89f31ef27ddad48feb30de648913f0091e205652d005b95255c49e743d087", [], [], "hexpm"},

View File

@ -41,9 +41,26 @@ defmodule Farmbot.Target.Bootstrap.Configurator do
end
end
def init(_) do
first_boot? = ConfigStorage.get_config_value(:bool, "settings", "first_boot")
@data_path Application.get_env(:farmbot, :data_path) || Mix.raise("Unconfigured data path.")
def flag_configured do
check_file = Path.join(@data_path, "configured")
File.write(check_file, "configured")
end
defp block() do
block()
end
def init(_) do
#working settings
# settings = [ssid: "findme", psk: "password1234", key_mgmt: :"WPA-PSK"]
# current_settings = [ssid: "findme", psk: "password1234", security: :"WPA-PSK"]
# Nerves.Network.setup("wlan0",)
# block()
# check_file = Path.join(@data_path, "configured")
# first_boot? = !(File.exists?(check_file))
first_boot? = ConfigStorage.get_config_value(:bool, "settings", "first_boot")
if first_boot? do
Logger.info("Building new configuration.")
import Supervisor.Spec

View File

@ -9,11 +9,21 @@ defmodule Farmbot.Target.Network.Manager do
GenServer.start_link(__MODULE__, {interface, opts}, [name: :"#{__MODULE__}-#{interface}"])
end
def init({interface, opts}) do
Nerves.Network.Config.drop(interface)
def init({interface, opts} = args) do
unless interface in Nerves.NetworkInterface.interfaces() do
Logger.debug("Waiting for interface up.")
Process.sleep(1000)
init(args)
end
# Nerves.Network.teardown(interface)
# Nerves.NetworkInterface.ifdown(interface)
# Nerves.NetworkInterface.ifup(interface)
# Nerves.Network.Config.drop(interface)
SystemRegistry.register()
{:ok, _} = Registry.register(Nerves.NetworkInterface, interface, [])
{:ok, _} = Registry.register(Nerves.Udhcpc, interface, [])
IO.puts "OPTS: #{inspect opts}"
Network.setup(interface, opts)
{:ok, %{interface: interface, ip_address: nil, connected: false}}
end

View File

@ -17,7 +17,7 @@ defmodule Farmbot.Target.Network do
def to_network_config(%NetworkInterface{ssid: ssid, psk: psk, type: "wireless"} = config) do
Logger.debug("wireless network config: ssid: #{config.ssid}, psk: #{config.psk}")
{config.name, [ssid: ssid, security: :"WPA-PSK", psk: psk]}
{config.name, [ssid: ssid, key_mgmt: :"WPA-PSK", psk: psk]}
end
def to_network_config(%NetworkInterface{type: "wired"} = config) do
@ -36,7 +36,6 @@ defmodule Farmbot.Target.Network do
config = ConfigStorage.all(NetworkInterface)
Logger.info("Starting Networking")
children = config |> Enum.map(&to_network_config/1) |> Enum.map(&to_child_spec/1)
supervise(children, strategy: :one_for_one)
end
end

View File

@ -3,12 +3,15 @@ defmodule Farmbot.Target.SystemTasks do
@behaviour Farmbot.System
def factory_reset(_reason) do
def factory_reset(reason) do
reboot(reason)
end
def reboot(_reason) do
Nerves.Runtime.reboot()
end
def shutdown(_reason) do
Nerves.Runtime.poweroff()
end
end