diff --git a/firmware/lib/firmware/application.ex b/firmware/lib/firmware/application.ex index a3bf5ab..251d100 100644 --- a/firmware/lib/firmware/application.ex +++ b/firmware/lib/firmware/application.ex @@ -21,11 +21,10 @@ defmodule Firmware.Application do # List all child processes to be supervised def children(:host) do - [ - # Children that only run on the host - # Starts a worker by calling: Firmware.Worker.start_link(arg) - # {Firmware.Worker, arg}, - ] + {:ok, _} = Node.start(:"host@0.0.0.0") + Node.set_cookie(:testcookie) + true = Node.connect(:"esrom@nerves.local") + [] end def children(_target) do diff --git a/firmware/mix.exs b/firmware/mix.exs index e472592..b8652d5 100644 --- a/firmware/mix.exs +++ b/firmware/mix.exs @@ -63,7 +63,7 @@ defmodule Firmware.MixProject do def release do [ overwrite: true, - cookie: "#{@app}_cookie", + cookie: "testcookie", include_erts: &Nerves.Release.erts/0, steps: [&Nerves.Release.init/1, :assemble] ] diff --git a/morse/lib/morse/worker.ex b/morse/lib/morse/worker.ex index 31ebe13..873b365 100644 --- a/morse/lib/morse/worker.ex +++ b/morse/lib/morse/worker.ex @@ -1,6 +1,4 @@ defmodule Morse.Worker do - alias Circuits.GPIO - @moduledoc """ Functions to control the signal lamp connected with GPIO. """ @@ -24,32 +22,31 @@ defmodule Morse.Worker do update_progress(0, 100) - {:ok, gpio} = GPIO.open(relay_pin(), :output) - GPIO.write(gpio, @off) + toggle_lamp(@off) Process.sleep(@sleep_start) code |> Enum.with_index() - |> Enum.each(&signal_symbol(gpio, &1, code_length)) + |> Enum.each(&signal_symbol(&1, code_length)) update_progress(100, 100) end - defp signal_symbol(gpio, {?., _index}, _length) do - GPIO.write(gpio, @on) + defp signal_symbol({?., _index}, _length) do + toggle_lamp(@on) Process.sleep(@sleep_short) - GPIO.write(gpio, @off) + toggle_lamp(@off) Process.sleep(@sleep_delay) end - defp signal_symbol(gpio, {?-, _index}, _length) do - GPIO.write(gpio, @on) + defp signal_symbol({?-, _index}, _length) do + toggle_lamp(@on) Process.sleep(@sleep_long) - GPIO.write(gpio, @off) + toggle_lamp(@off) Process.sleep(@sleep_delay) end - defp signal_symbol(_gpio, {?\s, index}, length) do + defp signal_symbol({?\s, index}, length) do Process.sleep(@sleep_pause) update_progress(index, length) end @@ -58,12 +55,27 @@ defmodule Morse.Worker do Morse.Server.update_progress(index / length * 100) end - defp relay_pin() do - Application.fetch_env!(:morse, :relay_pin) - end - defp secret_code do Application.fetch_env!(:morse, :morse_message) |> String.to_charlist() end + + case Mix.Nerves.Utils.mix_target() do + :host -> + def toggle_lamp(state) do + :rpc.call(:"esrom@nerves.local", Morse.Worker, :toggle_lamp, [state]) + end + + _ -> + alias Circuits.GPIO + + def toggle_lamp(state) do + {:ok, gpio} = GPIO.open(relay_pin(), :output) + GPIO.write(gpio, state) + end + + defp relay_pin() do + Application.fetch_env!(:morse, :relay_pin) + end + end end diff --git a/ui/lib/ui_web/channels/user_socket.ex b/ui/lib/ui_web/channels/user_socket.ex index f624af5..5fc032f 100644 --- a/ui/lib/ui_web/channels/user_socket.ex +++ b/ui/lib/ui_web/channels/user_socket.ex @@ -32,7 +32,6 @@ defmodule UiWeb.UserSocket do def id(_socket), do: nil def broadcast_progress(progress) do - IO.puts("in user socket!") UiWeb.Endpoint.broadcast("morse:progress", "update", %{value: progress}) end end