   end
 
   def handle_info({:publish, topic_notify, payload}, state = %{topic_notify: topic_notify}) do
-    IO.puts "Received notification:"
-    IO.inspect payload
+    Logger.info("Received notofication: #{inspect payload}")
     {:noreply, state}
   end
 
   def handle_info({:publish, unknown_topic, payload}, state) do
-    IO.puts "Received:"
-    IO.inspect unknown_topic
-    IO.inspect payload
+    Logger.info("Received unknown topic(#{unknown_topic}): #{inspect payload}")
     {:noreply, state}
   end
 

  end

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

  def handle_info({:mqttc, pid, :connected}, state) do
    IO.puts "Connected"

    #TODO: Send connected
    IO.puts "Subscribint to #{state.topic_command}"

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

    topic_notify = "/World/Fog/1/#{pi_name}/Notify"

    ssl = [cacertfile: Path.join(:code.priv_dir(:doorpi), cacert_name)]
    will_payload = Poison.encode!(%{disconnected: %{device: pi_name}})
    {:ok, pid} = :emqttc.start_link([host: host,
                                     port: port,
                                     username: un,
                                     password: pw,
                                     ssl: ssl, reconnect: {3, 120, 10},
                                     auto_resub: true,
                                     will: [qos: 1, reatin: true, topic: topic_connection, payload: will_payload]])
    #Process.send_after(self(), :heart_beat, 500)
    state = %{pid: pid,
              pi_name: pi_name,
