   (mh/subscribe @conn {topic 2}
                 (fn [^String topic _ ^bytes payload]
                   (receive mqtt topic payload))
-                {:on-connection-lost reconnect}))
+                {:on-connection-lost (partial reconnect mqtt) }))
 
 (defn unsubscribe
   "Unsubscribe to mqtt topic"

    (log/debug "Nil message on topic " topic)
    (async/go (async/>!! (:subscribe-channel mqtt) {:topic topic :message (msg/from-bytes message)}))))

(defn reconnect [reason]
  (let [url (or (System/getenv "MQTT_BROKER_URL") "tcp://localhost:1883")]
    (log/debugf "%s%nConnection lost. Attempting reconnect to %s" reason url)
    (connectmqtt url)))

(defn subscribe
  "Subscribe to mqtt topic with message handler function f"

                (try
                  (if-not (mh/connected? @conn)
                    (do
                      (reconnect mqtt nil)
                      (if-not (or (nil? t) (nil? m))
                        (mh/publish @conn t m)))
                    (if-not (or (nil? t) (nil? m))
