From 589061b5c612fdfc634c2cf118e9db3f1a31431c Mon Sep 17 00:00:00 2001 From: connor rigby Date: Tue, 14 Mar 2017 09:37:41 -0700 Subject: [PATCH] fix update checker and replace Logger.debug with Logger.info --- README.md | 4 ++-- config/prod.exs | 2 +- lib/bot_state/trackers/hardware_tracker.ex | 6 +++--- lib/configurator/router.ex | 4 ++-- lib/database/syncable.ex | 2 +- lib/regimen/regimen_runner.ex | 8 ++++---- lib/sequence/sequence_supervisor.ex | 6 +++--- lib/serial/handler.ex | 12 ++++++------ lib/system/farmbot_system_updates.ex | 11 +++++++++++ test/logger_test.exs | 4 ++-- 10 files changed, 35 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 13e03d39..b7fb75e0 100644 --- a/README.md +++ b/README.md @@ -26,14 +26,14 @@ Instalation should be fairly straight forward, you will need a computer for this 0. Plug your SD Card into your RPi3 0. Plug your Arduino into your RPi3 0. Plug your power into your RPi3 - 0. From a WiFi enabled device*, search for the SSID `FarmbotConfigurator` + 0. From a WiFi enabled device*, search for the SSID `farmbot-XXXX` 0. Connect to that and open a web browser to [http://192.168.24.1/](http://192.168.24.1) 0. Follow the on screen instructions to configure your FarmBot. Once you save your configuration FarmBot will connect to your home WiFi network and to the FarmBot web application. \* If you are using a smartphone you may need to disable cellular data to allow your phone's browser to connect to the configurator. ## Updating the firmware -To update the firmware on the Raspberry Pi (Only version 3 for now) and the Arduino (on any rpi), simply use the "update" buttons on the web application. There is no need to reinstall the entire OS. +To update the firmware on the Raspberry Pi simply use the "update" button on the web application. There is no need to reinstall the entire OS. # Problems? diff --git a/config/prod.exs b/config/prod.exs index 469acb73..709201f1 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -6,7 +6,7 @@ config :farmbot, config :tzdata, :data_dir, "/tmp" config :tzdata, :autoupdate, :disabled -config :quantum, cron: [ "5 1 * * *": {Farmbot.Updates.Handler, :do_update_check}] +config :quantum, cron: [ "5 1 * * *": {FFarmbot.System.Updates, :do_update_check}] config :nerves_interim_wifi, regulatory_domain: "US" #FIXME diff --git a/lib/bot_state/trackers/hardware_tracker.ex b/lib/bot_state/trackers/hardware_tracker.ex index 44382db2..55d1b84b 100644 --- a/lib/bot_state/trackers/hardware_tracker.ex +++ b/lib/bot_state/trackers/hardware_tracker.ex @@ -48,7 +48,7 @@ defmodule Farmbot.BotState.Hardware do if !Farmbot.Serial.Handler.available? do # UGHHHHHH - Logger.debug "Waiting for Serial..." + Logger.info "Waiting for Serial..." Process.sleep(100) set_initial_params(state) end @@ -56,11 +56,11 @@ defmodule Farmbot.BotState.Hardware do Farmbot.CeleryScript.Command.read_param(%{label: "param_version"}, []) if Enum.empty?(state.mcu_params) do - Logger.debug "reading all mcu params." + Logger.info "reading all mcu params." Farmbot.CeleryScript.Command.read_all_params(%{}, []) {:ok, :no_params} else - Logger.debug "setting previous mcu commands." + Logger.info "setting previous mcu commands." config_pairs = Enum.map(state.mcu_params, fn({param, val}) -> %Farmbot.CeleryScript.Ast{kind: "pair", args: %{label: param, value: val}, body: []} diff --git a/lib/configurator/router.ex b/lib/configurator/router.ex index bd6e3891..c0ca28c5 100644 --- a/lib/configurator/router.ex +++ b/lib/configurator/router.ex @@ -207,13 +207,13 @@ defmodule Farmbot.Configurator.Router do GenServer.cast(Farmbot.Serial.Handler, {:update_fw, file, self()}) errrm.(conn) else - Logger.debug "doing some magic..." + Logger.info "doing some magic..." herp = Nerves.UART.enumerate() |> Map.drop(["ttyS0","ttyAMA0"]) |> Map.keys case herp do [tty] -> - Logger.debug "magic complete!" + Logger.info "magic complete!" Farmbot.Serial.Handler.flash_firmware(tty, file, self()) errrm.(conn) _ -> diff --git a/lib/database/syncable.ex b/lib/database/syncable.ex index b5eff4f0..2ce518a7 100644 --- a/lib/database/syncable.ex +++ b/lib/database/syncable.ex @@ -60,7 +60,7 @@ defmodule Syncable do @doc false def terminate(_reason, _state) do - Logger.debug "#{unquote(module)} differ died" + Logger.info "#{unquote(module)} differ died" end # HANDLE_CALL diff --git a/lib/regimen/regimen_runner.ex b/lib/regimen/regimen_runner.ex index 6557d3a0..994bf855 100644 --- a/lib/regimen/regimen_runner.ex +++ b/lib/regimen/regimen_runner.ex @@ -37,7 +37,7 @@ defmodule RegimenRunner do first_dt = Timex.shift(epoch, milliseconds: first_item.time_offset) timestr = "#{first_dt.month}/#{first_dt.day}/#{first_dt.year} " <> "at: #{first_dt.hour}:#{first_dt.minute}" - Logger.debug "your fist item will execute on #{timestr}" + Logger.info "your fist item will execute on #{timestr}" millisecond_offset = Timex.diff(first_dt, Timex.now(), :milliseconds) Process.send_after(self(), :execute, millisecond_offset) {:ok, %{epoch: epoch, regimen: %{regimen | regimen_items: items}, next_execution: first_dt}} @@ -58,19 +58,19 @@ defmodule RegimenRunner do if next_item do next_dt = Timex.shift(state.epoch, milliseconds: next_item.time_offset) timestr = "#{next_dt.month}/#{next_dt.day}/#{next_dt.year} at: #{next_dt.hour}:#{next_dt.minute}" - Logger.debug "your next item will execute on #{timestr}" + Logger.info "your next item will execute on #{timestr}" millisecond_offset = Timex.diff(next_dt, Timex.now(), :milliseconds) Process.send_after(self(), :execute, millisecond_offset) {:ok, %{state | regimen: regimen, next_execution: next_dt}} else - Logger.debug ">> #{regimen.name} is complete!" + Logger.info ">> #{regimen.name} is complete!" spawn fn() -> Elixir.Regimen.Supervisor.remove_child(regimen) end {:noreply, :finished} end else - Logger.debug ">> #{regimen.name} is complete!" + Logger.info ">> #{regimen.name} is complete!" spawn fn() -> Elixir.Regimen.Supervisor.remove_child(regimen) end diff --git a/lib/sequence/sequence_supervisor.ex b/lib/sequence/sequence_supervisor.ex index 45f3698f..3272c2ac 100644 --- a/lib/sequence/sequence_supervisor.ex +++ b/lib/sequence/sequence_supervisor.ex @@ -60,12 +60,12 @@ defmodule Sequence.Supervisor do case state.running do {_pid, _sequence} -> # queue up a sequence - Logger.debug ">> is queing up a sequence" + Logger.info ">> is queing up a sequence" q = :queue.in(sequence, state.q) {:reply, {:ok, :queued}, %{state | q: q}} _ -> # start it now - Logger.debug ">> is starting a sequence" + Logger.info ">> is starting a sequence" {:ok, pid} = SequenceRunner.start_link(sequence) {:reply, {:ok, pid}, %{state | running: {pid, sequence}}} end @@ -109,7 +109,7 @@ defmodule Sequence.Supervisor do Logger.info ">> no more sequences to run right now." {:noreply, %{state | q: q, running: nil}} {{:value, sequence}, q} -> - Logger.debug ">> is starting a sequence" + Logger.info ">> is starting a sequence" {:ok, pid} = SequenceRunner.start_link(sequence) {:noreply, %{state | q: q, running: {pid, sequence}}} end diff --git a/lib/serial/handler.ex b/lib/serial/handler.ex index f53d8a25..69546bd3 100644 --- a/lib/serial/handler.ex +++ b/lib/serial/handler.ex @@ -114,14 +114,14 @@ defmodule Farmbot.Serial.Handler do @spec init({nerves, binary}) :: {:ok, state} | :ignore def init({nerves, tty}) do Process.link(nerves) - Logger.debug "Starting serial handler: #{tty}" + Logger.info "Starting serial handler: #{tty}" :ok = open_tty(nerves, tty) update_default(self()) # generate a handshake handshake = generate_handshake() - Logger.debug "doing handshaking: #{handshake}" + Logger.info "doing handshaking: #{handshake}" if do_handshake(nerves, tty, handshake) do UART.write(nerves, "F83 #{handshake}") # ??? @@ -151,7 +151,7 @@ defmodule Farmbot.Serial.Handler do defp do_handshake(nerves, tty, handshake, retries \\ 5) defp do_handshake(_, _, _, 0) do - Logger.debug "Could not handshake: to many retries." + Logger.info "Could not handshake: to many retries." false end @@ -177,7 +177,7 @@ defmodule Farmbot.Serial.Handler do # if it contains our handshake, check if its the right command. # flush the buffer and return if String.contains?(str, handshake) do - Logger.debug "Successfully completed handshake!" + Logger.info "Successfully completed handshake!" "R83 " <> version = String.trim(str, " " <> handshake) Farmbot.BotState.set_fw_version(version) UART.flush(nerves) @@ -213,7 +213,7 @@ defmodule Farmbot.Serial.Handler do # if one existst, unregister it. if old_pid do - Logger.debug "Deregistering #{inspect old_pid} from default Serial Handler" + Logger.info "Deregistering #{inspect old_pid} from default Serial Handler" Process.unregister(__MODULE__) end end @@ -415,7 +415,7 @@ defmodule Farmbot.Serial.Handler do end defp log({_, 0}, pid) do - Logger.debug "FLASHED FIRMWARE!" + Logger.info "FLASHED FIRMWARE!" send pid, :done end diff --git a/lib/system/farmbot_system_updates.ex b/lib/system/farmbot_system_updates.ex index 9cb6a31b..a678c394 100644 --- a/lib/system/farmbot_system_updates.ex +++ b/lib/system/farmbot_system_updates.ex @@ -16,6 +16,17 @@ defmodule Farmbot.System.Updates do @spec mod(atom) :: atom defp mod(target), do: Module.concat([Farmbot, System, target, Updates]) + @doc """ + Checks for updates if the bot says so + """ + def do_update_check do + if Farmbot.BotState.get_config(:os_auto_update) do + check_and_download_updates() + else + Logger.warn ">> Will not do update check!" + end + end + @doc """ Checks for updates, and if there is an update, downloads, and applies it. """ diff --git a/test/logger_test.exs b/test/logger_test.exs index 6c2f2c32..4221518d 100644 --- a/test/logger_test.exs +++ b/test/logger_test.exs @@ -17,7 +17,7 @@ defmodule Farmbot.LoggerTest do Logger.flush use_cassette "good_log_upload" do for i <- 0..51 do - Logger.debug "Farmbot can count to: #{i}" + Logger.info "Farmbot can count to: #{i}" end Process.sleep(3000) @@ -30,7 +30,7 @@ defmodule Farmbot.LoggerTest do test "gets the logger state" do Logger.flush - Logger.debug "hey world" + Logger.info "hey world" state = GenEvent.call(Logger, Farmbot.Logger, :get_state) assert is_list(state.logs) [log] = state.logs