@@ -58,6 +58,19 @@ def on_message_received(topic, payload, dup, qos, retain, **kwargs):
58
58
if received_count == cmdData .input_count :
59
59
received_all_event .set ()
60
60
61
+ # Callback when the connection successfully connects
62
+ def on_connection_success (connection , callback_data ):
63
+ assert isinstance (callback_data , mqtt .OnConnectionSuccessData )
64
+ print ("Connection Successful with return code: {} session present: {}" .format (callback_data .return_code , callback_data .session_present ))
65
+
66
+ # Callback when a connection attempt fails
67
+ def on_connection_failure (connection , callback_data ):
68
+ assert isinstance (callback_data , mqtt .OnConnectionFailuredata )
69
+ print ("Connection failed with error code: {}" .format (callback_data .error ))
70
+
71
+ # Callback when a connection has been disconnected or shutdown successfully
72
+ def on_connection_closed (connection , callback_data ):
73
+ print ("Connection closed" )
61
74
62
75
if __name__ == '__main__' :
63
76
# Create the proxy options if the data is present in cmdData
@@ -79,7 +92,10 @@ def on_message_received(topic, payload, dup, qos, retain, **kwargs):
79
92
client_id = cmdData .input_clientId ,
80
93
clean_session = False ,
81
94
keep_alive_secs = 30 ,
82
- http_proxy_options = proxy_options )
95
+ http_proxy_options = proxy_options ,
96
+ on_connection_success = on_connection_success ,
97
+ on_connection_failure = on_connection_failure ,
98
+ on_connection_closed = on_connection_closed )
83
99
84
100
if not cmdData .input_is_ci :
85
101
print (f"Connecting to { cmdData .input_endpoint } with client ID '{ cmdData .input_clientId } '..." )
0 commit comments