From 97f8bdd3ac5f09f4943e1bf02b07100e6676d580 Mon Sep 17 00:00:00 2001 From: Benjamin Dweck Date: Thu, 22 Oct 2020 10:32:23 +0200 Subject: [PATCH] Try to disconnect only after publishing --- torch_agent/torch_agent.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/torch_agent/torch_agent.py b/torch_agent/torch_agent.py index 98fee34..415cbf5 100755 --- a/torch_agent/torch_agent.py +++ b/torch_agent/torch_agent.py @@ -56,7 +56,7 @@ def main(): mqtt_cert_file = config_path + mqtt_config.get('CertFile') mqtt_key_file = config_path + mqtt_config.get('KeyFile') - print("Connecting to local TOR controller on port %s" % tor_proxy_port) + print("Connecting to local TOR controller on port %s" % tor_controller_port) with Controller.from_port(port=tor_controller_port) as controller: @@ -72,7 +72,17 @@ def main(): print("Created Tor Hidden Service for local service on port %s at %s" % (ssh_port, onion_address)) + def on_publish(pub_client): + print("Published payload!") + pub_client.disconnect() + + def on_disconnect(): + print("Disconnected!") + client = mqtt.Client() + client.on_publish = on_publish + client.on_disconnect = on_disconnect + protocol = "mqtt" if mqtt_broker_using_tor: @@ -102,7 +112,3 @@ def main(): print("Publishing payload: " + payload) client.publish(mqtt_topic, payload, qos=1) - print("Published payload!") - - client.disconnect() - print("Disconnected from MQTT Broker")