     Logger.remove_backend(be)
   end
 
-  # def handle_info(:r_u_alive_bb?, {%Token{} = tkn, %Context{} = ctx}) do
-  #   # debug_log "Got alive checkup"
-  #   Process.send_after(self(), :r_u_alive_bb?, 1000)
-  #   {:noreply, {tkn, ctx}}
-  # end
-
   @spec build_opts(Token.t) :: GenMQTT.option
   defp build_opts(%Token{} = token) do
     [

  def init({%Context{} = context, %Token{} = token}) do
    Logger.info ">> Starting mqtt!", type: :busy
    Process.flag(:trap_exit, true)
    # Process.send_after(self(), :r_u_alive_bb?, 1000)
    {:ok, %{token: token, context: context, cs_nodes: []}}
  end


    {:ok, state}
  end

  def on_connect_error(:invalid_credentials, _) do
    msg = """
    Failed to authenticate with the message broker!
    This is likely a problem with your server/broker configuration.
    """
    Logger.error ">> #{msg}"
    Farmbot.System.factory_reset(msg)
  end

  def on_connect_error(reason, state) do
    Logger.error ">> Failed to connect to mqtt #{state.token.unencoded.mqtt}: #{inspect reason}"
    {:ok, state}
  end

