Skip to content

Commit

Permalink
Release of version 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
liuszeng committed Oct 12, 2016
1 parent cb67058 commit 41ead94
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 31 deletions.
104 changes: 101 additions & 3 deletions AWSIoTPythonSDK/MQTTLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import core.shadow.shadowManager as shadowManager
# import deviceShadow
import core.shadow.deviceShadow as deviceShadow

# Constants
# - Protocol types:
MQTTv3_1 = 3
Expand All @@ -30,7 +29,6 @@
DROP_NEWEST = 1
#


class AWSIoTMQTTClient:

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

# Configuration APIs
def configureLastWill(self, topic, payload, QoS):
"""
**Description**
Used to configure the last will topic, payload and QoS of the client. Should be called before connect.
**Syntax**
.. code:: python
myAWSIoTMQTTClient.configureLastWill("last/Will/Topic", "lastWillPayload", 0)
**Parameters**
*topic* - Topic name that last will publishes to.
*payload* - Payload to publish for last will.
*QoS* - Quality of Service. Could be 0 or 1.
**Returns**
None
"""
# mqttCore.setLastWill(srcTopic, srcPayload, srcQos)
self._mqttCore.setLastWill(topic, payload, QoS)

def clearLastWill(self):
"""
**Description**
Used to clear the last will configuration that is previously set through configureLastWill.
**Syntax**
..code:: python
myAWSIoTMQTTClient.clearLastWill()
**Parameter**
None
**Returns**
None
"""
#mqttCore.clearLastWill()
self._mqttCore.clearLastWill()

def configureEndpoint(self, hostName, portNumber):
"""
**Description**
Expand Down Expand Up @@ -399,7 +447,7 @@ def publish(self, topic, payload, QoS):
*payload* - Payload to publish.
*QoS* - Quality of Service. Could be 0 ot 1.
*QoS* - Quality of Service. Could be 0 or 1.
**Returns**
Expand Down Expand Up @@ -525,6 +573,56 @@ def __init__(self, clientID, protocolType=MQTTv3_1_1, useWebsocket=False, cleanS
self._shadowManager = shadowManager.shadowManager(self._AWSIoTMQTTClient._mqttCore)

# Configuration APIs
def configureLastWill(self, topic, payload, QoS):
"""
**Description**
Used to configure the last will topic, payload and QoS of the client. Should be called before connect.
**Syntax**
.. code:: python
myAWSIoTMQTTClient.configureLastWill("last/Will/Topic", "lastWillPayload", 0)
**Parameters**
*topic* - Topic name that last will publishes to.
*payload* - Payload to publish for last will.
*QoS* - Quality of Service. Could be 0 or 1.
**Returns**
None
"""
# AWSIoTMQTTClient.configureLastWill(srcTopic, srcPayload, srcQos)
self._AWSIoTMQTTClient.configureLastWill(topic, payload, QoS)

def clearLastWill(self):
"""
**Description**
Used to clear the last will configuration that is previously set through configureLastWill.
**Syntax**
..code:: python
myAWSIoTShadowMQTTClient.clearLastWill()
**Parameter**
None
**Returns**
None
"""
# AWSIoTMQTTClient.clearLastWill()
self._AWSIoTMQTTClient.clearLastWill()

def configureEndpoint(self, hostName, portNumber):
"""
**Description**
Expand Down
5 changes: 3 additions & 2 deletions AWSIoTPythonSDK/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import sys
sys.path.insert(0, os.path.dirname(__file__))

__version__ = "1.0.1"
__version__ = "1.1.0"


39 changes: 24 additions & 15 deletions AWSIoTPythonSDK/core/protocol/mqttCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
import time
import logging
import threading
import core.protocol.paho.client as mqtt
import core.util.offlinePublishQueue as offlinePublishQueue
import AWSIoTPythonSDK.core.protocol.paho.client as mqtt
import AWSIoTPythonSDK.core.util.offlinePublishQueue as offlinePublishQueue
from threading import Lock
from core.exception.AWSIoTExceptions import connectError
from core.exception.AWSIoTExceptions import connectTimeoutException
from core.exception.AWSIoTExceptions import disconnectError
from core.exception.AWSIoTExceptions import disconnectTimeoutException
from core.exception.AWSIoTExceptions import publishError
from core.exception.AWSIoTExceptions import publishQueueFullException
from core.exception.AWSIoTExceptions import publishQueueDisabledException
from core.exception.AWSIoTExceptions import subscribeError
from core.exception.AWSIoTExceptions import subscribeTimeoutException
from core.exception.AWSIoTExceptions import unsubscribeError
from core.exception.AWSIoTExceptions import unsubscribeTimeoutException
from AWSIoTPythonSDK.exception.AWSIoTExceptions import connectError
from AWSIoTPythonSDK.exception.AWSIoTExceptions import connectTimeoutException
from AWSIoTPythonSDK.exception.AWSIoTExceptions import disconnectError
from AWSIoTPythonSDK.exception.AWSIoTExceptions import disconnectTimeoutException
from AWSIoTPythonSDK.exception.AWSIoTExceptions import publishError
from AWSIoTPythonSDK.exception.AWSIoTExceptions import publishQueueFullException
from AWSIoTPythonSDK.exception.AWSIoTExceptions import publishQueueDisabledException
from AWSIoTPythonSDK.exception.AWSIoTExceptions import subscribeError
from AWSIoTPythonSDK.exception.AWSIoTExceptions import subscribeTimeoutException
from AWSIoTPythonSDK.exception.AWSIoTExceptions import unsubscribeError
from AWSIoTPythonSDK.exception.AWSIoTExceptions import unsubscribeTimeoutException

# Class that holds queued publish request details
class _publishRequest:
Expand Down Expand Up @@ -221,6 +221,15 @@ def configIAMCredentials(self, srcAWSAccessKeyID, srcAWSSecretAccessKey, srcAWSS
raise TypeError("None type inputs detected.")
self._pahoClient.configIAMCredentials(srcAWSAccessKeyID, srcAWSSecretAccessKey, srcAWSSessionToken)

def setLastWill(self, srcTopic, srcPayload, srcQos):
if srcTopic is None or srcPayload is None or srcQos is None:
self._log.error("setLastWill: None type inputs detected.")
raise TypeError("None type inputs detected.")
self._pahoClient.will_set(srcTopic, srcPayload, srcQos, False)

def clearLastWill(self):
self._pahoClient.will_clear()

def setBackoffTime(self, srcBaseReconnectTimeSecond, srcMaximumReconnectTimeSecond, srcMinimumConnectTimeSecond):
if srcBaseReconnectTimeSecond is None or srcMaximumReconnectTimeSecond is None or srcMinimumConnectTimeSecond is None:
self._log.error("setBackoffTime: None type inputs detected.")
Expand All @@ -231,7 +240,6 @@ def setBackoffTime(self, srcBaseReconnectTimeSecond, srcMaximumReconnectTimeSeco
self._log.debug("Custom setting for backoff timing: maximumReconnectTime = " + str(srcMaximumReconnectTimeSecond) + " sec")
self._log.debug("Custom setting for backoff timing: minimumConnectTime = " + str(srcMinimumConnectTimeSecond) + " sec")


def setOfflinePublishQueueing(self, srcQueueSize, srcDropBehavior=mqtt.MSG_QUEUEING_DROP_NEWEST):
if srcQueueSize is None or srcDropBehavior is None:
self._log.error("setOfflinePublishQueueing: None type inputs detected.")
Expand Down Expand Up @@ -333,7 +341,8 @@ def publish(self, topic, payload, qos, retain):
if queuedPublishCondition:
if self._connectResultCode == sys.maxsize:
self._log.info("Offline publish request detected.")
if not self._drainingComplete:
# If the client is connected but draining is not completed...
elif not self._drainingComplete:
self._log.info("Drainging is still on-going.")
self._log.info("Try queueing up this request...")
# Publish to the queue and report error (raise Exception)
Expand Down
8 changes: 5 additions & 3 deletions AWSIoTPythonSDK/core/protocol/paho/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
else:
EAGAIN = errno.EAGAIN
# AWS WSS implementation
import core.protocol.paho.securedWebsocket.securedWebsocketCore as wssCore
import core.util.progressiveBackoffCore as backoffCore
import core.util.offlinePublishQueue as offlinePublishQueue
import AWSIoTPythonSDK.core.protocol.paho.securedWebsocket.securedWebsocketCore as wssCore
import AWSIoTPythonSDK.core.util.progressiveBackoffCore as backoffCore
import AWSIoTPythonSDK.core.util.offlinePublishQueue as offlinePublishQueue

VERSION_MAJOR=1
VERSION_MINOR=0
Expand Down Expand Up @@ -989,6 +989,8 @@ def disconnect(self):
self._state = mqtt_cs_disconnecting
self._state_mutex.release()

self._backoffCore.stopStableConnectionTimer()

if self._sock is None and self._ssl is None:
return MQTT_ERR_NO_CONN

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import socket
import base64
import hashlib
from core.util.sigV4Core import sigV4Core
from core.exception.AWSIoTExceptions import wssNoKeyInEnvironmentError
from core.exception.AWSIoTExceptions import wssHandShakeError
from AWSIoTPythonSDK.core.util.sigV4Core import sigV4Core
from AWSIoTPythonSDK.exception.AWSIoTExceptions import wssNoKeyInEnvironmentError
from AWSIoTPythonSDK.exception.AWSIoTExceptions import wssHandShakeError

# This is an internal class that buffers the incoming bytes into an
# internal buffer until it gets the full desired length of bytes.
Expand Down
2 changes: 1 addition & 1 deletion AWSIoTPythonSDK/core/shadow/deviceShadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def shadowUpdate(self, srcJSONPayload, srcCallback, srcTimeout):
.. code:: python
# Retrieve the shadow JSON document from AWS IoT, with a timeout set to 5 seconds
# Update the shadow JSON document from AWS IoT, with a timeout set to 5 seconds
BotShadow.shadowUpdate(newShadowJSONDocumentString, customCallback, 5)
**Parameters**
Expand Down
5 changes: 5 additions & 0 deletions AWSIoTPythonSDK/core/util/progressiveBackoffCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def startStableConnectionTimer(self):
self._resetBackoffTimer = threading.Timer(self._minimumConnectTimeSecond, self._connectionStableThenResetBackoffTime)
self._resetBackoffTimer.start()

def stopStableConnectionTimer(self):
if self._resetBackoffTimer is not None:
# Cancel the timer
self._resetBackoffTimer.cancel()

# Timer callback to reset _currentBackoffTimeSecond
# If the connection is stable for longer than _minimumConnectTimeSecond,
# reset the currentBackoffTimeSecond to _baseReconnectTimeSecond
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# * permissions and limitations under the License.
# */

import core.exception.operationTimeoutException as operationTimeoutException
import core.exception.operationError as operationError
import AWSIoTPythonSDK.exception.operationTimeoutException as operationTimeoutException
import AWSIoTPythonSDK.exception.operationError as operationError


# Serial Exception
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
CHANGELOG
=========

1.1.0
=====
* feature:AWSIoTMQTTClient:last will configuration APIs
* bugfix:Pull request:`#12 <https://github.com/aws/aws-iot-device-sdk-python/pull/12>`__
* bugfix:Pull request:`#14 <https://github.com/aws/aws-iot-device-sdk-python/pull/14>`__
* Addressed issue:`#15 <https://github.com/aws/aws-iot-device-sdk-python/issues/15>`__

1.0.1
=====
* bugfix:Pull request:`#9 <https://github.com/aws/aws-iot-device-sdk-python/pull/9>`__
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ You can initialize and configure the client like this:
# For TLS mutual authentication
myMQTTClient.configureEndpoint("YOUR.ENDPOINT", 8883)
# For Websocket
# myShadowClient.configureEndpoint("YOUR.ENDPOINT", 443)
# myMQTTClient.configureEndpoint("YOUR.ENDPOINT", 443)
myMQTTClient.configureCredentials("YOUR/ROOT/CA/PATH", "PRIVATE/KEY/PATH", "CERTIFICATE/PATH")
# For Websocket, we only need to configure the root CA
# myMQTTClient.configureCredentials("YOUR/ROOT/CA/PATH")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
setup(
name = 'AWSIoTPythonSDK',
packages = ['AWSIoTPythonSDK', "AWSIoTPythonSDK.core", \
"AWSIoTPythonSDK.core.exception", "AWSIoTPythonSDK.core.shadow", \
"AWSIoTPythonSDK.exception", "AWSIoTPythonSDK.core.shadow", \
"AWSIoTPythonSDK.core.util", \
"AWSIoTPythonSDK.core.protocol", "AWSIoTPythonSDK.core.protocol.paho", \
"AWSIoTPythonSDK.core.protocol.paho.securedWebsocket"],
Expand Down

0 comments on commit 41ead94

Please sign in to comment.