Sfoglia il codice sorgente

resend availability if disconnected

blakeblackshear 6 anni fa
parent
commit
80f7e998ae
2 ha cambiato i file con 7 aggiunte e 3 eliminazioni
  1. 2 1
      README.md
  2. 5 2
      detect_objects.py

+ 2 - 1
README.md

@@ -46,9 +46,10 @@ Access the mjpeg stream at http://localhost:5000
 - [x] Add last will and availability for MQTT
 - [ ] Build tensorflow from source for CPU optimizations
 - [ ] Add ability to turn detection on and off via MQTT
-- [ ] MQTT reconnect if disconnected (and resend availability message)
+- [x] MQTT reconnect if disconnected (and resend availability message)
 - [ ] MQTT motion occasionally gets stuck ON
 - [ ] Output movie clips of people for notifications, etc.
+- [ ] Integrate with homeassistant push camera
 - [x] Store highest scoring person frame from most recent event
 - [x] Add a max size for motion and objects (height/width > 1.5, total area > 1500 and < 100,000)
 - [x] Make motion less sensitive to rain

+ 5 - 2
detect_objects.py

@@ -139,12 +139,15 @@ def main():
     object_cleaner.start()
 
     # connect to mqtt and setup last will
+    def on_connect(client, userdata, flags, rc): 
+        print("On connect called")
+        # publish a message to signal that the service is running
+        client.publish(MQTT_TOPIC_PREFIX+'/available', 'online', retain=True)
     client = mqtt.Client()
+    client.on_connect = on_connect
     client.will_set(MQTT_TOPIC_PREFIX+'/available', payload='offline', qos=1, retain=True)
     client.connect(MQTT_HOST, 1883, 60)
     client.loop_start()
-    # publish a message to signal that the service is running
-    client.publish(MQTT_TOPIC_PREFIX+'/available', 'online', retain=True)
 
     # start a thread to publish object scores (currently only person)
     mqtt_publisher = MqttObjectPublisher(client, MQTT_TOPIC_PREFIX, objects_parsed,