Dahua VTO to MQTT Broker

Hi @bar, there is bigger issue with your script … as it may end up in creating a lot of connection to MQTT Broker without closing previous one.

How to replicate issue:

  1. Start your script - it will connect with intercom & MQTT Broker
  2. Restart Dahua VTO - it will trigger loop where whole class “DahuaVTOClient” will be executed
  3. When intercom will go up - script will initiate connection again to intercom (no issue here) and 2nd connection to MQTT Broker without closing previous one … and subscribe to topic again - guess what will happen upon x+1 subscriptions?
  4. … and so on

We may set up “self.mqtt_client = mqtt.Client(“VTO2MQTT”)” but it won’t solve issue. It will close previous connection just fine (as only 1 client with same name can be connected to MQTT Broker), but each disconnect will create loop in “def on_mqtt_disconnect(client, userdata, rc)”

Only solution which I see is to remove all MQTT connection related tasks from “class DahuaVTOClient” and initiate it only once upon start. MQTT pahu implementation takes care just fine in restoring connection when it’s broken … so no harm done to this part.

Any other ideas?