   end
 
   def handle_info({:mqttc, _pid, :disconnected}, state) do
-    IO.puts "Disconnected"
+    Logger.warn("Disconnected")
     {:noreply,state}
   end
 

  end

  def handle_info({:publish, topic_notify, payload}, state = %{topic_notify: topic_notify}) do
    IO.puts "Received notification:"
    IO.inspect payload
    {:noreply, state}
  end

  def handle_info({:publish, unknown_topic, payload}, state) do
    IO.puts "Received:"
    IO.inspect unknown_topic
    IO.inspect payload
    {:noreply, state}
  end


  end

  def handle_cast({:send_event, payload}, state) do
    :emqttc.publish(state.pid, state.topic_event, payload, [qos: 1, retain: true])
    {:noreply, state}
  end

  def handle_info({:mqttc, pid, :connected}, state) do
    send_connected(pid, state.topic_connection)
    Logger.debug("Subscribing to #{state.topic_command}")

    :emqttc.subscribe(pid, state.topic_notify, 1)
    :emqttc.subscribe(pid, state.topic_command, 1)
