some farmware fixes.
This commit is contained in:
parent
44b8b37656
commit
054cc8dd1c
|
@ -36,7 +36,13 @@ defmodule Farmbot.Bootstrap.AuthTask do
|
|||
end
|
||||
|
||||
defp restart_transports do
|
||||
:ok = Supervisor.terminate_child(Farmbot.BotState.Supervisor, Farmbot.BotState.Transport.Supervisor)
|
||||
:ok = Supervisor.terminate_child(Farmbot.Bootstrap.Supervisor, Farmbot.BotState.Transport.Supervisor)
|
||||
case Supervisor.restart_child(Farmbot.Bootstrap.Supervisor, Farmbot.BotState.Transport.Supervisor) do
|
||||
{:ok, _} -> :ok
|
||||
{:error, :running} -> :ok
|
||||
{:error, {:already_started, _}} -> :ok
|
||||
err -> exit(err)
|
||||
end
|
||||
end
|
||||
|
||||
defp refresh_timer(pid) do
|
||||
|
|
|
@ -33,6 +33,7 @@ defmodule Farmbot.Bootstrap.Authorization do
|
|||
Map.fetch(map, "encoded")
|
||||
else
|
||||
:error -> {:error, "unknown error."}
|
||||
{:error, :invalid, _} -> authorize(email, password, server)
|
||||
# If we got maintance mode, a 5xx error etc, just sleep for a few seconds
|
||||
# and try again.
|
||||
{:ok, {{_, code, _}, _, _}} ->
|
||||
|
|
|
@ -35,7 +35,7 @@ defmodule Farmbot.BotState.Transport.GenMQTT do
|
|||
end
|
||||
|
||||
def handle_log_events(logs, {%{client: client} = internal_state, old_bot_state}) do
|
||||
for log <- logs do
|
||||
for %Farmbot.Log{} = log <- logs do
|
||||
if log.module == nil or Module.split(log.module || Elixir.Logger) |> List.first == "Farmbot" do
|
||||
location_data = Map.get(old_bot_state || %{}, :location_data, %{position: %{x: -1, y: -1, z: -1}})
|
||||
meta = %{type: log.level, x: nil, y: nil, z: nil}
|
||||
|
@ -54,11 +54,7 @@ defmodule Farmbot.BotState.Transport.GenMQTT do
|
|||
Client.emit(client, ast)
|
||||
handle_bot_state_events(rest, {internal_state, old_bot_state})
|
||||
new_bot_state ->
|
||||
# json = Poison.encode!(new_bot_state)
|
||||
# GenMQTT.publish(client, "bot/device_2/status", json, 0, false)
|
||||
Client.push_bot_state(client, new_bot_state)
|
||||
# IO.puts "push state"
|
||||
# Logger.success 3, "pushed state (#{new_bot_state.informational_settings.busy}): #{inspect new_bot_state.location_data.position}"
|
||||
handle_bot_state_events(rest, {internal_state, new_bot_state})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,12 +6,14 @@ defmodule Farmbot.BotState.Transport.HTTP.Router do
|
|||
alias Farmbot.BotState.Transport.HTTP
|
||||
alias HTTP.AuthPlug
|
||||
|
||||
if Mix.env() == :dev do
|
||||
use Plug.Debugger, otp_app: :farmbot
|
||||
end
|
||||
|
||||
# if Mix.env() == :dev do
|
||||
# end
|
||||
use Plug.Debugger, otp_app: :farmbot
|
||||
|
||||
plug Plug.Logger, log: :debug
|
||||
plug AuthPlug, env: Mix.env()
|
||||
plug AuthPlug, env: :dev
|
||||
plug(Plug.Parsers, parsers: [:urlencoded, :multipart, :json], json_decoder: Poison)
|
||||
plug :match
|
||||
plug :dispatch
|
||||
|
||||
|
@ -20,6 +22,20 @@ defmodule Farmbot.BotState.Transport.HTTP.Router do
|
|||
send_resp conn, 200, data
|
||||
end
|
||||
|
||||
post "/celery_script" do
|
||||
with {:ok, _, conn} <- conn |> read_body(),
|
||||
{:ok, ast} <- Farmbot.CeleryScript.AST.decode(conn.params)
|
||||
do
|
||||
case Farmbot.CeleryScript.execute(ast) do
|
||||
{:ok, _} -> send_resp(conn, 200, "ok")
|
||||
{:error, reason} when is_binary(reason) or is_atom(reason) -> send_resp conn, 500, reason
|
||||
{:error, reason} -> send_resp conn, 500, "#{inspect reason}"
|
||||
end
|
||||
else
|
||||
err -> send_resp conn, 500, "#{inspect err}"
|
||||
end
|
||||
end
|
||||
|
||||
match _ do
|
||||
send_resp(conn, 404, "oops")
|
||||
end
|
||||
|
|
|
@ -10,8 +10,29 @@ defmodule Farmbot.CeleryScript.AST.Node.SendMessage do
|
|||
msg = String.replace(m, "{{", "<%=")
|
||||
|> String.replace("}}", "%>")
|
||||
|> EEx.eval_string(fetch_bindings())
|
||||
apply(Logger, type, [msg, [channels: channels]])
|
||||
{:ok, env}
|
||||
|
||||
case type do
|
||||
"debug" ->
|
||||
Logger.debug 2, msg, channels: channels
|
||||
{:ok, env}
|
||||
"info" ->
|
||||
Logger.info 2, msg, channels: channels
|
||||
{:ok, env}
|
||||
"busy" ->
|
||||
Logger.budy 2, msg, channels: channels
|
||||
{:ok, env}
|
||||
"success" ->
|
||||
Logger.success 2, msg, channels: channels
|
||||
{:ok, env}
|
||||
"warn" ->
|
||||
Logger.warn 2, msg, channels: channels
|
||||
{:ok, env}
|
||||
"error" ->
|
||||
Logger.error 2, msg, channels: channels
|
||||
{:ok, env}
|
||||
other ->
|
||||
{:error, "unknown type: #{other}", env}
|
||||
end
|
||||
rescue
|
||||
e in CompileError ->
|
||||
{:error, Exception.message(e), env}
|
||||
|
|
|
@ -46,7 +46,7 @@ defmodule Farmbot.Farmware.Runtime do
|
|||
Logger.warn 2, "#{inspect farmware} completed with exit status: #{status}"
|
||||
%{state | exit_status: status}
|
||||
{^port, {:data, data}} ->
|
||||
Logger.info "[#{inspect farmware}] sent data: \r\n===========\r\n\r\n#{data} \r\n===========", color: :NC
|
||||
Logger.info 3, "[#{inspect farmware}] sent data: \r\n===========\r\n\r\n#{data} \r\n===========", color: :NC
|
||||
handle_port(state)
|
||||
end
|
||||
end
|
||||
|
@ -59,7 +59,9 @@ defmodule Farmbot.Farmware.Runtime do
|
|||
|> Enum.filter(&match?(%{"label" => _, "name" => _, "value" => _}, &1))
|
||||
|> Map.new(&format_config(fw_name, &1))
|
||||
|> Map.put("API_TOKEN", token)
|
||||
|> Map.put("FARMWARE_TOKEN", token)
|
||||
|> Map.put("IMAGES_DIR", images_dir)
|
||||
|> Map.put("FARMWARE_URL", "http://localhost:27347/")
|
||||
|> Map.merge(Farmbot.BotState.get_user_env())
|
||||
|> Enum.map(fn({key, val}) -> {to_erl_safe(key), to_erl_safe(val)} end)
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ defmodule Farmbot.Logger do
|
|||
|
||||
defmacro busy(verbosity, message, meta \\ []) do
|
||||
quote bind_quoted: [verbosity: verbosity, message: message, meta: meta] do
|
||||
Farmbot.Logger.dispatch_log(__ENV__, :budy, verbosity, message, meta)
|
||||
Farmbot.Logger.dispatch_log(__ENV__, :busy, verbosity, message, meta)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -93,12 +93,13 @@ defmodule Farmbot.Logger do
|
|||
{fun, ar} -> "#{fun}/#{ar}"
|
||||
nil -> "no_function"
|
||||
end
|
||||
meta_map = Map.new(meta)
|
||||
log = struct(Farmbot.Log, [
|
||||
time: time,
|
||||
level: level,
|
||||
verbosity: verbosity,
|
||||
message: message,
|
||||
meta: meta,
|
||||
meta: meta_map,
|
||||
function: fun,
|
||||
file: env.file,
|
||||
line: env.line,
|
||||
|
|
|
@ -18,8 +18,6 @@ defmodule Farmbot.Repo.ModuleType do
|
|||
def type, do: :string
|
||||
|
||||
def cast(exp) do
|
||||
IO.puts "cast"
|
||||
IO.inspect exp
|
||||
do_cast(exp)
|
||||
end
|
||||
|
||||
|
@ -37,14 +35,10 @@ defmodule Farmbot.Repo.ModuleType do
|
|||
end
|
||||
|
||||
def load(exp) do
|
||||
IO.puts "load"
|
||||
IO.inspect exp
|
||||
{:ok, exp}
|
||||
end
|
||||
|
||||
def dump(exp) do
|
||||
IO.puts "dump"
|
||||
IO.inspect exp
|
||||
{:ok, Module.concat([Farmbot, Repo, exp]) |> to_string()}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue