@@ -74,10 +74,11 @@ def _mqtt_connect(self, client, userdata, flags, rc):
7474 def _mqtt_disconnect (self , client , userdata , rc ):
7575 logger .debug ('Client on_disconnect called.' )
7676 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.
7980 if rc != 0 :
80- raise RuntimeError ('Unexpected disconnect with rc: {0}' .format (rc ))
81+ logger . debug ('Unexpected disconnect with rc: {0}' .format (rc ))
8182 # Call the on_disconnect callback if available.
8283 if self .on_disconnect is not None :
8384 self .on_disconnect (self )
@@ -94,15 +95,15 @@ def _mqtt_message(self, client, userdata, msg):
9495
9596 def connect (self , ** kwargs ):
9697 """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
9899 connection cannot be made. Optional keyword arguments will be passed
99100 to paho-mqtt client connect function.
100101 """
101102 # Skip calling connect if already connected.
102103 if self ._connected :
103104 return
104105 # 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 ,
106107 keepalive = KEEP_ALIVE_SEC , ** kwargs )
107108
108109 def is_connected (self ):
@@ -128,7 +129,7 @@ def loop_blocking(self):
128129 your program and will not return until disconnect is explicitly called.
129130
130131 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
132133 processing, consider using the loop_background function to run a loop
133134 in the background.
134135 """
@@ -139,7 +140,7 @@ def loop(self, timeout_sec=1.0):
139140 inside your own main loop, where you periodically call this function to
140141 make sure messages are being processed to and from Adafruit_IO.
141142
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
143144 execution waiting for messages when this function is called. The default
144145 is one second.
145146 """
0 commit comments