1818import time
1919import logging
2020import threading
21- import core .protocol .paho .client as mqtt
22- import core .util .offlinePublishQueue as offlinePublishQueue
21+ import AWSIoTPythonSDK . core .protocol .paho .client as mqtt
22+ import AWSIoTPythonSDK . core .util .offlinePublishQueue as offlinePublishQueue
2323from threading import Lock
24- from core .exception .AWSIoTExceptions import connectError
25- from core .exception .AWSIoTExceptions import connectTimeoutException
26- from core .exception .AWSIoTExceptions import disconnectError
27- from core .exception .AWSIoTExceptions import disconnectTimeoutException
28- from core .exception .AWSIoTExceptions import publishError
29- from core .exception .AWSIoTExceptions import publishQueueFullException
30- from core .exception .AWSIoTExceptions import publishQueueDisabledException
31- from core .exception .AWSIoTExceptions import subscribeError
32- from core .exception .AWSIoTExceptions import subscribeTimeoutException
33- from core .exception .AWSIoTExceptions import unsubscribeError
34- from core .exception .AWSIoTExceptions import unsubscribeTimeoutException
24+ from AWSIoTPythonSDK .exception .AWSIoTExceptions import connectError
25+ from AWSIoTPythonSDK .exception .AWSIoTExceptions import connectTimeoutException
26+ from AWSIoTPythonSDK .exception .AWSIoTExceptions import disconnectError
27+ from AWSIoTPythonSDK .exception .AWSIoTExceptions import disconnectTimeoutException
28+ from AWSIoTPythonSDK .exception .AWSIoTExceptions import publishError
29+ from AWSIoTPythonSDK .exception .AWSIoTExceptions import publishQueueFullException
30+ from AWSIoTPythonSDK .exception .AWSIoTExceptions import publishQueueDisabledException
31+ from AWSIoTPythonSDK .exception .AWSIoTExceptions import subscribeError
32+ from AWSIoTPythonSDK .exception .AWSIoTExceptions import subscribeTimeoutException
33+ from AWSIoTPythonSDK .exception .AWSIoTExceptions import unsubscribeError
34+ from AWSIoTPythonSDK .exception .AWSIoTExceptions import unsubscribeTimeoutException
3535
3636# Class that holds queued publish request details
3737class _publishRequest :
@@ -221,6 +221,15 @@ def configIAMCredentials(self, srcAWSAccessKeyID, srcAWSSecretAccessKey, srcAWSS
221221 raise TypeError ("None type inputs detected." )
222222 self ._pahoClient .configIAMCredentials (srcAWSAccessKeyID , srcAWSSecretAccessKey , srcAWSSessionToken )
223223
224+ def setLastWill (self , srcTopic , srcPayload , srcQos ):
225+ if srcTopic is None or srcPayload is None or srcQos is None :
226+ self ._log .error ("setLastWill: None type inputs detected." )
227+ raise TypeError ("None type inputs detected." )
228+ self ._pahoClient .will_set (srcTopic , srcPayload , srcQos , False )
229+
230+ def clearLastWill (self ):
231+ self ._pahoClient .will_clear ()
232+
224233 def setBackoffTime (self , srcBaseReconnectTimeSecond , srcMaximumReconnectTimeSecond , srcMinimumConnectTimeSecond ):
225234 if srcBaseReconnectTimeSecond is None or srcMaximumReconnectTimeSecond is None or srcMinimumConnectTimeSecond is None :
226235 self ._log .error ("setBackoffTime: None type inputs detected." )
@@ -231,7 +240,6 @@ def setBackoffTime(self, srcBaseReconnectTimeSecond, srcMaximumReconnectTimeSeco
231240 self ._log .debug ("Custom setting for backoff timing: maximumReconnectTime = " + str (srcMaximumReconnectTimeSecond ) + " sec" )
232241 self ._log .debug ("Custom setting for backoff timing: minimumConnectTime = " + str (srcMinimumConnectTimeSecond ) + " sec" )
233242
234-
235243 def setOfflinePublishQueueing (self , srcQueueSize , srcDropBehavior = mqtt .MSG_QUEUEING_DROP_NEWEST ):
236244 if srcQueueSize is None or srcDropBehavior is None :
237245 self ._log .error ("setOfflinePublishQueueing: None type inputs detected." )
@@ -333,7 +341,8 @@ def publish(self, topic, payload, qos, retain):
333341 if queuedPublishCondition :
334342 if self ._connectResultCode == sys .maxsize :
335343 self ._log .info ("Offline publish request detected." )
336- if not self ._drainingComplete :
344+ # If the client is connected but draining is not completed...
345+ elif not self ._drainingComplete :
337346 self ._log .info ("Drainging is still on-going." )
338347 self ._log .info ("Try queueing up this request..." )
339348 # Publish to the queue and report error (raise Exception)
0 commit comments