diff --git a/src/suanni/client.clj b/src/suanni/client.clj index 3692903..74356fa 100644 --- a/src/suanni/client.clj +++ b/src/suanni/client.clj @@ -6,7 +6,8 @@ [objectifier-client.core :as obj] [clojure.core.async :as async :refer [! go-loop event :type (= :motion-detected)) (let [cam (syno/get-camera-by-location! syno-client (:location event))] - (>! image-chan - { - :location (syno/location cam) - :camera-id (syno/id cam) - :snapshot (syno/take-snapshot! cam) - :time (Instant/now) - :camera cam - })) + (try + (>! image-chan + { + :location (syno/location cam) + :camera-id (syno/id cam) + :snapshot (syno/take-snapshot! cam) + :time (Instant/now) + :camera cam + }) + (catch Exception e + (println (.toString e))))) (recur (> summary - :objects - (keys) - (map name) - (str/join " ")))) - (println (str "highlights: " (:output summary)))) - (when (> (count (:objects summary)) 0) - (>! obj-chan - { - :location location - :camera-id camera-id - :detect-time time - :snapshot snapshot - :objects (:objects summary) - :detection-url (:output summary) - })) + (if (exception? summary) + (println (.toString summary)) + (do + (when verbose + (println (str "detected " + (count (:objects summary)) + " objects: " + (->> summary + :objects + (keys) + (map name) + (str/join " ")))) + (println (str "highlights: " (:output summary)))) + (when (> (count (:objects summary)) 0) + (>! obj-chan + { + :location location + :camera-id camera-id + :detect-time time + :snapshot snapshot + :objects (:objects summary) + :detection-url (:output summary) + })))) (recur (! mqtt-chan - {:type :detection-event - :time (Instant/now) - :detection - (select-keys detection-event - [:location - :camera-id - :detect-time - :objects - :detection-url])}) - (recur (! mqtt-chan + {:type :detection-event + :time (Instant/now) + :detection + (select-keys detection-event + [:location + :camera-id + :detect-time + :objects + :detection-url])}) + (recur (SuanNiServer event-chan image-chan obj-chan listener)))