Skip to content

Commit

Permalink
Merge pull request #367 from mschlenstedt/mqtt_bugfix2
Browse files Browse the repository at this point in the history
Avoid exception if username/pwassword not defined or empty
  • Loading branch information
jasonacox committed Jun 17, 2023
2 parents db521e7 + 8e132ca commit e72f5bd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions server/mqtt/mqtt_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import threading
from queue import Queue

BUILD = "t1"
BUILD = "t2"

# Defaults
DEBUGMODE = False
Expand Down Expand Up @@ -165,8 +165,9 @@ def set_dps(url):
client.will_set(mqttconfig['topic'] + "/running", str("0"), 0, True)
client.connected_flag=False
client.on_connect = on_connect
if mqttconfig['username'] and mqttconfig['password']:
client.username_pw_set(username = mqttconfig['username'],password = mqttconfig['password'])
if 'username' in mqttconfig and 'password' in mqttconfig:
if mqttconfig['username'] != "" and mqttconfig['password'] != "":
client.username_pw_set(username = mqttconfig['username'],password = mqttconfig['password'])
log.debug("Connecting to Broker %s on port %s." % (mqttconfig['broker'], str(mqttconfig['port'])))
client.connect(mqttconfig['broker'], port = int(mqttconfig['port']))

Expand Down Expand Up @@ -202,7 +203,7 @@ def set_dps(url):
time.sleep(0.5)
get_status(id)
# Get status
if last + mqttconfig['pollingtime'] < now:
if last + int(mqttconfig['pollingtime']) < now:
last = time.time()
devices = getdevices()
get_status_all(devices)
Expand Down

0 comments on commit e72f5bd

Please sign in to comment.