Try to disconnect only after publishing

This commit is contained in:
B.J. Dweck 2020-10-22 10:32:23 +02:00
parent 64b67b08cb
commit 97f8bdd3ac

View File

@ -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")