mirror of
https://github.com/Schrolli91/BOSWatch.git
synced 2026-01-22 00:00:25 +01:00
added possibility to configure login data for mqtt broker
This commit is contained in:
parent
c75a807ad1
commit
14ab195061
|
|
@ -596,6 +596,9 @@ commandPOC =
|
|||
#Adress from MQTT-Broker
|
||||
brokeraddress = 192.168.178.27
|
||||
topic = alarm/data
|
||||
# username and password for the broker. leave username empty to use anonymous login
|
||||
brokerusername =
|
||||
brokerpassword =
|
||||
|
||||
#####################
|
||||
##### Not ready yet #
|
||||
|
|
|
|||
|
|
@ -77,7 +77,11 @@ def run(typ,freq,data):
|
|||
########## User Plugin CODE ##########
|
||||
broker_address = globalVars.config.get("mqtt", "brokeraddress")
|
||||
topic = globalVars.config.get("mqtt", "topic")
|
||||
mqttClient = mqtt.Client()
|
||||
|
||||
broker_username = globalVars.config.get("mqtt", "brokerusername")
|
||||
broker_password = globalVars.config.get("mqtt", "brokerpassword")
|
||||
|
||||
mqttClient = mqtt.Client()
|
||||
|
||||
if typ == "FMS":
|
||||
x = {
|
||||
|
|
@ -112,6 +116,12 @@ def run(typ,freq,data):
|
|||
logging.warning("Invalid Typ: %s", typ)
|
||||
|
||||
y = json.dumps(x)
|
||||
|
||||
|
||||
## only login if there is a username given
|
||||
if( len(broker_username) > 0 ):
|
||||
mqttClient.username_pw_set(broker_username, broker_password)
|
||||
|
||||
mqttClient.connect(broker_address)
|
||||
mqttClient.publish(topic,y)
|
||||
########## User Plugin CODE ##########
|
||||
|
|
|
|||
Loading…
Reference in a new issue