Skip to content

Commit 41ead94

Browse files
committed
Release of version 1.1.0
1 parent cb67058 commit 41ead94

File tree

14 files changed

+153
-31
lines changed

14 files changed

+153
-31
lines changed

AWSIoTPythonSDK/MQTTLib.py

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import core.shadow.shadowManager as shadowManager
2121
# import deviceShadow
2222
import core.shadow.deviceShadow as deviceShadow
23-
2423
# Constants
2524
# - Protocol types:
2625
MQTTv3_1 = 3
@@ -30,7 +29,6 @@
3029
DROP_NEWEST = 1
3130
#
3231

33-
3432
class AWSIoTMQTTClient:
3533

3634
def __init__(self, clientID, protocolType=MQTTv3_1_1, useWebsocket=False, cleanSession=True):
@@ -87,6 +85,56 @@ def __init__(self, clientID, protocolType=MQTTv3_1_1, useWebsocket=False, cleanS
8785
self._mqttCore = mqttCore.mqttCore(clientID, cleanSession, protocolType, useWebsocket)
8886

8987
# Configuration APIs
88+
def configureLastWill(self, topic, payload, QoS):
89+
"""
90+
**Description**
91+
92+
Used to configure the last will topic, payload and QoS of the client. Should be called before connect.
93+
94+
**Syntax**
95+
96+
.. code:: python
97+
myAWSIoTMQTTClient.configureLastWill("last/Will/Topic", "lastWillPayload", 0)
98+
99+
**Parameters**
100+
101+
*topic* - Topic name that last will publishes to.
102+
103+
*payload* - Payload to publish for last will.
104+
105+
*QoS* - Quality of Service. Could be 0 or 1.
106+
107+
**Returns**
108+
109+
None
110+
111+
"""
112+
# mqttCore.setLastWill(srcTopic, srcPayload, srcQos)
113+
self._mqttCore.setLastWill(topic, payload, QoS)
114+
115+
def clearLastWill(self):
116+
"""
117+
**Description**
118+
119+
Used to clear the last will configuration that is previously set through configureLastWill.
120+
121+
**Syntax**
122+
123+
..code:: python
124+
myAWSIoTMQTTClient.clearLastWill()
125+
126+
**Parameter**
127+
128+
None
129+
130+
**Returns**
131+
132+
None
133+
134+
"""
135+
#mqttCore.clearLastWill()
136+
self._mqttCore.clearLastWill()
137+
90138
def configureEndpoint(self, hostName, portNumber):
91139
"""
92140
**Description**
@@ -399,7 +447,7 @@ def publish(self, topic, payload, QoS):
399447
400448
*payload* - Payload to publish.
401449
402-
*QoS* - Quality of Service. Could be 0 ot 1.
450+
*QoS* - Quality of Service. Could be 0 or 1.
403451
404452
**Returns**
405453
@@ -525,6 +573,56 @@ def __init__(self, clientID, protocolType=MQTTv3_1_1, useWebsocket=False, cleanS
525573
self._shadowManager = shadowManager.shadowManager(self._AWSIoTMQTTClient._mqttCore)
526574

527575
# Configuration APIs
576+
def configureLastWill(self, topic, payload, QoS):
577+
"""
578+
**Description**
579+
580+
Used to configure the last will topic, payload and QoS of the client. Should be called before connect.
581+
582+
**Syntax**
583+
584+
.. code:: python
585+
myAWSIoTMQTTClient.configureLastWill("last/Will/Topic", "lastWillPayload", 0)
586+
587+
**Parameters**
588+
589+
*topic* - Topic name that last will publishes to.
590+
591+
*payload* - Payload to publish for last will.
592+
593+
*QoS* - Quality of Service. Could be 0 or 1.
594+
595+
**Returns**
596+
597+
None
598+
599+
"""
600+
# AWSIoTMQTTClient.configureLastWill(srcTopic, srcPayload, srcQos)
601+
self._AWSIoTMQTTClient.configureLastWill(topic, payload, QoS)
602+
603+
def clearLastWill(self):
604+
"""
605+
**Description**
606+
607+
Used to clear the last will configuration that is previously set through configureLastWill.
608+
609+
**Syntax**
610+
611+
..code:: python
612+
myAWSIoTShadowMQTTClient.clearLastWill()
613+
614+
**Parameter**
615+
616+
None
617+
618+
**Returns**
619+
620+
None
621+
622+
"""
623+
# AWSIoTMQTTClient.clearLastWill()
624+
self._AWSIoTMQTTClient.clearLastWill()
625+
528626
def configureEndpoint(self, hostName, portNumber):
529627
"""
530628
**Description**

AWSIoTPythonSDK/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import sys
3-
sys.path.insert(0, os.path.dirname(__file__))
43

5-
__version__ = "1.0.1"
4+
__version__ = "1.1.0"
5+
6+

AWSIoTPythonSDK/core/protocol/mqttCore.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@
1818
import time
1919
import logging
2020
import 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
2323
from 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
3737
class _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)

AWSIoTPythonSDK/core/protocol/paho/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
else:
4646
EAGAIN = errno.EAGAIN
4747
# AWS WSS implementation
48-
import core.protocol.paho.securedWebsocket.securedWebsocketCore as wssCore
49-
import core.util.progressiveBackoffCore as backoffCore
50-
import core.util.offlinePublishQueue as offlinePublishQueue
48+
import AWSIoTPythonSDK.core.protocol.paho.securedWebsocket.securedWebsocketCore as wssCore
49+
import AWSIoTPythonSDK.core.util.progressiveBackoffCore as backoffCore
50+
import AWSIoTPythonSDK.core.util.offlinePublishQueue as offlinePublishQueue
5151

5252
VERSION_MAJOR=1
5353
VERSION_MINOR=0
@@ -989,6 +989,8 @@ def disconnect(self):
989989
self._state = mqtt_cs_disconnecting
990990
self._state_mutex.release()
991991

992+
self._backoffCore.stopStableConnectionTimer()
993+
992994
if self._sock is None and self._ssl is None:
993995
return MQTT_ERR_NO_CONN
994996

AWSIoTPythonSDK/core/protocol/paho/securedWebsocket/securedWebsocketCore.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import socket
3030
import base64
3131
import hashlib
32-
from core.util.sigV4Core import sigV4Core
33-
from core.exception.AWSIoTExceptions import wssNoKeyInEnvironmentError
34-
from core.exception.AWSIoTExceptions import wssHandShakeError
32+
from AWSIoTPythonSDK.core.util.sigV4Core import sigV4Core
33+
from AWSIoTPythonSDK.exception.AWSIoTExceptions import wssNoKeyInEnvironmentError
34+
from AWSIoTPythonSDK.exception.AWSIoTExceptions import wssHandShakeError
3535

3636
# This is an internal class that buffers the incoming bytes into an
3737
# internal buffer until it gets the full desired length of bytes.

AWSIoTPythonSDK/core/shadow/deviceShadow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def shadowUpdate(self, srcJSONPayload, srcCallback, srcTimeout):
329329
330330
.. code:: python
331331
332-
# Retrieve the shadow JSON document from AWS IoT, with a timeout set to 5 seconds
332+
# Update the shadow JSON document from AWS IoT, with a timeout set to 5 seconds
333333
BotShadow.shadowUpdate(newShadowJSONDocumentString, customCallback, 5)
334334
335335
**Parameters**

AWSIoTPythonSDK/core/util/progressiveBackoffCore.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ def startStableConnectionTimer(self):
7878
self._resetBackoffTimer = threading.Timer(self._minimumConnectTimeSecond, self._connectionStableThenResetBackoffTime)
7979
self._resetBackoffTimer.start()
8080

81+
def stopStableConnectionTimer(self):
82+
if self._resetBackoffTimer is not None:
83+
# Cancel the timer
84+
self._resetBackoffTimer.cancel()
85+
8186
# Timer callback to reset _currentBackoffTimeSecond
8287
# If the connection is stable for longer than _minimumConnectTimeSecond,
8388
# reset the currentBackoffTimeSecond to _baseReconnectTimeSecond

AWSIoTPythonSDK/core/exception/AWSIoTExceptions.py renamed to AWSIoTPythonSDK/exception/AWSIoTExceptions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# * permissions and limitations under the License.
1414
# */
1515

16-
import core.exception.operationTimeoutException as operationTimeoutException
17-
import core.exception.operationError as operationError
16+
import AWSIoTPythonSDK.exception.operationTimeoutException as operationTimeoutException
17+
import AWSIoTPythonSDK.exception.operationError as operationError
1818

1919

2020
# Serial Exception

CHANGELOG.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
CHANGELOG
33
=========
44

5+
1.1.0
6+
=====
7+
* feature:AWSIoTMQTTClient:last will configuration APIs
8+
* bugfix:Pull request:`#12 <https://github.com/aws/aws-iot-device-sdk-python/pull/12>`__
9+
* bugfix:Pull request:`#14 <https://github.com/aws/aws-iot-device-sdk-python/pull/14>`__
10+
* Addressed issue:`#15 <https://github.com/aws/aws-iot-device-sdk-python/issues/15>`__
11+
512
1.0.1
613
=====
714
* bugfix:Pull request:`#9 <https://github.com/aws/aws-iot-device-sdk-python/pull/9>`__

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ You can initialize and configure the client like this:
220220
# For TLS mutual authentication
221221
myMQTTClient.configureEndpoint("YOUR.ENDPOINT", 8883)
222222
# For Websocket
223-
# myShadowClient.configureEndpoint("YOUR.ENDPOINT", 443)
223+
# myMQTTClient.configureEndpoint("YOUR.ENDPOINT", 443)
224224
myMQTTClient.configureCredentials("YOUR/ROOT/CA/PATH", "PRIVATE/KEY/PATH", "CERTIFICATE/PATH")
225225
# For Websocket, we only need to configure the root CA
226226
# myMQTTClient.configureCredentials("YOUR/ROOT/CA/PATH")

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
setup(
88
name = 'AWSIoTPythonSDK',
99
packages = ['AWSIoTPythonSDK', "AWSIoTPythonSDK.core", \
10-
"AWSIoTPythonSDK.core.exception", "AWSIoTPythonSDK.core.shadow", \
10+
"AWSIoTPythonSDK.exception", "AWSIoTPythonSDK.core.shadow", \
1111
"AWSIoTPythonSDK.core.util", \
1212
"AWSIoTPythonSDK.core.protocol", "AWSIoTPythonSDK.core.protocol.paho", \
1313
"AWSIoTPythonSDK.core.protocol.paho.securedWebsocket"],

0 commit comments

Comments
 (0)