Skip to content

Commit 37104a0

Browse files
authored
Merge pull request #81 from zeridon/paho-2.x
Ugrade and refactor paho to 2.0.0
2 parents 34f1b4f + d4afc04 commit 37104a0

3 files changed

Lines changed: 22 additions & 22 deletions

File tree

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ name = "pypi"
55

66
[packages]
77
bottle = "==0.12.25"
8-
paho-mqtt = "==1.6.1"
8+
paho-mqtt = "==2.0.0"
99

1010
[dev-packages]
1111
pre-commit = "*"

luftdaten2mqtt.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -239,27 +239,27 @@ def route_index():
239239
"""on_connect handler to disconnect and die in case of error"""
240240

241241

242-
def on_connect(client, userdata, flags, rc):
243-
if rc == 0:
242+
def on_connect(client, userdata, flags, reason_code, properties):
243+
if reason_code == 0:
244244
logging.info("Connected to broker %s", MQTT_HOST)
245-
elif rc == 1:
246-
logging.error("Can't connect to MQTT Broker %s. Incorrect protocol", MQTT_HOST)
247-
os._exit(rc)
248-
elif rc == 2:
249-
logging.error("MQTT Broker %s Refused connection. Invalid Client ID", MQTT_HOST)
250-
os._exit(rc)
251-
elif rc == 3:
252-
logging.error("MQTT Broker %s available ", MQTT_HOST)
253-
os._exit(rc)
254-
elif rc == 4:
255-
logging.error("MQTT Broker %s Refused connection. Bad Username/Password", MQTT_HOST)
256-
os._exit(rc)
257-
elif rc == 5:
258-
logging.error("MQTT Broker %s Refused connection. Not Authorized", MQTT_HOST)
259-
os._exit(rc)
245+
elif reason_code == "Unsupported protocol version":
246+
logging.error("Can't connect to MQTT Broker %s. Unsupported protocol version", MQTT_HOST)
247+
os._exit(1)
248+
elif reason_code == "Client identifier not valid":
249+
logging.error("MQTT Broker %s Refused connection. Client identifier not valid", MQTT_HOST)
250+
os._exit(2)
251+
elif reason_code == "Server unavailable":
252+
logging.error("MQTT Broker %s Server unavailable", MQTT_HOST)
253+
os._exit(3)
254+
elif reason_code == "Bad user name or password":
255+
logging.error("MQTT Broker %s Refused connection. Bad user name or password", MQTT_HOST)
256+
os._exit(4)
257+
elif reason_code == "Not authorized":
258+
logging.error("MQTT Broker %s Refused connection. Not authorized", MQTT_HOST)
259+
os._exit(5)
260260
else:
261-
logging.info("Reserved error code (%s), from Broker %s", rc, MQTT_HOST)
262-
os._exit(rc)
261+
logging.info("Reserved error code (%s), from Broker %s", reason_code, MQTT_HOST)
262+
os._exit(99)
263263

264264

265265
def setup():
@@ -279,7 +279,7 @@ def setup():
279279

280280
logging.debug("connecting to mqtt broker %s", MQTT_HOST)
281281
global CLIENT
282-
CLIENT = mqtt.Client(clean_session=True)
282+
CLIENT = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, clean_session=True)
283283

284284
CLIENT.on_connect = on_connect
285285
if MQTT_USER and MQTT_PASS:

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
bottle==0.12.25
2-
paho-mqtt==1.6.1
2+
paho-mqtt==2.0.0

0 commit comments

Comments
 (0)