deploy2rpi3

pull/363/head
connor rigby 2017-09-26 13:21:49 -07:00
parent ca0b4fccf3
commit f8d52e33f5
10 changed files with 155 additions and 26 deletions

View File

@ -60,4 +60,10 @@ case target do
else
import_config("target/#{env}.exs")
end
rootfs_overlay_dir = "config/target/rootfs_overlay_#{Mix.Project.config[:target]}"
if File.exists?(rootfs_overlay_dir) do
config :nerves, :firmware,
rootfs_overlay: rootfs_overlay_dir
end
end

View File

@ -20,7 +20,7 @@ config :farmbot, :init, [
Farmbot.Target.Bootstrap.Configurator,
# Start up Network
# Farmbot.Target.Network
Farmbot.Target.Network
]
# Transports.
@ -28,7 +28,6 @@ config :farmbot, :transport, [
Farmbot.BotState.Transport.GenMqtt
]
# Configure Farmbot Behaviours.
config :farmbot, :behaviour, [
authorization: Farmbot.Bootstrap.Authorization,
@ -41,5 +40,5 @@ config :nerves_firmware_ssh,
]
config :bootloader,
init: [:nerves_runtime, :nerves_init_gadget],
init: [:nerves_runtime],
app: :farmbot

View File

@ -0,0 +1,57 @@
# Additional configuration for erlinit
# Turn on the debug prints
#-v
# Specify where erlinit should send the IEx prompt. Only one may be enabled at
# a time.
-c ttyS0 # UART pins on the GPIO connector
# -c tty1 # HDMI output
# If more than one tty are available, always warn if the user is looking at the
# wrong one.
--warn-unused-tty
# Use dtach to capture the iex session so that it can be redirected to the
# app's GUI
#-s "/usr/bin/dtach -N /tmp/iex_prompt"
# Specify the user and group IDs for the Erlang VM
#--uid 100
#--gid 200
# Uncomment to hang the board rather than rebooting when Erlang exits
# NOTE: Do not enable on production boards
--hang-on-exit
# Change the graceful shutdown time. If 10 seconds isn't long enough between
# calling "poweroff", "reboot", or "halt" and :init.stop/0 stopping all OTP
# applications, enable this option with a new timeout in milliseconds.
#--graceful-shutdown-timeout 15000
# Optionally run a program if the Erlang VM exits
#--run-on-exit /bin/sh
# Enable UTF-8 filename handling in Erlang and custom inet configuration
-e LANG=en_US.UTF-8;LANGUAGE=en;ERL_INETRC=/etc/erl_inetrc;ERL_CRASH_DUMP=/root/crash.dump
# Mount the application partition
# NOTE: This must match the location in the fwup.conf. If it doesn't the system
# will probably still work fine, but you won't get shell history since
# bootloader/nerves_runtime can't mount the application filesystem before
# the history is loaded. If this mount fails due to corruption, etc.,
# nerves_runtime will auto-format it. Your applications will need to handle
# initializing any expected files and folders.
-m /dev/mmcblk0p3:/root:ext4::
# Erlang release search path
-r /srv/erlang
# Assign a unique hostname based on the board id
-d "/usr/bin/boardid -b rpi -n 4"
-n nerves-%.4s
# If using bootloader (https://github.com/nerves-project/bootloader), start the
# bootloader OTP release up first. If bootloader isn't around, erlinit fails back
# to the main OTP release.
--boot bootloader

View File

@ -103,7 +103,7 @@ defmodule Farmbot.Bootstrap.Supervisor do
case @auth_task.authorize(email, pass, server) do
{:ok, token} ->
Logger.info "Successful authorization: #{@auth_task} - #{email} - #{server}"
ConfigStorage.update_config_value(:boolean, "authorization", "first_boot", false)
ConfigStorage.update_config_value(:bool, "settings", "first_boot", false)
ConfigStorage.update_config_value(:string, "authorization", "token", token)
children = [
supervisor(Farmbot.BotState.Supervisor, [token, [name: Farmbot.BotState.Supervisor ]]),

View File

@ -30,6 +30,10 @@ defmodule Farmbot.System.ConfigStorage do
|> Map.fetch!(:value)
end
def get_config_value(type, _, _) do
raise "Unsupported type: #{type}"
end
def update_config_value(type, group_name, key_name, value) when type in [:bool, :float, :string] do
__MODULE__
|> apply(:"get_#{type}_value", [group_name, key_name])
@ -37,11 +41,19 @@ defmodule Farmbot.System.ConfigStorage do
|> update!()
end
def update_config_value(type, _, _, _) do
raise "Unsupported type: #{type}"
end
def get_bool_value(group_name, key_name) do
group_id = get_group_id(group_name)
[type_id] = (from c in Config, where: c.group_id == ^group_id and c.key == ^key_name, select: c.bool_value_id) |> all()
[val] = (from v in BoolValue, where: v.id == ^type_id, select: v) |> all()
val
case (from c in Config, where: c.group_id == ^group_id and c.key == ^key_name, select: c.bool_value_id) |> all() do
[type_id] ->
[val] = (from v in BoolValue, where: v.id == ^type_id, select: v) |> all()
val
[] ->
raise "no such key #{key_name}"
end
end
def get_float_value(group_name, key_name) do

View File

@ -16,12 +16,17 @@ defmodule Farmbot.System.Init.FSCheckup do
end
defp do_checkup do
case File.write(Path.join(@data_path, "boot"), "Hello") do
check_file = Path.join(@data_path, "boot")
unless File.exists?(@data_path) do
File.mkdir(@data_path)
end
Logger.info "Checking #{check_file}"
case File.write(check_file, "Hello") do
:ok ->
Process.sleep(500)
Process.sleep(500)
:ok
_ ->
Logger.info "Filesystem not up yet..."
err ->
Logger.info "Filesystem not up yet (#{inspect err})..."
Process.sleep(1000)
do_checkup()
end

View File

@ -104,10 +104,12 @@ defmodule Farmbot.Mixfile do
[ system(target),
{:bootloader, "~> 0.1"},
{:nerves_runtime, "~> 0.4"},
{:nerves_init_gadget, "~> 0.2", only: :dev}
{:nerves_network, "~> 0.3"},
{:nerves_firmware_ssh, "~> 0.2"},
]
end
defp system("rpi3"), do: {:nerves_system_rpi3, "~> 0.16.1", runtime: false}
defp system("rpi0"), do: {:nerves_system_rpi0, ">= 0.0.0", runtime: false}
defp system("qemu_arm"), do: {:nerves_system_qemu_arm, ">= 0.0.0", runtime: false}
@ -127,7 +129,7 @@ defmodule Farmbot.Mixfile do
["./lib", "./nerves/host", "./test/support"]
end
defp elixirc_paths(_env, target) do
defp elixirc_paths(_env, _target) do
["./lib", "./nerves/target"]
end

51
mix.lock.rpi3 100644
View File

@ -0,0 +1,51 @@
%{"bootloader": {:hex, :bootloader, "0.1.2", "835ddcf50b796714658f342061d5d48ebc34cbd0d81cdbd5a5a8ae00705d72b1", [], [{:distillery, "~> 1.0", [hex: :distillery, repo: "hexpm", optional: false]}], "hexpm"},
"certifi": {:hex, :certifi, "2.0.0", "a0c0e475107135f76b8c1d5bc7efb33cd3815cb3cf3dea7aefdd174dabead064", [], [], "hexpm"},
"combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [], [], "hexpm"},
"connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [], [], "hexpm"},
"cowboy": {:hex, :cowboy, "1.0.4", "a324a8df9f2316c833a470d918aaf73ae894278b8aa6226ce7a9bf699388f878", [], [{:cowlib, "~> 1.0.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
"cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [], [], "hexpm"},
"db_connection": {:hex, :db_connection, "1.1.2", "2865c2a4bae0714e2213a0ce60a1b12d76a6efba0c51fbda59c9ab8d1accc7a8", [], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"decimal": {:hex, :decimal, "1.4.0", "fac965ce71a46aab53d3a6ce45662806bdd708a4a95a65cde8a12eb0124a1333", [], [], "hexpm"},
"distillery": {:hex, :distillery, "1.5.1", "7ad7354214959c0f65f57ddd49478c81c3b2733ca2e5ccfb9eb55351108466aa", [], [], "hexpm"},
"dns": {:hex, :dns, "1.0.1", "1d88187fdf564d937cee202949141090707fd0c9d7fcae903a6878ef24ef5d1e", [], [{:socket, "~> 0.3.12", [hex: :socket, repo: "hexpm", optional: false]}], "hexpm"},
"ecto": {:hex, :ecto, "2.2.4", "defde3c8eca385bd86466d2e1491d19e77f9b79ad996dc8e89e4e107f3942f40", [], [{:db_connection, "~> 1.1", [hex: :db_connection, repo: "hexpm", optional: true]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:mariaex, "~> 0.8.0", [hex: :mariaex, repo: "hexpm", optional: true]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:poolboy, "~> 1.5", [hex: :poolboy, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: true]}], "hexpm"},
"elixir_make": {:hex, :elixir_make, "0.4.0", "992f38fabe705bb45821a728f20914c554b276838433349d4f2341f7a687cddf", [], [], "hexpm"},
"esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [], [], "hexpm"},
"ex_json_schema": {:hex, :ex_json_schema, "0.5.5", "d8d4c3f47b86c9e634e124d518b290dda82a8b94dcc314e45af10042fc369361", [], [], "hexpm"},
"gen_mqtt": {:hex, :gen_mqtt, "0.3.1", "6ce6af7c2bcb125d5b4125c67c5ab1f29bcec2638236509bcc6abf510a6661ed", [], [{:vmq_commons, "1.0.0", [hex: :vmq_commons, repo: "hexpm", optional: false]}], "hexpm"},
"gettext": {:hex, :gettext, "0.13.1", "5e0daf4e7636d771c4c71ad5f3f53ba09a9ae5c250e1ab9c42ba9edccc476263", [], [], "hexpm"},
"hackney": {:hex, :hackney, "1.9.0", "51c506afc0a365868469dcfc79a9d0b94d896ec741cfd5bd338f49a5ec515bfe", [], [{:certifi, "2.0.0", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"httpoison": {:hex, :httpoison, "0.13.0", "bfaf44d9f133a6599886720f3937a7699466d23bb0cd7a88b6ba011f53c6f562", [], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "5.1.0", "d72b4effeb324ad5da3cab1767cb16b17939004e789d8c0ad5b70f3cea20c89a", [], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
"mdns": {:hex, :mdns, "0.1.6", "b51b902b15b50e0e1522483c6a5fb073413e3d3d6ef52a44b93a541460b47d29", [], [{:dns, "~> 1.0", [hex: :dns, repo: "hexpm", optional: false]}], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [], [], "hexpm"},
"mime": {:hex, :mime, "1.1.0", "01c1d6f4083d8aa5c7b8c246ade95139620ef8effb009edde934e0ec3b28090a", [], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [], [], "hexpm"},
"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_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"},
"nerves_system_rpi3": {:hex, :nerves_system_rpi3, "0.16.1", "46b2fc942d7434d9eb8164c06c25a94ee6dd6db7e88c857101e5a06e6b7d01a8", [], [{:nerves, "~> 0.7", [hex: :nerves, repo: "hexpm", optional: false]}, {:nerves_system_br, "~> 0.13.7", [hex: :nerves_system_br, repo: "hexpm", optional: false]}, {:nerves_toolchain_arm_unknown_linux_gnueabihf, "~> 0.11.0", [hex: :nerves_toolchain_arm_unknown_linux_gnueabihf, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_toolchain_arm_unknown_linux_gnueabihf": {:hex, :nerves_toolchain_arm_unknown_linux_gnueabihf, "0.11.0", "8d7606275a2d19de26ae238cd59475f4c06679aa9222b8987518d7c8a7beae51", [], [{:nerves, "~> 0.7", [hex: :nerves, repo: "hexpm", optional: false]}, {:nerves_toolchain_ctng, "~> 1.1", [hex: :nerves_toolchain_ctng, repo: "hexpm", optional: false]}], "hexpm"},
"nerves_toolchain_ctng": {:hex, :nerves_toolchain_ctng, "1.1.0", "0f03e4a3f3beef5fe271de0148b9f106c417e57f303f635c21c74b4bd6eb68ee", [], [], "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"},
"plug": {:hex, :plug, "1.4.3", "236d77ce7bf3e3a2668dc0d32a9b6f1f9b1f05361019946aae49874904be4aed", [], [{:cowboy, "~> 1.0.1 or ~> 1.1", [hex: :cowboy, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}], "hexpm"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [], [], "hexpm"},
"poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [], [], "hexpm"},
"ranch": {:hex, :ranch, "1.4.0", "10272f95da79340fa7e8774ba7930b901713d272905d0012b06ca6d994f8826b", [], [], "hexpm"},
"rsa": {:hex, :rsa, "0.0.1", "a63069f88ce342ffdf8448b7cdef4b39ba7dee3c1510644a39385c7e63ba246f", [], [], "hexpm"},
"sbroker": {:hex, :sbroker, "1.0.0", "28ff1b5e58887c5098539f236307b36fe1d3edaa2acff9d6a3d17c2dcafebbd0", [], [], "hexpm"},
"socket": {:hex, :socket, "0.3.12", "4a6543815136503fee67eff0932da1742fad83f84c49130c854114153cc549a6", [], [], "hexpm"},
"sqlite_ecto2": {:hex, :sqlite_ecto2, "2.2.1", "6447456ef4264177d16e489b88f7abc63463e9eddc1fef4358b3f73562b7a2d8", [], [{:connection, "~> 1.0.3", [hex: :connection, repo: "hexpm", optional: false]}, {:db_connection, "~> 1.1.0", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.2", [hex: :decimal, repo: "hexpm", optional: false]}, {:ecto, "~> 2.2.2", [hex: :ecto, repo: "hexpm", optional: false]}, {:esqlite, "~> 0.2.3", [hex: :esqlite, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.13.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:sbroker, "~> 1.0", [hex: :sbroker, repo: "hexpm", optional: false]}, {:sqlitex, "~> 1.3.2 or ~> 1.4", [hex: :sqlitex, repo: "hexpm", optional: false]}], "hexpm"},
"sqlitex": {:hex, :sqlitex, "1.3.3", "3aac5fd702be346f71d9de6e01702c9954484cd0971aa443490bb3bde045d919", [], [{:decimal, "~> 1.1", [hex: :decimal, repo: "hexpm", optional: false]}, {:esqlite, "~> 0.2.3", [hex: :esqlite, repo: "hexpm", optional: false]}], "hexpm"},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [], [], "hexpm"},
"system_registry": {:hex, :system_registry, "0.6.0", "31642177e6002d3cff2ada3553ed4e9c0a6ca015797d62d7d17c0ab8696185fc", [], [], "hexpm"},
"timex": {:hex, :timex, "3.1.24", "d198ae9783ac807721cca0c5535384ebdf99da4976be8cefb9665a9262a1e9e3", [], [{:combine, "~> 0.7", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
"tzdata": {:hex, :tzdata, "0.1.201605", "0c4184819b9d6adedcc02107b68321c45d8e853def7a32629b7961b9f2e95f33", [], [], "hexpm"},
"unicode_util_compat": {:hex, :unicode_util_compat, "0.3.1", "a1f612a7b512638634a603c8f401892afbf99b8ce93a45041f8aaca99cadb85e", [], [], "hexpm"},
"uuid": {:hex, :uuid, "1.1.7", "007afd58273bc0bc7f849c3bdc763e2f8124e83b957e515368c498b641f7ab69", [], [], "hexpm"},
"vmq_commons": {:hex, :vmq_commons, "1.0.0", "5f5005c12db33f92f40e818a3617fb148972d59adcf99298c9d3808ef3582e34", [], [], "hexpm"}}

View File

@ -7,7 +7,6 @@ defmodule Farmbot.Host.Bootstrap.Configurator do
end
def init(_) do
# require IEx; IEx.pry
# Get out authorization data out of the environment.
# for host environment this will be configured at compile time.
# for target environment it will be configured by `configurator`.
@ -18,8 +17,6 @@ defmodule Farmbot.Host.Bootstrap.Configurator do
ConfigStorage.update_config_value(:string, "authorization", "password", pass)
ConfigStorage.update_config_value(:string, "authorization", "server", server)
ConfigStorage.update_config_value(:string, "authorization", "token", nil)
# require IEx; IEx.pry
# Process.sleep(1000)
:ignore
end

View File

@ -22,20 +22,20 @@ defmodule Farmbot.Target.Bootstrap.Configurator do
def start_link(_, opts) do
Logger.info "Configuring Farmbot."
supervisor = Supervisor.start_link(__MODULE__, [self()], opts)
case supervisor do
{:ok, pid} ->
receive do
:ok -> stop(pid, :ignore)
{:error, _reason} = err -> stop(pid, err)
end
:ignore -> :ignore
end
# case supervisor do
# {:ok, pid} ->
# receive do
# :ok -> stop(pid, :ignore)
# {:error, _reason} = err -> stop(pid, err)
# end
# :ignore -> :ignore
# end
end
def init(cb) do
first_boot? = ConfigStorage.get_config_value(:boolean, "authorization", "first_boot")
first_boot? = ConfigStorage.get_config_value(:bool, "settings", "first_boot")
if first_boot? do
Logger.info "Building new config."
Logger.info "Building new configuration."
import Supervisor.Spec
:ets.new(:session, [:named_table, :public, read_concurrency: true])
children = [