Skip to content

Commit

Permalink
Merge pull request #620 from FarmBot/staging
Browse files Browse the repository at this point in the history
6.4.9
  • Loading branch information
ConnorRigby authored Aug 13, 2018
2 parents 2ef237d + 837f069 commit fd00163
Show file tree
Hide file tree
Showing 30 changed files with 206 additions and 272 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Changelog
# 6.4.9
* Add feature to save logs to sdcard for debugging.
* Fix bug causing long running Farmwares to fail.
* Make sure to clear eeprom before flashing Arduino firmware.
* Update Linux system layer.

# 6.4.8
* Make sure not to crash if a wifi network is malformed.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The "brains" of the FarmBot Project
# :floppy_disk: LATEST OS IMAGE DOWNLOADS
<!-- DON'T CHANGE THE TEXT ABOVE. It is used in documentation links. -->

:star: **[RPi 3 (Ships with FarmBot.io kits)](https://github.com/FarmBot/farmbot_os/releases/download/v6.4.7/farmbot-rpi3-6.4.7.img)**
:star: **[RPi 3 (Ships with FarmBot.io kits)](https://github.com/FarmBot/farmbot_os/releases/download/v6.4.8/farmbot-rpi3-6.4.8.img)**
---

## Installation
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.4.8
6.4.9
14 changes: 11 additions & 3 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ env = Mix.env()

config :logger, [
utc_log: true,
# handle_otp_reports: true,
# handle_sasl_reports: true,
backends: [RingLogger]
handle_otp_reports: true,
handle_sasl_reports: true,
backends: [:console]
]

# Randomly picked 300 megabytes.
# 3964928 bytes == ~4 megabytes in sqlite3
# 9266 logs = ~4 megabytes
# 4 logs * 75 = 300 megabytes
# 9266 logs * 75 = 694950 logs
# This will trim 175000 logs (25%) every time it gets to the max logs.
config :logger_backend_ecto, max_logs: 700000

# Stop lager redirecting :error_logger messages
config :lager, :error_logger_redirect, false

Expand Down
10 changes: 6 additions & 4 deletions config/host/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,16 @@ config :farmbot, ecto_repos: [Farmbot.Repo, Farmbot.System.ConfigStorage]
config :farmbot, Farmbot.Repo,
adapter: Sqlite.Ecto2,
loggers: [],
database: "tmp/#{Farmbot.Repo}_dev.sqlite3",
pool_size: 1
database: "tmp/#{Farmbot.Repo}_dev.sqlite3"

config :farmbot, Farmbot.System.ConfigStorage,
adapter: Sqlite.Ecto2,
loggers: [],
database: "tmp/#{Farmbot.System.ConfigStorage}_dev.sqlite3",
pool_size: 1
database: "tmp/#{Farmbot.System.ConfigStorage}_dev.sqlite3"

config :logger_backend_ecto, LoggerBackendEcto.Repo,
adapter: Sqlite.Ecto2,
database: "tmp/logs.sqlite3"

config :farmbot, :farmware, first_part_farmware_manifest_url: nil
config :farmbot, default_server: "https://staging.farm.bot"
Expand Down
7 changes: 4 additions & 3 deletions config/host/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ config :farmbot, :behaviour,
system_tasks: Farmbot.Test.SystemTasks,
update_handler: FarmbotTestSupport.TestUpdateHandler


config :farmbot, Farmbot.Repo, [
adapter: Sqlite.Ecto2,
database: "test_tmp/farmbot_repo_test",
priv: "priv/repo",
pool_size: 2,
loggers: []
]

config :farmbot, Farmbot.System.ConfigStorage, [
adapter: Sqlite.Ecto2,
database: "test_tmp/farmbot_config_storage_test",
pool_size: 2,
loggers: []
]

config :logger_backend_ecto, LoggerBackendEcto.Repo,
adapter: Sqlite.Ecto2,
database: "test_tmp/debug_logs.sqlite3"

config :farmbot, ecto_repos: [Farmbot.Repo, Farmbot.System.ConfigStorage]
4 changes: 4 additions & 0 deletions config/target/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ config :farmbot, Farmbot.System.ConfigStorage,
loggers: [],
database: "/root/config-#{Mix.env()}.sqlite3"

config :logger_backend_ecto, LoggerBackendEcto.Repo,
adapter: Sqlite.Ecto2,
database: "/root/debug_logs.sqlite3"

config :farmbot, ecto_repos: [Farmbot.Repo, Farmbot.System.ConfigStorage]

# Configure your our init system.
Expand Down
11 changes: 4 additions & 7 deletions config/target/prod.exs
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
use Mix.Config

config :logger, [
utc_log: true,
handle_otp_reports: true,
handle_sasl_reports: true,
backends: [RingLogger]
]

config :farmbot, data_path: "/root"

# Disable tzdata autoupdates because it tries to dl the update file
Expand All @@ -23,6 +16,10 @@ config :farmbot, Farmbot.System.ConfigStorage,
loggers: [],
database: "/root/config-#{Mix.env()}.sqlite3"

config :logger_backend_ecto, LoggerBackendEcto.Repo,
adapter: Sqlite.Ecto2,
database: "/root/debug_logs.sqlite3"

config :farmbot, ecto_repos: [Farmbot.Repo, Farmbot.System.ConfigStorage]

# Configure your our init system.
Expand Down
11 changes: 3 additions & 8 deletions lib/farmbot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule Farmbot do
end

def init([]) do
RingLogger.attach()
# RingLogger.attach()
children = [
{Farmbot.Logger.Supervisor, []},
{Farmbot.System.Supervisor, []},
Expand All @@ -38,13 +38,8 @@ defmodule Farmbot do
end

def prep_stop(_state) do
formatted = Farmbot.Logger.format_logs()

formatted
|> Enum.join("\n")
|> Farmbot.System.stop()

formatted
# logs = LoggerBackendEcto.all_logs()
Logger.remove_backend(LoggerBackendEcto)
end

def stop(_data) do
Expand Down
10 changes: 2 additions & 8 deletions lib/farmbot/bot_state/transport/amqp/amqp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,13 @@ defmodule Farmbot.BotState.Transport.AMQP do
{:noreply, [], state}
else
case Poison.decode(payload) do
{:ok, %{"body" => nil}} ->
# If the settings were reset remotely, just set migrated to true,
# which will cause FBOS to download the defaults and apply them.
pl = %{"api_migrated" => true} |> Poison.encode!()
Farmbot.HTTP.put!("/api/fbos_config", pl)
Farmbot.Bootstrap.SettingsSync.run()
{:noreply, [], state}
{:ok, %{"body" => config}} ->
{:ok, %{"body" => %{"api_migrated" => true} = config}} ->
# Logger.info 1, "Got fbos config from amqp: #{inspect config}"
old = state.state_cache.configuration
updated = Farmbot.Bootstrap.SettingsSync.apply_fbos_map(old, config)
push_bot_state(state.chan, state.bot, %{state.state_cache | configuration: updated})
{:noreply, [], state}
_ -> {:noreply, [], state}
end
end
end
Expand Down
16 changes: 14 additions & 2 deletions lib/farmbot/bot_state/transport/http/http.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,20 @@ defmodule Farmbot.BotState.Transport.HTTP do
public_key = body |> JOSE.JWK.from_pem
# FIXME(Connor) The router should probably
# be put in an externally supervised module..
opts = [port: @port, acceptors: 2, dispatch: [cowboy_dispatch()]]
case Plug.Adapters.Cowboy2.http Router, [], opts do
protocol_options = [
idle_timeout: :infinity,
shutdown_timeout: :infinity,
inactivity_timeout: :infinity,
shutdown_timeout: :infinity,
request_timeout: :infinity
]
opts = [
port: @port,
acceptors: 2,
dispatch: [cowboy_dispatch()],
protocol_options: protocol_options
]
case Plug.Adapters.Cowboy2.http(Router, [], opts) do
{:ok, web} ->
state = %{web: web, bot_state: nil, sockets: [], public_key: public_key}
Process.link(state.web)
Expand Down
13 changes: 10 additions & 3 deletions lib/farmbot/firmware/uart_handler/update.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,21 @@ defmodule Farmbot.Firmware.UartHandler.Update do

# Farmduino
defp do_flash("F", uart, tty) do
avrdude("#{:code.priv_dir(:farmbot)}/eeprom_clear.ino.hex", uart, tty)
Process.sleep(1000)
avrdude("#{:code.priv_dir(:farmbot)}/farmduino.hex", uart, tty)
end

defp do_flash("G", uart, tty) do
avrdude("#{:code.priv_dir(:farmbot)}/eeprom_clear.ino.hex", uart, tty)
Process.sleep(1000)
avrdude("#{:code.priv_dir(:farmbot)}/farmduino_k14.hex", uart, tty)
end

# Anything else. (should always be "R")
defp do_flash(_, uart, tty) do
avrdude("#{:code.priv_dir(:farmbot)}/eeprom_clear.ino.hex", uart, tty)
Process.sleep(1000)
avrdude("#{:code.priv_dir(:farmbot)}/arduino_firmware.hex", uart, tty)
end

Expand All @@ -141,17 +147,18 @@ defmodule Farmbot.Firmware.UartHandler.Update do

def avrdude(fw_file, uart, tty) do
close(uart)
Logger.busy 3, "Starting avrdude."
Logger.busy 3, "Starting avrdude: #{fw_file}"
args = ~w"-q -q -patmega2560 -cwiring -P#{tty} -b#{@uart_speed} -D -V -Uflash:w:#{fw_file}:i"
opts = [stderr_to_stdout: true, into: IO.stream(:stdio, :line)]
res = System.cmd("avrdude", args, opts)
Process.sleep(1500) # wait to allow file descriptors to be closed.
case res do
{_, 0} ->
Logger.success 1, "Firmware flashed!"
Logger.success 1, "Firmware flashed! #{fw_file}"
:ok
{_, err_code} ->
Logger.error 1, "Failed to flash Firmware! #{err_code}"
Logger.error 1, "Failed to flash Firmware! #{fw_file} #{err_code}"
Farmbot.Firmware.Utils.replace_firmware_handler(Farmbot.Firmware.StubHandler)
:error
end
end
Expand Down
9 changes: 8 additions & 1 deletion lib/farmbot/logger/logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,14 @@ defmodule Farmbot.Logger do
file: env.file,
line: env.line,
module: env.module])
logger_meta = [function: fun, file: env.file, line: env.line, module: env.module, time: time]
logger_meta = [
application: :farmbot,
function: fun,
file: env.file,
line: env.line,
module: env.module,
time: time
]
logger_level = if level in [:info, :debug, :warn, :error], do: level, else: :info
Elixir.Logger.bare_log(logger_level, log, logger_meta)
{:noreply, [log], state}
Expand Down
41 changes: 0 additions & 41 deletions lib/farmbot/logger/net_logger.ex

This file was deleted.

1 change: 0 additions & 1 deletion lib/farmbot/system/init/ecto.ex
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ defmodule Farmbot.System.Init.Ecto do
migrated = migrator.(repo, migrations_path, :up, opts)
pid && repo.stop(pid)
Mix.Ecto.restart_apps_if_migrated(apps, migrated)
Logger.remove_backend Logger.Backends.Console
Process.sleep(500)
end
end
3 changes: 2 additions & 1 deletion lib/farmbot/system/init/fs_checkup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Farmbot.System.Init.FSCheckup do
@moduledoc false
use Supervisor
use Farmbot.Logger

@behaviour Farmbot.System.Init
@data_path Application.get_env(:farmbot, :data_path)
@data_path || Mix.raise("Unconfigured data path.")
Expand Down Expand Up @@ -46,6 +46,7 @@ defmodule Farmbot.System.Init.FSCheckup do
Logger.busy(3, "Deleting: #{fw}")
File.rm_rf(fw)
end
Elixir.Logger.add_backend(LoggerBackendEcto)
:ok

err ->
Expand Down
7 changes: 0 additions & 7 deletions lib/farmbot/system/system.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ defmodule Farmbot.System do
"""
@type unparsed_reason :: any

@doc "Called when the Application stops."
@callback stop(String.t) :: any

@doc """
Should remove all persistant data. this includes:
* network config
Expand All @@ -42,10 +39,6 @@ defmodule Farmbot.System do
@doc "Shuts down the machine."
@callback shutdown(reason) :: no_return

def stop(data) do
@system_tasks.stop(data)
end

@doc "Remove all configuration data, and reboot."
@spec factory_reset(unparsed_reason) :: no_return
def factory_reset(reason) do
Expand Down
Loading

0 comments on commit fd00163

Please sign in to comment.