   alias Farmbot.System.ConfigStorage
   alias Nerves.Network
   alias Farmbot.Target.Network.Ntp
-  import Farmbot.Target.Network, only: [test_dns: 0]
+  import Farmbot.Target.Network, only: [test_dns: 0, test_dns: 1]
 
   def get_ip_addr(interface) do
     GenServer.call(:"#{__MODULE__}-#{interface}", :ip)

    {:noreply, %{state | ntp_timer: new_timer}}
  end

  def handle_info(_event, state) do
    # Logger.warn 3, "unhandled network event: #{inspect event}"
    {:noreply, state}
  end

  defp cancel_not_found_timer(timer) do
    # If there was a timer, cancel it.
    if timer do
      Logger.warn 3, "Cancelling Network timer"
      Process.cancel_timer(timer)
    end
    nil
  end

  defp maybe_cancel_and_reset_ntp_timer(timer) do
    if timer do
      Process.cancel_timer(timer)
    end
    # introduce a bit of randomness to avoid dosing ntp servers.
    # I don't think this would ever happen but the default ntpd implementation
    # does this..


    connected = match?({:ok, {:hostent, 'nerves-project.org', [], :inet, 4, _}}, test_dns())
    if connected do
      not_found_timer = cancel_timer(state.not_found_timer)
      dns_timer = restart_dns_timer(state.dns_timer, 45_000)
      {:noreply, %{state | dns_timer: dns_timer, ip_address: ip, connected: true, not_found_timer: not_found_timer, ntp_timer: ntp_timer}}
    else
      {:noreply, %{state | connected: false, ntp_timer: ntp_timer, ip_address: ip}}
    end
