@@ -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
265265def 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 :
0 commit comments