Set local ip address in a info worker instead of once per boot

pull/1035/head
connor rigby 2019-10-01 15:36:20 -07:00 committed by Connor Rigby
parent 74b9b92d5c
commit f5e8cd3e6f
2 changed files with 10 additions and 3 deletions

View File

@ -19,6 +19,8 @@ defmodule FarmbotOS.Platform.Target.InfoWorker.WifiLevel do
Disabling WiFi status reporting
""")
VintageNet.subscribe(["interface", "eth0"])
{:noreply, state}
else
case FarmbotCore.Config.get_network_config("wlan0") do
@ -33,6 +35,14 @@ defmodule FarmbotOS.Platform.Target.InfoWorker.WifiLevel do
end
end
def handle_info(
{VintageNet, ["interface", _, "addresses"], _old, [%{address: address} | _], _meta},
state
) do
FarmbotCore.BotState.set_private_ip(to_string(:inet.ntoa(address)))
{:noreply, state}
end
def handle_info(
{VintageNet, ["interface", "wlan0", "wifi", "access_points"], _, new, _meta},
%{ssid: ssid} = state

View File

@ -65,9 +65,6 @@ defmodule FarmbotOS.Platform.Target.Network.Utils do
_ = :os.cmd('epmd -daemon')
_ = :net_kernel.stop()
FarmbotCore.BotState.set_node_name(to_string(name))
{:ok, ips} = :inet.getif()
ip = ips |> Enum.at(0) |> Tuple.to_list() |> Enum.at(0) |> Tuple.to_list() |> Enum.join(".")
FarmbotCore.BotState.set_private_ip(ip)
:net_kernel.start([name])
end
end