@@ -74,10 +74,11 @@ def _mqtt_connect(self, client, userdata, flags, rc):
74
74
def _mqtt_disconnect (self , client , userdata , rc ):
75
75
logger .debug ('Client on_disconnect called.' )
76
76
self ._connected = False
77
- # If this was an unexpected disconnect (non-zero result code) then raise
78
- # an exception.
77
+ # If this was an unexpected disconnect (non-zero result code) then just
78
+ # log the RC as an error. Continue on to call any disconnect handler
79
+ # so clients can potentially recover gracefully.
79
80
if rc != 0 :
80
- raise RuntimeError ('Unexpected disconnect with rc: {0}' .format (rc ))
81
+ logger . debug ('Unexpected disconnect with rc: {0}' .format (rc ))
81
82
# Call the on_disconnect callback if available.
82
83
if self .on_disconnect is not None :
83
84
self .on_disconnect (self )
@@ -94,15 +95,15 @@ def _mqtt_message(self, client, userdata, msg):
94
95
95
96
def connect (self , ** kwargs ):
96
97
"""Connect to the Adafruit.IO service. Must be called before any loop
97
- or publish operations are called. Will raise an exception if a
98
+ or publish operations are called. Will raise an exception if a
98
99
connection cannot be made. Optional keyword arguments will be passed
99
100
to paho-mqtt client connect function.
100
101
"""
101
102
# Skip calling connect if already connected.
102
103
if self ._connected :
103
104
return
104
105
# Connect to the Adafruit IO MQTT service.
105
- self ._client .connect (self ._service_host , port = self ._service_port ,
106
+ self ._client .connect (self ._service_host , port = self ._service_port ,
106
107
keepalive = KEEP_ALIVE_SEC , ** kwargs )
107
108
108
109
def is_connected (self ):
@@ -128,7 +129,7 @@ def loop_blocking(self):
128
129
your program and will not return until disconnect is explicitly called.
129
130
130
131
This is useful if your program doesn't need to do anything else except
131
- listen and respond to Adafruit.IO feed events. If you need to do other
132
+ listen and respond to Adafruit.IO feed events. If you need to do other
132
133
processing, consider using the loop_background function to run a loop
133
134
in the background.
134
135
"""
@@ -139,7 +140,7 @@ def loop(self, timeout_sec=1.0):
139
140
inside your own main loop, where you periodically call this function to
140
141
make sure messages are being processed to and from Adafruit_IO.
141
142
142
- The optional timeout_sec parameter specifies at most how long to block
143
+ The optional timeout_sec parameter specifies at most how long to block
143
144
execution waiting for messages when this function is called. The default
144
145
is one second.
145
146
"""
0 commit comments