   def init(args) do
     Process.flag(:sensitive, true)
     jwt = Keyword.fetch!(args, :jwt)
-    {:ok, %State{conn: nil, chan: nil, jwt: jwt}, 1000}
+    http_ping_timer = Process.send_after(self(), :http_ping, 5000)
+
+    state = %State{
+      conn: nil,
+      chan: nil,
+      jwt: jwt,
+      http_ping_timer: http_ping_timer,
+      ping_fails: 0
+    }
+
+    {:ok, state, 1000}
   end
 
   def terminate(reason, state) do

  use GenServer
  use AMQP

  alias FarmbotExt.AMQP.ConnectionWorker

  require Logger
  require FarmbotCore.Logger

  @exchange "amq.topic"

  defstruct [:conn, :chan, :jwt]
  alias __MODULE__, as: State

  @doc false

    end
  end

  def handle_info(:http_ping, state) do
    ms = Enum.random(@lower_bound_ms..@upper_bound_ms)

    case API.get(API.client(), "/api/device") do
      {:ok, _} ->
        http_ping_timer = Process.send_after(self(), :http_ping, ms)
        {:noreply, %{state | http_ping_timer: http_ping_timer, ping_fails: 0}}

      _ ->
        ping_fails = state.ping_fails + 1
        FarmbotCore.Logger.error(3, "Ping failed (#{ping_fails})")
        http_ping_timer = Process.send_after(self(), :http_ping, ms)
        {:noreply, %{state | http_ping_timer: http_ping_timer, ping_fails: ping_fails}}
    end
  end

  # Confirmation sent by the broker after registering this process as a consumer
  def handle_info({:basic_consume_ok, _}, state) do
    {:noreply, state}
