 
   @interface Application.get_env(:farmbot, :captive_portal_interface, "wlan0")
   @address Application.get_env(:farmbot, :captive_portal_address, "192.168.25.1")
+  @mdns_domain "farmbot-setup.local"
 
   @dnsmasq_conf_file "dnsmasq.conf"
   @dnsmasq_pid_file "dnsmasq.pid"


  def terminate(_, state) do
    Logger.busy 3, "Stopping captive portal GenServer."

    Logger.busy 3, "Stopping DHCP GenServer."
    GenServer.stop(state.dhcp_server, :normal)

    :error
  end

  defp init_mdns(mdns_domain) do
    Mdns.Server.add_service(%Mdns.Server.Service{
      domain: mdns_domain,
      data: :ip,
      ttl: 120,
      type: :a
    })
  end

  defp update_mdns(ip) do
    ip_tuple = to_ip_tuple(ip)
    Mdns.Server.stop()

    # Give the interface time to settle to fix an issue where mDNS's multicast
    # membership is not registered. This occurs on wireless interfaces and
    # needs to be revisited.
    :timer.sleep(100)

    Mdns.Server.start(interface: ip_tuple)
    Mdns.Server.set_ip(ip_tuple)
  end

  defp to_ip_tuple(str) do
    str
    |> String.split(".")
    |> Enum.map(&String.to_integer/1)
    |> List.to_tuple()
  end

end
