From 40b76cab86018b87b942f204e53ee1164ba08f97 Mon Sep 17 00:00:00 2001 From: Gabriel Burnworth Date: Thu, 7 Jun 2018 18:07:00 -0700 Subject: [PATCH 01/67] Update README img download link (v6.4.3) [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fea7d1a24..12faf0b07 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ if you spot a bug or fix, but for now we suggest obtaining a Raspberry Pi 3 for |Raspbery Pi Version | |---| -| :star: **[RPi 3 (Ships with FarmBot.io kits)](https://github.com/FarmBot/farmbot_os/releases/download/v6.4.1/farmbot-rpi3-6.4.1.img)**| +| :star: **[RPi 3 (Ships with FarmBot.io kits)](https://github.com/FarmBot/farmbot_os/releases/download/v6.4.3/farmbot-rpi3-6.4.3.img)**| --- ## Installation From 99227953423cceea208674f326ad2af16af190c7 Mon Sep 17 00:00:00 2001 From: connor rigby Date: Mon, 11 Jun 2018 15:15:47 -0700 Subject: [PATCH 02/67] Update some dialyzer stuffs --- formatted_files | 1 + lib/farmbot/bootstrap/supervisor.ex | 6 -- .../bot_state/transport/http/router.ex | 2 + lib/farmbot/farm_event/execution/execution.ex | 1 + lib/farmbot/http/adapter.ex | 2 +- lib/farmbot/http/http.ex | 10 +- lib/farmbot/http/httpoison_adapter.ex | 8 -- lib/farmbot/jwt.ex | 13 ++- lib/farmbot/regimen/manager.ex | 6 +- lib/farmbot/regimen/supervisor.ex | 2 +- lib/farmbot/system/debug/debug.ex | 15 +-- lib/farmbot/system/debug/debug_router.ex | 97 ------------------- lib/farmbot/system/updates/updates.ex | 2 +- mix.exs | 2 +- mix.lock.host | 2 +- 15 files changed, 28 insertions(+), 141 deletions(-) delete mode 100644 lib/farmbot/system/debug/debug_router.ex diff --git a/formatted_files b/formatted_files index b3f4c79b7..e11ba6627 100644 --- a/formatted_files +++ b/formatted_files @@ -8,3 +8,4 @@ lib/farmbot/repo/worker.ex lib/farmbot/system/gpio/gpio.ex lib/farmbot/asset/farm_event.ex lib/farmbot/asset/regimen.ex +lib/farmbot/jwt.ex diff --git a/lib/farmbot/bootstrap/supervisor.ex b/lib/farmbot/bootstrap/supervisor.ex index 8db57bd8e..acb3bdf41 100644 --- a/lib/farmbot/bootstrap/supervisor.ex +++ b/lib/farmbot/bootstrap/supervisor.ex @@ -146,12 +146,6 @@ defmodule Farmbot.Bootstrap.Supervisor do {:error, reason} -> Farmbot.System.factory_reset(reason) :ignore - - # If we got invalid json, just try again. - # HACK(Connor) Sometimes we don't get valid json - # Just try again if that happened. - {:error, :invalid, _} -> - actual_init(email, pass, server) end end end diff --git a/lib/farmbot/bot_state/transport/http/router.ex b/lib/farmbot/bot_state/transport/http/router.ex index 540acc335..6030762d2 100644 --- a/lib/farmbot/bot_state/transport/http/router.ex +++ b/lib/farmbot/bot_state/transport/http/router.ex @@ -79,4 +79,6 @@ defmodule Farmbot.BotState.Transport.HTTP.Router do {:error, reason, env} -> {:error, reason, env} end end + + defp do_reduce([], env), do: {:ok, env} end diff --git a/lib/farmbot/farm_event/execution/execution.ex b/lib/farmbot/farm_event/execution/execution.ex index 2de7aef46..1ae02482b 100644 --- a/lib/farmbot/farm_event/execution/execution.ex +++ b/lib/farmbot/farm_event/execution/execution.ex @@ -3,6 +3,7 @@ defprotocol Farmbot.FarmEvent.Execution do Protocol to be implemented by any struct that can be executed by Farmbot.FarmEvent.Manager. """ + @dialyzer {:nowarn_function, __protocol__: 1} @typedoc "Data to be executed." @type data :: map diff --git a/lib/farmbot/http/adapter.ex b/lib/farmbot/http/adapter.ex index cd4abf006..521cf3f48 100644 --- a/lib/farmbot/http/adapter.ex +++ b/lib/farmbot/http/adapter.ex @@ -6,7 +6,7 @@ defmodule Farmbot.HTTP.Adapter do @type adapter :: pid @typedoc "HTTP method." - @type method :: :get | :put | :post | :update + @type method :: :get | :put | :post | :delete @typedoc "HTTP url. Must be fully formatted." @type url :: binary diff --git a/lib/farmbot/http/http.ex b/lib/farmbot/http/http.ex index 03cfb5d83..6a3352962 100644 --- a/lib/farmbot/http/http.ex +++ b/lib/farmbot/http/http.ex @@ -75,31 +75,39 @@ defmodule Farmbot.HTTP do end @doc "Same as `post/4` but raises." - @spec post!(url, headers, opts) :: Response.t | no_return + @spec post!(url, body, headers, opts) :: Response.t | no_return def post!(url, body, headers \\ [], opts \\ []) def post!(url, body, headers, opts) do request!(:post, url, body, headers, opts) end + @doc "HTTP PUT request." + @spec put(url, body, headers, opts) :: {:ok, Response.t} | {:error, term} def put(url, body, headers \\ [], opts \\ []) def put(url, body, headers, opts) do request(:put, url, body, headers, opts) end + @doc "Same as `put/4` but raises." + @spec put!(url, body, headers, opts) :: Response.t | no_return def put!(url, body, headers \\ [], opts \\ []) def put!(url, body, headers, opts) do request!(:put, url, body, headers, opts) end + @doc "HTTP DELETE request." + @spec delete(url, headers, opts) :: {:ok, Response.t} | {:error, term} def delete(url, headers \\ [], opts \\ []) def delete(url, headers, opts) do request!(:delete, url, "", headers, opts) end + @doc "Same as `delete/3` but raises." + @spec delete!(url, headers, opts) :: Response.t | no_return def delete!(url, headers \\ [], opts \\ []) def delete!(url, headers, opts) do diff --git a/lib/farmbot/http/httpoison_adapter.ex b/lib/farmbot/http/httpoison_adapter.ex index 94743fde1..98fbaffae 100644 --- a/lib/farmbot/http/httpoison_adapter.ex +++ b/lib/farmbot/http/httpoison_adapter.ex @@ -368,10 +368,6 @@ defmodule Farmbot.HTTP.HTTPoisonAdapter do {:error, %HTTPoison.Error{reason: reason}} -> GenServer.reply(from, {:error, reason}) {:noreply, state} - - {:error, reason} -> - GenServer.reply(from, {:error, reason}) - {:noreply, state} end end @@ -398,10 +394,6 @@ defmodule Farmbot.HTTP.HTTPoisonAdapter do {:error, %HTTPoison.Error{reason: reason}} -> GenServer.reply(buffer.from, {:error, reason}) {:noreply, state} - - {:error, reason} -> - GenServer.reply(buffer.from, {:error, reason}) - {:noreply, state} end end diff --git a/lib/farmbot/jwt.ex b/lib/farmbot/jwt.ex index 5781aeba7..8a7e76ef0 100644 --- a/lib/farmbot/jwt.ex +++ b/lib/farmbot/jwt.ex @@ -9,7 +9,7 @@ defmodule Farmbot.Jwt do :vhost, :os_update_server, :beta_os_update_server, - :interim_email, + :interim_email ] @typedoc "Type def for Farmbot Web Token." @@ -29,8 +29,12 @@ defmodule Farmbot.Jwt do body = tkn |> String.split(".") |> Enum.at(1) with {:ok, json} <- Base.decode64(body, padding: false), - {:ok, jwt} <- Poison.decode(json, as: %__MODULE__{}), - do: {:ok, jwt} + {:ok, jwt} <- Poison.decode(json, as: %__MODULE__{}) do + {:ok, jwt} + else + :error -> {:error, :base64_decode_fail} + {:error, :invalid, _} -> {:error, :json_decode_error} + end end @doc "Decodes a token, raises if it fails." @@ -38,8 +42,7 @@ defmodule Farmbot.Jwt do def decode!(tkn) do case decode(tkn) do {:ok, tkn} -> tkn - :error -> raise "Failed to base64 decode." - {:error, {:invalid, _char, _pos}} -> raise "Failed to json decode." + {:error, reason} -> raise(reason) end end end diff --git a/lib/farmbot/regimen/manager.ex b/lib/farmbot/regimen/manager.ex index 19e2cb8c6..4d67aa18e 100644 --- a/lib/farmbot/regimen/manager.ex +++ b/lib/farmbot/regimen/manager.ex @@ -56,11 +56,7 @@ defmodule Farmbot.Regimen.Manager do regimen = %{regimen | regimen_items: items} epoch = - Farmbot.TimeUtils.build_epoch(time) || - raise Error, - message: "Could not determine EPOCH because no timezone was supplied.", - epoch: :error, - regimen: regimen + Farmbot.TimeUtils.build_epoch(time) initial_state = %{ next_execution: nil, diff --git a/lib/farmbot/regimen/supervisor.ex b/lib/farmbot/regimen/supervisor.ex index f3f0e1ff1..f6855d777 100644 --- a/lib/farmbot/regimen/supervisor.ex +++ b/lib/farmbot/regimen/supervisor.ex @@ -142,7 +142,7 @@ defmodule Farmbot.Regimen.Supervisor do end @doc "Builds a list of supervisor children. Will also delete and not build a child from stale data." - @spec build_children([%PersistentRegimen{}]) :: Supervisor.child_spec() + @spec build_children([%PersistentRegimen{}]) :: [Supervisor.child_spec()] def build_children(prs) do Enum.reject(prs, fn %PersistentRegimen{regimen_id: rid, farm_event_id: feid} -> reg = Asset.get_regimen_by_id(rid, feid) diff --git a/lib/farmbot/system/debug/debug.ex b/lib/farmbot/system/debug/debug.ex index ec3feab3a..81df7e127 100644 --- a/lib/farmbot/system/debug/debug.ex +++ b/lib/farmbot/system/debug/debug.ex @@ -1,26 +1,13 @@ defmodule Farmbot.System.Debug do @moduledoc "Supervisor for Various debugging modules." use Supervisor - alias Plug.Adapters.Cowboy - alias Farmbot.System.DebugRouter def start_link(_, opts) do Supervisor.start_link(__MODULE__, [], opts) end def init([]) do - options = [ - port: 5000, - acceptors: 3, - dispatch: [ - {:_, [ - {:_, Cowboy.Handler, {DebugRouter, []}} - ]} - ], - ] - children = [ - Plug.Adapters.Cowboy.child_spec(:http, DebugRouter, [], options), - ] + children = [] opts = [strategy: :one_for_one] supervise(children, opts) diff --git a/lib/farmbot/system/debug/debug_router.ex b/lib/farmbot/system/debug/debug_router.ex deleted file mode 100644 index e42deb787..000000000 --- a/lib/farmbot/system/debug/debug_router.ex +++ /dev/null @@ -1,97 +0,0 @@ -defmodule Farmbot.System.DebugRouter do - @moduledoc false - - use Plug.Router - use Farmbot.Logger - - # max length of a uploaded file. - @max_length 111_409_842 - - use Plug.Debugger, otp_app: :farmbot - plug(Plug.Logger, log: :debug) - - plug( - Plug.Parsers, - length: @max_length, - parsers: [:urlencoded, :multipart, :json], - json_decoder: Poison - ) - - plug(Plug.Static, from: {:farmbot, "priv/debug/static"}, at: "/") - plug(CORSPlug) - plug(:match) - plug(:dispatch) - - get "/" do - conn |> send_resp(200, make_html("index")) - end - - get "/firmware/upload" do - conn |> send_resp(200, make_html("firmware_upload")) - end - - post "/api/upload_firmware" do - ml = @max_length - {:ok, _body, conn} = Plug.Conn.read_body(conn, length: ml) - - upload = - case conn.body_params do - %{"file" => upload} -> upload - %{"firmware" => upload} -> upload - end - - file = upload.path - - case Path.extname(upload.filename) do - ".hex" -> - Logger.warn(1, "applying debug arduino/farmduino firmware.") - handle_arduino(file, conn) - - ".fw" -> - Logger.warn(1, "applying debug os firmware.") - handle_os(file, conn) - - _ -> - conn |> send_resp(500, "COULD NOT HANDLE #{upload.filename}") - end - end - - get "/api/release_mock.json" do - file = "#{:code.priv_dir(:farmbot)}/debug/templates/release_mock.json.eex" - - url = "http://#{conn.host}:#{conn.port}/api/release_mock.json" - tag_name = conn.params["tag_name"] || "v#{Farmbot.Project.version()}" - target_commitish = conn.params["target_commitish"] || Farmbot.Project.commit - body = conn.params["body"] || "This is a fake release" - - File.cp "_build/rpi3/prod/nerves/images/farmbot-signed.fw", "#{:code.priv_dir(:farmbot)}/debug/static/farmbot-rpi3-#{tag_name}.fw" - fw_asset_url = conn.params["fw_asset_url"] || "http://#{conn.host}:#{conn.port}/farmbot-rpi3-#{tag_name}.fw" - resp = EEx.eval_file(file, [url: url, fw_asset_url: fw_asset_url, tag_name: tag_name, target_commitish: target_commitish, body: body]) - conn - |> put_resp_header("content-type", "Application/JSON") - |> send_resp(200, resp) - end - - match(_, do: send_resp(conn, 404, "Page not found")) - - defp make_html(file) do - "#{:code.priv_dir(:farmbot)}/debug/static/#{file}.html" |> File.read!() - end - - defp handle_arduino(_, conn) do - send_resp(conn, 500, "Not implemented.") - end - - defp handle_os(file, conn) do - case Nerves.Firmware.upgrade_and_finalize(file) do - {:error, reason} -> - conn |> send_resp(400, inspect(reason)) - - :ok -> - conn = send_resp(conn, 200, "UPGRADING") - Process.sleep(2000) - Nerves.Firmware.reboot() - conn - end - end -end diff --git a/lib/farmbot/system/updates/updates.ex b/lib/farmbot/system/updates/updates.ex index 007f705ab..09e92b577 100644 --- a/lib/farmbot/system/updates/updates.ex +++ b/lib/farmbot/system/updates/updates.ex @@ -232,7 +232,7 @@ defmodule Farmbot.System.Updates do {release_version_obj, bdurl} else Logger.debug 3, "Incorrect asset name for target: #{current_target}: #{name}" - try_find_dl_url_in_asset(rest, release_version, current_stuff) + try_find_dl_url_in_asset(rest, release_version_obj, current_stuff) end end diff --git a/mix.exs b/mix.exs index 2e0063324..cadc6d4d4 100644 --- a/mix.exs +++ b/mix.exs @@ -129,7 +129,7 @@ defmodule Farmbot.Mixfile do [ {:ex_doc, "~> 0.18.1", only: :dev}, {:excoveralls, "~> 0.7", only: :test}, - {:dialyxir, "~> 0.5.1", only: :dev, runtime: false}, + {:dialyxir, github: "jeremyjh/dialyxir", only: :dev, runtime: false}, {:credo, "~> 0.9.1", only: [:dev, :test], runtime: false}, {:inch_ex, ">= 0.0.0", only: :dev}, {:mock, "~> 0.2.0", only: :test}, diff --git a/mix.lock.host b/mix.lock.host index 475ae9eaf..5a2e1c7aa 100644 --- a/mix.lock.host +++ b/mix.lock.host @@ -14,7 +14,7 @@ "credo": {:hex, :credo, "0.9.1", "f021affa11b32a94dc2e807a6472ce0914289c9132f99644a97fc84432b202a1", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{: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.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], [], "hexpm"}, - "dialyxir": {:hex, :dialyxir, "0.5.1", "b331b091720fd93e878137add264bac4f644e1ddae07a70bf7062c7862c4b952", [:mix], [], "hexpm"}, + "dialyxir": {:git, "https://github.com/jeremyjh/dialyxir.git", "292191fdb71a10827e7088d01d9ba16461e40369", []}, "distillery": {:hex, :distillery, "1.5.2", "eec18b2d37b55b0bcb670cf2bcf64228ed38ce8b046bb30a9b636a6f5a4c0080", [:mix], [], "hexpm"}, "earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"}, "ecto": {:hex, :ecto, "2.2.8", "a4463c0928b970f2cee722cd29aaac154e866a15882c5737e0038bbfcf03ec2c", [:mix], [{: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"}, From 091f13d834596ab87e44cdad76ff338efb7d433a Mon Sep 17 00:00:00 2001 From: connor rigby Date: Mon, 11 Jun 2018 15:57:34 -0700 Subject: [PATCH 03/67] Add json wrapper --- config/config.exs | 3 ++- formatted_files | 2 ++ lib/farmbot/json/jason_parser.ex | 10 ++++++++++ lib/farmbot/json/json.ex | 25 +++++++++++++++++++++++++ lib/farmbot/json/parser.ex | 7 +++++++ lib/farmbot/jwt.ex | 21 ++++++++++++++++++--- lib/mix/tasks/farmbot/firmware/slack.ex | 1 - mix.exs | 1 + mix.lock.host | 3 ++- test/farmbot/jwt_test.exs | 8 ++++---- 10 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 lib/farmbot/json/jason_parser.ex create mode 100644 lib/farmbot/json/json.ex create mode 100644 lib/farmbot/json/parser.ex diff --git a/config/config.exs b/config/config.exs index c5ffef4e3..a2127cff9 100644 --- a/config/config.exs +++ b/config/config.exs @@ -44,7 +44,8 @@ config :farmbot, :behaviour, authorization: Farmbot.Bootstrap.Authorization, firmware_handler: Farmbot.Firmware.StubHandler, http_adapter: Farmbot.HTTP.HTTPoisonAdapter, - gpio_handler: Farmbot.System.GPIO.StubHandler + gpio_handler: Farmbot.System.GPIO.StubHandler, + json_parser: Farmbot.JSON.JasonParser config :farmbot, :farmware, first_part_farmware_manifest_url: "https://raw.githubusercontent.com/FarmBot-Labs/farmware_manifests/master/manifest.json" diff --git a/formatted_files b/formatted_files index e11ba6627..7e86103d9 100644 --- a/formatted_files +++ b/formatted_files @@ -9,3 +9,5 @@ lib/farmbot/system/gpio/gpio.ex lib/farmbot/asset/farm_event.ex lib/farmbot/asset/regimen.ex lib/farmbot/jwt.ex +lib/farmbot/json/jason_parser.ex +lib/farmbot/json/parser.ex diff --git a/lib/farmbot/json/jason_parser.ex b/lib/farmbot/json/jason_parser.ex new file mode 100644 index 000000000..efdd14430 --- /dev/null +++ b/lib/farmbot/json/jason_parser.ex @@ -0,0 +1,10 @@ +defmodule Farmbot.JSON.JasonParser do + @moduledoc "Parser handler for Jason" + @behaviour Farmbot.JSON.Parser + + def decode(data), do: Jason.decode(data) + def encode(data), do: Jason.encode(data) + + require Protocol + Protocol.derive(Jason.Encoder, Farmbot.Jwt) +end diff --git a/lib/farmbot/json/json.ex b/lib/farmbot/json/json.ex new file mode 100644 index 000000000..adceda4e9 --- /dev/null +++ b/lib/farmbot/json/json.ex @@ -0,0 +1,25 @@ +defmodule Farmbot.JSON do + @moduledoc "Wraps a dependency for easy upgrade and no vendor lock." + + @parser Application.get_env(:farmbot, :behaviour)[:json_parser] + @parser || Mix.raise("Unconfigured JSON Parser.") + @spec decode(iodata) :: {:ok, term} | {:error, term} + def decode(iodata), do: @parser.decode(iodata) + + @spec encode(term) :: {:ok, term} | {:error, term} + def encode(data), do: @parser.encode(data) + + def decode!(iodata) do + case decode(iodata) do + {:ok, results} -> results + {:error, reason} -> raise(reason) + end + end + + def encode!(data) do + case encode(data) do + {:ok, results} -> results + {:error, reason} -> raise(reason) + end + end +end diff --git a/lib/farmbot/json/parser.ex b/lib/farmbot/json/parser.ex new file mode 100644 index 000000000..da0a76c0e --- /dev/null +++ b/lib/farmbot/json/parser.ex @@ -0,0 +1,7 @@ +defmodule Farmbot.JSON.Parser do + @moduledoc """ + Callback module for wrapping a json dependency. + """ + @callback decode(iodata) :: {:ok, term} | {:error, term} + @callback encode(term) :: {:ok, iodata} | {:error, term} +end diff --git a/lib/farmbot/jwt.ex b/lib/farmbot/jwt.ex index 8a7e76ef0..40d1f5022 100644 --- a/lib/farmbot/jwt.ex +++ b/lib/farmbot/jwt.ex @@ -29,11 +29,12 @@ defmodule Farmbot.Jwt do body = tkn |> String.split(".") |> Enum.at(1) with {:ok, json} <- Base.decode64(body, padding: false), - {:ok, jwt} <- Poison.decode(json, as: %__MODULE__{}) do + {:ok, data} <- Farmbot.JSON.decode(json), + {:ok, jwt} <- decode_map(data) do {:ok, jwt} else - :error -> {:error, :base64_decode_fail} - {:error, :invalid, _} -> {:error, :json_decode_error} + :error -> {:error, "base64_decode_fail"} + {:error, _resson} -> {:error, "json_decode_error"} end end @@ -45,4 +46,18 @@ defmodule Farmbot.Jwt do {:error, reason} -> raise(reason) end end + + defp decode_map(%{} = map) do + {:ok, + struct( + Farmbot.Jwt, + bot: map["bot"], + exp: map["exp"], + iss: map["iss"], + mqtt: map["mqtt"], + os_update_server: map["os_update_server"], + vhost: map["vhost"], + interim_email: map["interim_email"] + )} + end end diff --git a/lib/mix/tasks/farmbot/firmware/slack.ex b/lib/mix/tasks/farmbot/firmware/slack.ex index 6252d2a3f..b2c73fd4e 100644 --- a/lib/mix/tasks/farmbot/firmware/slack.ex +++ b/lib/mix/tasks/farmbot/firmware/slack.ex @@ -5,7 +5,6 @@ defmodule Mix.Tasks.Farmbot.Firmware.Slack do use Mix.Task import Mix.Tasks.Farmbot.Env - @dialyzer {[:no_return], [run: 1]} def run(opts) do token = slack_token() diff --git a/mix.exs b/mix.exs index cadc6d4d4..ab811e628 100644 --- a/mix.exs +++ b/mix.exs @@ -102,6 +102,7 @@ defmodule Farmbot.Mixfile do {:gen_stage, "~> 0.12"}, {:phoenix_html, "~> 2.10.5"}, {:poison, "~> 3.1.0"}, + {:jason, "~> 1.0"}, {:httpoison, "~> 1.1"}, {:jsx, "~> 2.8.0"}, {:timex, "~> 3.3"}, diff --git a/mix.lock.host b/mix.lock.host index 5a2e1c7aa..900904e7f 100644 --- a/mix.lock.host +++ b/mix.lock.host @@ -14,7 +14,7 @@ "credo": {:hex, :credo, "0.9.1", "f021affa11b32a94dc2e807a6472ce0914289c9132f99644a97fc84432b202a1", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "db_connection": {:hex, :db_connection, "1.1.3", "89b30ca1ef0a3b469b1c779579590688561d586694a3ce8792985d4d7e575a61", [:mix], [{: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.1", "ad9e501edf7322f122f7fc151cce7c2a0c9ada96f2b0155b8a09a795c2029770", [:mix], [], "hexpm"}, - "dialyxir": {:git, "https://github.com/jeremyjh/dialyxir.git", "292191fdb71a10827e7088d01d9ba16461e40369", []}, + "dialyxir": {:git, "https://github.com/jeremyjh/dialyxir.git", "fa821b418b5e7c54ca7a2f184d55b5310693457c", []}, "distillery": {:hex, :distillery, "1.5.2", "eec18b2d37b55b0bcb670cf2bcf64228ed38ce8b046bb30a9b636a6f5a4c0080", [:mix], [], "hexpm"}, "earmark": {:hex, :earmark, "1.2.4", "99b637c62a4d65a20a9fb674b8cffb8baa771c04605a80c911c4418c69b75439", [:mix], [], "hexpm"}, "ecto": {:hex, :ecto, "2.2.8", "a4463c0928b970f2cee722cd29aaac154e866a15882c5737e0038bbfcf03ec2c", [:mix], [{: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"}, @@ -32,6 +32,7 @@ "httpoison": {:hex, :httpoison, "1.1.1", "96ed7ab79f78a31081bb523eefec205fd2900a02cda6dbc2300e7a1226219566", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, "idna": {:hex, :idna, "5.1.1", "cbc3b2fa1645113267cc59c760bafa64b2ea0334635ef06dbac8801e42f7279c", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, "inch_ex": {:hex, :inch_ex, "0.5.6", "418357418a553baa6d04eccd1b44171936817db61f4c0840112b420b8e378e67", [:mix], [{:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, + "jason": {:hex, :jason, "1.0.0", "0f7cfa9bdb23fed721ec05419bcee2b2c21a77e926bce0deda029b5adc716fe2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, "joken": {:hex, :joken, "1.5.0", "42a0953e80bd933fc98a0874e156771f78bf0e92abe6c3a9c22feb6da28efb0b", [:mix], [{:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}, {:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"}, "jose": {:hex, :jose, "1.8.4", "7946d1e5c03a76ac9ef42a6e6a20001d35987afd68c2107bcd8f01a84e75aa73", [:mix, :rebar3], [{:base64url, "~> 0.0.1", [hex: :base64url, repo: "hexpm", optional: false]}], "hexpm"}, "jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], [], "hexpm"}, diff --git a/test/farmbot/jwt_test.exs b/test/farmbot/jwt_test.exs index 763964169..e6f3674fb 100644 --- a/test/farmbot/jwt_test.exs +++ b/test/farmbot/jwt_test.exs @@ -30,7 +30,7 @@ defmodule Farmbot.JwtTest do tkn = [head, "not_a_valid_token", foot] |> Enum.join(".") r = Jwt.decode(tkn) refute match?({:ok, _}, r) - assert r == :error + assert r == {:error, "base64_decode_fail"} end test "Gives Poison Error when it can't be decoded as json", %{token: tkn} do @@ -39,14 +39,14 @@ defmodule Farmbot.JwtTest do tkn = [head, not_token, foot] |> Enum.join(".") r = Jwt.decode(tkn) refute match?({:ok, _}, r) - assert r == {:error, {:invalid, "h", 0}} + assert r == {:error, "json_decode_error"} end test "raises on bad token because base64", %{token: tkn} do [head, _body, foot] = String.split(tkn, ".") tkn = [head, "not_a_valid_token", foot] |> Enum.join(".") - assert_raise RuntimeError, "Failed to base64 decode.", fn -> + assert_raise RuntimeError, "base64_decode_fail", fn -> Jwt.decode!(tkn) end end @@ -56,7 +56,7 @@ defmodule Farmbot.JwtTest do not_token = Base.encode64("hello world", padding: false) tkn = [head, not_token, foot] |> Enum.join(".") - assert_raise RuntimeError, "Failed to json decode.", fn -> + assert_raise RuntimeError, "json_decode_error", fn -> Jwt.decode!(tkn) end end From d63d3bf1d35c943a946ffd62101818a547bb897f Mon Sep 17 00:00:00 2001 From: connor rigby Date: Mon, 11 Jun 2018 16:09:33 -0700 Subject: [PATCH 04/67] More dialyzir and jwt fix --- lib/farmbot/celery_script/ast/node.ex | 8 +++++--- lib/farmbot/celery_script/ast/node/rpc_request.ex | 7 +++---- lib/farmbot/jwt.ex | 7 ++++--- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/farmbot/celery_script/ast/node.ex b/lib/farmbot/celery_script/ast/node.ex index 165fa8741..fd85bb9ac 100644 --- a/lib/farmbot/celery_script/ast/node.ex +++ b/lib/farmbot/celery_script/ast/node.ex @@ -5,10 +5,12 @@ defmodule Farmbot.CeleryScript.AST.Node do @doc "Decode and validate arguments." @callback decode_args(map) :: {:ok, AST.args} | {:error, term} + @type env :: %Macro.Env{} + @doc "Execute a node" - @callback execute(AST.args, AST.body, Macro.Env.t) :: {:ok, AST.t} | - {:ok, Macro.Env.t} | - {:error, Macro.Env.t, term} + @callback execute(AST.args, AST.body, env) :: {:ok, AST.t, env} | + {:ok, env} | + {:error, term, env} @doc false defmacro __after_compile__(env, _) do diff --git a/lib/farmbot/celery_script/ast/node/rpc_request.ex b/lib/farmbot/celery_script/ast/node/rpc_request.ex index 5254c6daa..b5ca3384c 100644 --- a/lib/farmbot/celery_script/ast/node/rpc_request.ex +++ b/lib/farmbot/celery_script/ast/node/rpc_request.ex @@ -20,9 +20,8 @@ defmodule Farmbot.CeleryScript.AST.Node.RpcRequest do end defp handle_error(ast, label, reason, env) do - case Node.Explanation.execute(%{message: "#{inspect ast} failed: #{inspect reason}"}, [], env) do - {:ok, expl, new_env} -> Node.RpcError.execute(%{label: label}, [expl], new_env) - {:error, reason, env} -> {:error, reason, env} - end + args = %{message: "#{inspect ast} failed: #{inspect reason}"} + {:ok, expl, new_env} = Node.Explanation.execute(args, [], env) + Node.RpcError.execute(%{label: label}, [expl], new_env) end end diff --git a/lib/farmbot/jwt.ex b/lib/farmbot/jwt.ex index 40d1f5022..c4d3275b6 100644 --- a/lib/farmbot/jwt.ex +++ b/lib/farmbot/jwt.ex @@ -50,14 +50,15 @@ defmodule Farmbot.Jwt do defp decode_map(%{} = map) do {:ok, struct( - Farmbot.Jwt, + Farmbot.Jwt, [ bot: map["bot"], exp: map["exp"], iss: map["iss"], mqtt: map["mqtt"], - os_update_server: map["os_update_server"], vhost: map["vhost"], + os_update_server: map["os_update_server"], + beta_os_update_server: map["beta_os_update_server"], interim_email: map["interim_email"] - )} + ])} end end From dc99aad9c2fca2c5e316c6f65413adbf70b2b4bb Mon Sep 17 00:00:00 2001 From: connor rigby Date: Mon, 11 Jun 2018 16:13:44 -0700 Subject: [PATCH 05/67] Format --- lib/farmbot/jwt.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/farmbot/jwt.ex b/lib/farmbot/jwt.ex index c4d3275b6..1086c0fa9 100644 --- a/lib/farmbot/jwt.ex +++ b/lib/farmbot/jwt.ex @@ -50,7 +50,7 @@ defmodule Farmbot.Jwt do defp decode_map(%{} = map) do {:ok, struct( - Farmbot.Jwt, [ + Farmbot.Jwt, bot: map["bot"], exp: map["exp"], iss: map["iss"], @@ -59,6 +59,6 @@ defmodule Farmbot.Jwt do os_update_server: map["os_update_server"], beta_os_update_server: map["beta_os_update_server"], interim_email: map["interim_email"] - ])} + )} end end From c10adff57e0c960e9d8a882117b038350d95661c Mon Sep 17 00:00:00 2001 From: connor rigby Date: Tue, 19 Jun 2018 09:48:02 -0700 Subject: [PATCH 06/67] Update Linux layer. --- mix.exs | 2 +- mix.lock.rpi3 | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/mix.exs b/mix.exs index ab811e628..33d29d720 100644 --- a/mix.exs +++ b/mix.exs @@ -155,7 +155,7 @@ defmodule Farmbot.Mixfile do end defp system("rpi3"), - do: [{:nerves_system_farmbot_rpi3, "1.0.1-farmbot.0", runtime: false}] + do: [{:nerves_system_farmbot_rpi3, "1.1.1-farmbot.0", runtime: false}] defp system("rpi0"), do: [{:nerves_system_farmbot_rpi0, "1.0.0-rc.1-farmbot.0", runtime: false}] diff --git a/mix.lock.rpi3 b/mix.lock.rpi3 index 28c273ac3..ef541d297 100644 --- a/mix.lock.rpi3 +++ b/mix.lock.rpi3 @@ -26,6 +26,7 @@ "hackney": {:hex, :hackney, "1.12.1", "8bf2d0e11e722e533903fe126e14d6e7e94d9b7983ced595b75f532e04b7fdc7", [:rebar3], [{:certifi, "2.3.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "5.1.1", [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, "1.1.1", "96ed7ab79f78a31081bb523eefec205fd2900a02cda6dbc2300e7a1226219566", [:mix], [{:hackney, "~> 1.8", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"}, "idna": {:hex, :idna, "5.1.1", "cbc3b2fa1645113267cc59c760bafa64b2ea0334635ef06dbac8801e42f7279c", [:rebar3], [{:unicode_util_compat, "0.3.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"}, + "jason": {:hex, :jason, "1.0.0", "0f7cfa9bdb23fed721ec05419bcee2b2c21a77e926bce0deda029b5adc716fe2", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"}, "joken": {:hex, :joken, "1.5.0", "42a0953e80bd933fc98a0874e156771f78bf0e92abe6c3a9c22feb6da28efb0b", [:mix], [{:jose, "~> 1.8", [hex: :jose, repo: "hexpm", optional: false]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}, {:poison, "~> 1.5 or ~> 2.0 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: true]}], "hexpm"}, "jose": {:hex, :jose, "1.8.4", "7946d1e5c03a76ac9ef42a6e6a20001d35987afd68c2107bcd8f01a84e75aa73", [:mix, :rebar3], [{:base64url, "~> 0.0.1", [hex: :base64url, repo: "hexpm", optional: false]}], "hexpm"}, "jsx": {:hex, :jsx, "2.8.2", "7acc7d785b5abe8a6e9adbde926a24e481f29956dd8b4df49e3e4e7bcc92a018", [:mix, :rebar3], [], "hexpm"}, @@ -43,8 +44,8 @@ "nerves_network": {:hex, :nerves_network, "0.3.6", "c95779283ace071e9d12882d6a80e31edc8c476012adc61aba2ff6c306ef97b3", [:make, :mix], [{: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.4", "200b1a84bc1a7fdeaf3a1e0e2d4e9b33e240b034e73f39372768d43f8690bae0", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"}, "nerves_runtime": {:hex, :nerves_runtime, "0.5.3", "7447a3e718762f3901046f72cc824e528f8d0565a581b8ae58f4f5b6436bca7f", [: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.0.1", "ca3b6f3c9bad0eadbeef7567a83dbbd87208e290edb2377ff9932609e3806c30", [:mix], [], "hexpm"}, - "nerves_system_farmbot_rpi3": {:hex, :nerves_system_farmbot_rpi3, "1.0.1-farmbot.0", "ff1fdf6a8f46eb21d72a9d8a151ec31caf6ac8c384970d5de42c0c80294ee575", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}, {:nerves_system_br, "~> 1.0.0", [hex: :nerves_system_br, repo: "hexpm", optional: false]}, {:nerves_system_linter, "~> 0.3.0", [hex: :nerves_system_linter, repo: "hexpm", optional: false]}, {:nerves_toolchain_arm_unknown_linux_gnueabihf, "~> 1.0.0", [hex: :nerves_toolchain_arm_unknown_linux_gnueabihf, repo: "hexpm", optional: false]}], "hexpm"}, + "nerves_system_br": {:hex, :nerves_system_br, "1.2.2", "41166311f4d492a4992a6131dca456d4270fb3d216b2673d3a37b1434d30f1d2", [:mix], [], "hexpm"}, + "nerves_system_farmbot_rpi3": {:hex, :nerves_system_farmbot_rpi3, "1.1.1-farmbot.0", "8db53af33d8747504671e2ec0e1ca23395e401509e36294c2d287fecce119397", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}, {:nerves_system_br, "1.2.2", [hex: :nerves_system_br, repo: "hexpm", optional: false]}, {:nerves_system_linter, "~> 0.3.0", [hex: :nerves_system_linter, repo: "hexpm", optional: false]}, {:nerves_toolchain_arm_unknown_linux_gnueabihf, "1.0.0", [hex: :nerves_toolchain_arm_unknown_linux_gnueabihf, repo: "hexpm", optional: false]}], "hexpm"}, "nerves_system_linter": {:hex, :nerves_system_linter, "0.3.0", "84e0f63c8ac196b16b77608bbe7df66dcf352845c4e4fb394bffd2b572025413", [:mix], [], "hexpm"}, "nerves_toolchain_arm_unknown_linux_gnueabihf": {:hex, :nerves_toolchain_arm_unknown_linux_gnueabihf, "1.0.0", "39da5b503b977a594c9e386ca16a50c433b333797bc30ac941fd402ce1832274", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}, {:nerves_toolchain_ctng, "~> 1.4", [hex: :nerves_toolchain_ctng, repo: "hexpm", optional: false]}], "hexpm"}, "nerves_toolchain_ctng": {:hex, :nerves_toolchain_ctng, "1.4.0", "ec844dd286a5281223e023edb1359c8763fef79a3af9daac45397713cff1cb88", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}], "hexpm"}, From f5e3e93b258de3e71fdec9d51dade4a707e76c95 Mon Sep 17 00:00:00 2001 From: connor rigby Date: Tue, 19 Jun 2018 12:47:54 -0700 Subject: [PATCH 07/67] Attempt to fix various amqp buildup --- lib/farmbot/bot_state/transport/amqp/amqp.ex | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/lib/farmbot/bot_state/transport/amqp/amqp.ex b/lib/farmbot/bot_state/transport/amqp/amqp.ex index d50e07960..bfdc2cc17 100644 --- a/lib/farmbot/bot_state/transport/amqp/amqp.ex +++ b/lib/farmbot/bot_state/transport/amqp/amqp.ex @@ -32,7 +32,7 @@ defmodule Farmbot.BotState.Transport.AMQP do defmodule State do @moduledoc false - defstruct [:conn, :chan, :queue_name, :bot, :state_cache] + defstruct [:conn, :chan, :bot, :state_cache] end def init([]) do @@ -42,15 +42,21 @@ defmodule Farmbot.BotState.Transport.AMQP do with {:ok, %{bot: device, mqtt: mqtt_host, vhost: vhost}} <- decode(token), {:ok, conn} <- open_connection(token, device, mqtt_host, vhost), {:ok, chan} <- AMQP.Channel.open(conn), - q_name <- Enum.join([device, UUID.uuid1()], "-"), + q_base <- device, + :ok <- Basic.qos(chan, [global: true]), - {:ok, _} <- AMQP.Queue.declare(chan, q_name, [auto_delete: true]), + {:ok, _} <- AMQP.Queue.declare(chan, q_base <> "_from_clients", [auto_delete: true]), from_clients <- [routing_key: "bot.#{device}.from_clients"], + res <- AMQP.Queue.purge(chan, q_base <> "_from_clients"), + :ok <- AMQP.Queue.bind(chan, q_base <> "_from_clients", @exchange, from_clients), + + {:ok, _} <- AMQP.Queue.declare(chan, q_base <> "_auto_sync", [auto_delete: false]), sync <- [routing_key: "bot.#{device}.sync.#"], - :ok <- AMQP.Queue.bind(chan, q_name, @exchange, from_clients), - :ok <- AMQP.Queue.bind(chan, q_name, @exchange, sync), - {:ok, _tag} <- Basic.consume(chan, q_name, self(), [no_ack: true]), - opts <- [conn: conn, chan: chan, queue_name: q_name, bot: device], + :ok <- AMQP.Queue.bind(chan, q_base <> "_auto_sync", @exchange, sync), + + {:ok, _tag} <- Basic.consume(chan, q_base <> "_from_clients", self(), [no_ack: true]), + {:ok, _tag} <- Basic.consume(chan, q_base <> "_from_clients", self(), [no_ack: true]), + opts <- [conn: conn, chan: chan, bot: device], state <- struct(State, opts) do update_config_value(:bool, "settings", "ignore_fbos_config", false) From 6e525d6639e8e23877d402d5e078615af077db24 Mon Sep 17 00:00:00 2001 From: connor rigby Date: Mon, 25 Jun 2018 11:43:23 -0700 Subject: [PATCH 08/67] Fix bad subscribe --- lib/farmbot/bot_state/transport/amqp/amqp.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/farmbot/bot_state/transport/amqp/amqp.ex b/lib/farmbot/bot_state/transport/amqp/amqp.ex index bfdc2cc17..57a981157 100644 --- a/lib/farmbot/bot_state/transport/amqp/amqp.ex +++ b/lib/farmbot/bot_state/transport/amqp/amqp.ex @@ -55,7 +55,7 @@ defmodule Farmbot.BotState.Transport.AMQP do :ok <- AMQP.Queue.bind(chan, q_base <> "_auto_sync", @exchange, sync), {:ok, _tag} <- Basic.consume(chan, q_base <> "_from_clients", self(), [no_ack: true]), - {:ok, _tag} <- Basic.consume(chan, q_base <> "_from_clients", self(), [no_ack: true]), + {:ok, _tag} <- Basic.consume(chan, q_base <> "_auto_sync", self(), [no_ack: true]), opts <- [conn: conn, chan: chan, bot: device], state <- struct(State, opts) do From ec384eab025b7513cdf55a89c39c300e1dcefcd4 Mon Sep 17 00:00:00 2001 From: connor rigby Date: Mon, 25 Jun 2018 16:04:14 -0700 Subject: [PATCH 09/67] Add module to report soc temperature --- config/target/dev.exs | 5 ++++- lib/farmbot/bot_state/bot_state.ex | 12 +++++++++++- platform/target/soc_temp_worker.ex | 28 ++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 platform/target/soc_temp_worker.ex diff --git a/config/target/dev.exs b/config/target/dev.exs index d7e6795a5..d45b35a97 100644 --- a/config/target/dev.exs +++ b/config/target/dev.exs @@ -36,9 +36,12 @@ config :farmbot, :init, [ # Stops the disk from getting full. Farmbot.Target.Network.TzdataTask, + # Reports SOC temperature to BotState + Farmbot.Target.SocTempWorker, + # Debug stuff Farmbot.System.Debug, - Farmbot.Target.Uevent.Supervisor + Farmbot.Target.Uevent.Supervisor, ] config :farmbot, :transport, [ diff --git a/lib/farmbot/bot_state/bot_state.ex b/lib/farmbot/bot_state/bot_state.ex index c821c0a35..8dc777ae4 100644 --- a/lib/farmbot/bot_state/bot_state.ex +++ b/lib/farmbot/bot_state/bot_state.ex @@ -52,6 +52,10 @@ defmodule Farmbot.BotState do end end + def report_soc_temp(temp_celcius) when is_number(temp_celcius) do + GenStage.call(__MODULE__, {:report_soc_temp, temp_celcius}) + end + def locked? do GenStage.call(__MODULE__, :locked?) end @@ -165,6 +169,11 @@ defmodule Farmbot.BotState do {:noreply, [state], state} end + def handle_call({:report_soc_temp, temp}, _from, state) do + new_info_settings = %{state.informational_settings | soc_temp: temp} + {:reply, :ok, %{state | informational_settings: new_info_settings}} + end + def handle_call(:locked?, _from, state) do {:reply, state.informational_settings.locked, [], state} end @@ -329,7 +338,8 @@ defmodule Farmbot.BotState do sync_status: :booting, last_status: nil, locked: false, - cache_bust: 0 + cache_bust: 0, + soc_temp: 0, }, location_data: %{ position: %{x: nil, y: nil, z: nil}, diff --git a/platform/target/soc_temp_worker.ex b/platform/target/soc_temp_worker.ex new file mode 100644 index 000000000..255a146c2 --- /dev/null +++ b/platform/target/soc_temp_worker.ex @@ -0,0 +1,28 @@ +defmodule Farmbot.Target.SocTempWorker do + use GenServer + def start_link(_, opts) do + GenServer.start_link(__MODULE__, [], opts) + end + + def init([]) do + send(self(), :report_temp) + {:ok, %{}} + end + + def handle_info(:report_temp, state) do + {temp_str, 0} = Nerves.Runtime.cmd("vcgencmd", ["measure_temp"], :return) + temp = temp_str + |> String.trim() + |> String.split("=") + |> List.last() + |> Float.parse + |> elem(0) + if GenServer.whereis(Farmbot.BotState) do + Farmbot.BotState.report_soc_temp(temp) + Process.send_after(self(), :report_temp, 60_000) + else + Process.send_after(self(), :report_temp, 5000) + end + {:noreply, state} + end +end From 642dd322b94fea394e3351fed6c0af873a0e2632 Mon Sep 17 00:00:00 2001 From: connor rigby Date: Mon, 25 Jun 2018 16:21:59 -0700 Subject: [PATCH 10/67] Add soc_temp field to informational_settings --- lib/farmbot/bot_state/bot_state.ex | 3 ++- lib/farmbot/bot_state/transport/amqp/amqp.ex | 2 +- mix.exs | 2 +- mix.lock.rpi3 | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/farmbot/bot_state/bot_state.ex b/lib/farmbot/bot_state/bot_state.ex index 8dc777ae4..9790751f6 100644 --- a/lib/farmbot/bot_state/bot_state.ex +++ b/lib/farmbot/bot_state/bot_state.ex @@ -171,7 +171,8 @@ defmodule Farmbot.BotState do def handle_call({:report_soc_temp, temp}, _from, state) do new_info_settings = %{state.informational_settings | soc_temp: temp} - {:reply, :ok, %{state | informational_settings: new_info_settings}} + state = %{state | informational_settings: new_info_settings} + {:reply, :ok, [state], state} end def handle_call(:locked?, _from, state) do diff --git a/lib/farmbot/bot_state/transport/amqp/amqp.ex b/lib/farmbot/bot_state/transport/amqp/amqp.ex index 57a981157..1a3609b17 100644 --- a/lib/farmbot/bot_state/transport/amqp/amqp.ex +++ b/lib/farmbot/bot_state/transport/amqp/amqp.ex @@ -47,7 +47,7 @@ defmodule Farmbot.BotState.Transport.AMQP do :ok <- Basic.qos(chan, [global: true]), {:ok, _} <- AMQP.Queue.declare(chan, q_base <> "_from_clients", [auto_delete: true]), from_clients <- [routing_key: "bot.#{device}.from_clients"], - res <- AMQP.Queue.purge(chan, q_base <> "_from_clients"), + {:ok, _} <- AMQP.Queue.purge(chan, q_base <> "_from_clients"), :ok <- AMQP.Queue.bind(chan, q_base <> "_from_clients", @exchange, from_clients), {:ok, _} <- AMQP.Queue.declare(chan, q_base <> "_auto_sync", [auto_delete: false]), diff --git a/mix.exs b/mix.exs index 33d29d720..784cdeb09 100644 --- a/mix.exs +++ b/mix.exs @@ -142,7 +142,7 @@ defmodule Farmbot.Mixfile do system(target) ++ [ {:shoehorn, "~> 0.2.0", except: :test}, - {:nerves_runtime, "0.5.3"}, + {:nerves_runtime, "~> 0.6.1"}, {:nerves_firmware, "~> 0.4.0"}, {:nerves_init_gadget, "~> 0.3.0", only: :dev}, {:nerves_network, "~> 0.3"}, diff --git a/mix.lock.rpi3 b/mix.lock.rpi3 index ef541d297..1d3b2a0c3 100644 --- a/mix.lock.rpi3 +++ b/mix.lock.rpi3 @@ -17,7 +17,7 @@ "dns": {:hex, :dns, "2.1.0", "4777fe07ae3060c1d5d75024f05c26d7e11fa701d48a6edb9fc305d24cd12c8c", [:mix], [{:socket, "~> 0.3.13", [hex: :socket, repo: "hexpm", optional: false]}], "hexpm"}, "ecto": {:hex, :ecto, "2.2.8", "a4463c0928b970f2cee722cd29aaac154e866a15882c5737e0038bbfcf03ec2c", [:mix], [{: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_ale": {:hex, :elixir_ale, "1.0.2", "f2b7cadf3d1e2adc67201ef4e725e18f3ee5ff37b80ccb7f1bb812f0f765356d", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"}, - "elixir_make": {:hex, :elixir_make, "0.4.1", "6628b86053190a80b9072382bb9756a6c78624f208ec0ff22cb94c8977d80060", [:mix], [], "hexpm"}, + "elixir_make": {:hex, :elixir_make, "0.4.2", "332c649d08c18bc1ecc73b1befc68c647136de4f340b548844efc796405743bf", [:mix], [], "hexpm"}, "esqlite": {:hex, :esqlite, "0.2.3", "1a8b60877fdd3d50a8a84b342db04032c0231cc27ecff4ddd0d934485d4c0cd5", [:rebar3], [], "hexpm"}, "fs": {:hex, :fs, "3.4.0", "6d18575c250b415b3cad559e6f97a4c822516c7bc2c10bfbb2493a8f230f5132", [:rebar3], [], "hexpm"}, "gen_stage": {:hex, :gen_stage, "0.13.1", "edff5bca9cab22c5d03a834062515e6a1aeeb7665fb44eddae086252e39c4378", [:mix], [], "hexpm"}, @@ -43,7 +43,7 @@ "nerves_leds": {:hex, :nerves_leds, "0.8.0", "193692767dca1a201b09113d242648493b9be0087bab83ebee99c3b0a254f5e1", [:mix], [], "hexpm"}, "nerves_network": {:hex, :nerves_network, "0.3.6", "c95779283ace071e9d12882d6a80e31edc8c476012adc61aba2ff6c306ef97b3", [:make, :mix], [{: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.4", "200b1a84bc1a7fdeaf3a1e0e2d4e9b33e240b034e73f39372768d43f8690bae0", [:make, :mix], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"}, - "nerves_runtime": {:hex, :nerves_runtime, "0.5.3", "7447a3e718762f3901046f72cc824e528f8d0565a581b8ae58f4f5b6436bca7f", [: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_runtime": {:hex, :nerves_runtime, "0.6.1", "0af96a0de0ec85bdbda349aa3bdbe999ce2236640bb21b2c8ca29a03388863b8", [: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.2.2", "41166311f4d492a4992a6131dca456d4270fb3d216b2673d3a37b1434d30f1d2", [:mix], [], "hexpm"}, "nerves_system_farmbot_rpi3": {:hex, :nerves_system_farmbot_rpi3, "1.1.1-farmbot.0", "8db53af33d8747504671e2ec0e1ca23395e401509e36294c2d287fecce119397", [:mix], [{:nerves, "~> 1.0", [hex: :nerves, repo: "hexpm", optional: false]}, {:nerves_system_br, "1.2.2", [hex: :nerves_system_br, repo: "hexpm", optional: false]}, {:nerves_system_linter, "~> 0.3.0", [hex: :nerves_system_linter, repo: "hexpm", optional: false]}, {:nerves_toolchain_arm_unknown_linux_gnueabihf, "1.0.0", [hex: :nerves_toolchain_arm_unknown_linux_gnueabihf, repo: "hexpm", optional: false]}], "hexpm"}, "nerves_system_linter": {:hex, :nerves_system_linter, "0.3.0", "84e0f63c8ac196b16b77608bbe7df66dcf352845c4e4fb394bffd2b572025413", [:mix], [], "hexpm"}, From f91b75ae5d98fe50e7ba8f118ed8a20702018cf2 Mon Sep 17 00:00:00 2001 From: connor rigby Date: Tue, 26 Jun 2018 12:24:18 -0700 Subject: [PATCH 11/67] Bump versions --- CHANGELOG.md | 4 ++++ VERSION | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e66965122..d9ca42f3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +# 6.4.4 +* Optimize AMQP connection +* Add new field on `informational_settings`: `soc_temp` + # 6.4.3 * Fix Ramps firmware build. diff --git a/VERSION b/VERSION index 133cad286..49df80bfe 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -6.4.3 +6.4.4 From 81e34e66f9ba3a2475a34aab0dc00c5d8915c368 Mon Sep 17 00:00:00 2001 From: connor rigby Date: Tue, 26 Jun 2018 13:06:52 -0700 Subject: [PATCH 12/67] Add soc_temp worker to prod config. --- config/target/prod.exs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/target/prod.exs b/config/target/prod.exs index 6f16c319b..37cb81405 100644 --- a/config/target/prod.exs +++ b/config/target/prod.exs @@ -35,6 +35,9 @@ config :farmbot, :init, [ # Stops the disk from getting full. Farmbot.Target.Network.TzdataTask, + # Reports SOC temperature to BotState + Farmbot.Target.SocTempWorker, + # Helps with hot plugging of serial devices. Farmbot.Target.Uevent.Supervisor ] From 50bfc92194c32094d7c23105d445f3312897a20e Mon Sep 17 00:00:00 2001 From: connor rigby Date: Thu, 28 Jun 2018 10:39:29 -0700 Subject: [PATCH 13/67] Add language and charset fields to configurator. --- priv/static/templates/config_wired.html.eex | 7 +- .../templates/config_wireless_step_1.html.eex | 7 +- .../config_wireless_step_2_NONE.html.eex | 7 +- .../config_wireless_step_2_PSK.html.eex | 6 +- .../config_wireless_step_2_custom.html.eex | 7 +- .../config_wireless_step_2_other.html.eex | 7 +- priv/static/templates/credentials.html.eex | 80 +++++------ priv/static/templates/finish.html.eex | 42 +++--- priv/static/templates/firmware.html.eex | 124 +++++++++--------- priv/static/templates/index.html.eex | 57 ++++---- priv/static/templates/network.html.eex | 6 +- 11 files changed, 172 insertions(+), 178 deletions(-) diff --git a/priv/static/templates/config_wired.html.eex b/priv/static/templates/config_wired.html.eex index 4be5daa1d..a05678d82 100644 --- a/priv/static/templates/config_wired.html.eex +++ b/priv/static/templates/config_wired.html.eex @@ -1,8 +1,7 @@ - - - + - + + Configure Farmbot's Network diff --git a/priv/static/templates/config_wireless_step_1.html.eex b/priv/static/templates/config_wireless_step_1.html.eex index f7738e93d..75160f0b6 100644 --- a/priv/static/templates/config_wireless_step_1.html.eex +++ b/priv/static/templates/config_wireless_step_1.html.eex @@ -1,9 +1,8 @@ <% import Phoenix.HTML %> - - - + - + + Configure Farmbot's Network diff --git a/priv/static/templates/config_wireless_step_2_NONE.html.eex b/priv/static/templates/config_wireless_step_2_NONE.html.eex index 507b51760..be8a74f3e 100644 --- a/priv/static/templates/config_wireless_step_2_NONE.html.eex +++ b/priv/static/templates/config_wireless_step_2_NONE.html.eex @@ -1,8 +1,7 @@ - - - + - + + Configure Farmbot's Network diff --git a/priv/static/templates/config_wireless_step_2_PSK.html.eex b/priv/static/templates/config_wireless_step_2_PSK.html.eex index 725f37003..f34452b6d 100644 --- a/priv/static/templates/config_wireless_step_2_PSK.html.eex +++ b/priv/static/templates/config_wireless_step_2_PSK.html.eex @@ -1,7 +1,7 @@ - - - + + + Configure Farmbot's Network + - -

Configure your FarmBot

-
-
-
Firmware
-
-