Browse Source

Try to disconnect only after publishing

master
B.J. Dweck 1 year ago
parent
commit
97f8bdd3ac
1 changed files with 11 additions and 5 deletions
  1. +11
    -5
      torch_agent/torch_agent.py

+ 11
- 5
torch_agent/torch_agent.py 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")

Loading…
Cancel
Save