   end
 
   defp handle_command("ping", id, pid, topic_event) do
-
     timestamp = DateTime.utc_now |> DateTime.to_string
     msg = %{pong: %{id: id, timestamp: timestamp}}
     msg_raw = Poison.encode!(msg)
-    IO.puts msg_raw
-    IO.puts topic_event
     :emqttc.publish(pid, topic_event, msg_raw)
   end
 
   defp handle_command(unknown_command, _id, _pid, _topic_event) do
-    IO.puts "Unknown command: #{unknown_command}"
+    Logger.warn("Unknown command: #{unknown_command}")
+  end
+
+  defp send_connected(pid, topic_connection) do
+    timestamp = DateTime.utc_now |> DateTime.to_string
+    boot_time = "unknown" # TODO: Try to get boot time
+    addresses = "TODO" # TODO: Try to get IP-addresses
+    msg = %{connected: %{boot_time: boot_time, addresses: addresses, timestamp: timestamp}}
+    payload = Poison.encode!(msg)
+    :emqttc.publish(pid, topic_connection, payload, [qos: 1, retain: true])
   end
 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)
