Add module to report soc temperature

pull/566/head
connor rigby 2018-06-25 16:04:14 -07:00
parent 6e525d6639
commit ec384eab02
No known key found for this signature in database
GPG Key ID: 24DC438382965C3B
3 changed files with 43 additions and 2 deletions

View File

@ -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, [

View File

@ -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},

View File

@ -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