Include ClientID (default: hostname) and default topic
This commit is contained in:
parent
d58745ca2e
commit
58eb806b95
|
@ -3,6 +3,8 @@ import stem.connection
|
|||
import paho.mqtt.client as mqtt
|
||||
import ssl
|
||||
import socks
|
||||
import socket
|
||||
import json
|
||||
import configparser
|
||||
|
||||
configPath = "/etc/torch/"
|
||||
|
@ -16,7 +18,8 @@ sshPort = config['ssh'].getint('Port', fallback = 22)
|
|||
mqttConfig = config['mqtt']
|
||||
mqttBrokerHost = mqttConfig.get('BrokerHost', fallback = "localhost")
|
||||
mqttBrokerPort = mqttConfig.getint('BrokerPort', fallback = 1883)
|
||||
mqttTopic = mqttConfig.get('Topic', fallback = "default/topic")
|
||||
clientID = mqttConfig.get('ClientID', fallback = socket.gethostname())
|
||||
mqttTopic = mqttConfig.get('Topic', fallback = "torch/%s/onion_url" % (clientID))
|
||||
|
||||
mqttRequireCertificate = mqttConfig.getboolean(
|
||||
'RequireCertificate',
|
||||
|
@ -40,6 +43,8 @@ with Controller.from_port(port = torControllerPort) as controller:
|
|||
|
||||
onionAddress = "%s.onion" % (service.service_id)
|
||||
|
||||
payload = { 'clientId': clientID, 'onionAddress': onionAddress }
|
||||
|
||||
client = mqtt.Client()
|
||||
|
||||
if mqttRequireCertificate:
|
||||
|
@ -54,5 +59,5 @@ if mqttBrokerHost.endswith(".onion"):
|
|||
client.tls_insecure_set(True)
|
||||
|
||||
client.connect(mqttBrokerHost, mqttBrokerPort, 60)
|
||||
client.publish(mqttTopic, onionAddress)
|
||||
client.publish(mqttTopic, json.dumps(payload))
|
||||
client.disconnect()
|
||||
|
|
Loading…
Reference in New Issue
Block a user