Skip to content

Commit

Permalink
Paho MQTT v2
Browse files Browse the repository at this point in the history
  • Loading branch information
aneisch committed Feb 17, 2024
1 parent 54f3f24 commit 698f785
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions thermostat_api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@
"uniq_id": thermostat_serial
}

def on_connect(client, userdata, flags, rc):
logging.info("Connected to MQTT")
def on_connect(client, userdata, flags, reason_code, properties):
if reason_code == 0:
logging.info("Connected to MQTT")
else:
return

client.subscribe(f"{thermostat_command_topic}/#")
logging.info(f'''Subscribed to {thermostat_command_topic}/#''')

Expand Down Expand Up @@ -411,7 +415,7 @@ class ThreadingSimpleServer(ThreadingMixIn, HTTPServer):

client = mqttClient.Client(f"thermostat_api_server_{thermostat_serial}")
if "mqtt_username" in locals():
client.username_pw_set(username=mqtt_username,password=mqtt_password)
client.username_pw_set(username=mqtt_username,password=mqtt_password)
server = ThreadingSimpleServer(('0.0.0.0', 8080), MyHttpRequestHandler)

client.on_connect = on_connect
Expand Down

0 comments on commit 698f785

Please sign in to comment.