Skip to content

Commit

Permalink
Release of version 1.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
liuszeng committed Jun 19, 2017
1 parent 0505f65 commit f1d0357
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 416 deletions.
14 changes: 9 additions & 5 deletions AWSIoTPythonSDK/MQTTLib.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def configureLastWill(self, topic, payload, QoS):
**Syntax**
.. code:: python
myAWSIoTMQTTClient.configureLastWill("last/Will/Topic", "lastWillPayload", 0)
**Parameters**
Expand All @@ -120,7 +121,8 @@ def clearLastWill(self):
**Syntax**
..code:: python
.. code:: python
myAWSIoTMQTTClient.clearLastWill()
**Parameter**
Expand Down Expand Up @@ -438,8 +440,8 @@ def publish(self, topic, payload, QoS):
# Publish a QoS0 message "myPayload" to topic "myToppic"
myAWSIoTMQTTClient.publish("myTopic", "myPayload", 0)
# Publish a QoS1 message "myPayload2" to topic "myTopic/sub"
myAWSIoTMQTTClient.publish("myTopic/sub", "myPayload", 1)
# Publish a QoS1 message "myPayloadWithQos1" to topic "myTopic/sub"
myAWSIoTMQTTClient.publish("myTopic/sub", "myPayloadWithQos1", 1)
**Parameters**
Expand Down Expand Up @@ -582,6 +584,7 @@ def configureLastWill(self, topic, payload, QoS):
**Syntax**
.. code:: python
myAWSIoTMQTTClient.configureLastWill("last/Will/Topic", "lastWillPayload", 0)
**Parameters**
Expand All @@ -608,7 +611,8 @@ def clearLastWill(self):
**Syntax**
..code:: python
.. code:: python
myAWSIoTShadowMQTTClient.clearLastWill()
**Parameter**
Expand Down Expand Up @@ -784,7 +788,7 @@ def connect(self, keepAliveIntervalSecond=30):
"""
**Description**
Connect to AWS IoT, with user-specific keeoalive interval configuration.
Connect to AWS IoT, with user-specific keepalive interval configuration.
**Syntax**
Expand Down
2 changes: 1 addition & 1 deletion AWSIoTPythonSDK/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys

__version__ = "1.1.1"
__version__ = "1.1.2"


8 changes: 7 additions & 1 deletion AWSIoTPythonSDK/core/protocol/paho/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,13 @@ def reconnect(self):
ssl.match_hostname(self._ssl.getpeercert(), self._host)

self._sock = sock
self._sock.setblocking(0)

if self._ssl and not self._useSecuredWebsocket:
self._ssl.setblocking(0) # For X.509 cert mutual auth.
elif not self._ssl:
self._sock.setblocking(0) # For plain socket
else:
pass # For MQTT over WebSocket

return self._send_connect(self._keepalive, self._clean_session)

Expand Down
15 changes: 4 additions & 11 deletions AWSIoTPythonSDK/core/shadow/deviceShadow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,22 @@
# * permissions and limitations under the License.
# */

import sys
import json
import string
import random
import logging
import uuid
from threading import Timer, Lock, Thread


class _shadowRequestToken:

URN_PREFIX_LENGTH = 9

def __init__(self, srcShadowName, srcClientID):
self._shadowName = srcShadowName
self._clientID = srcClientID
self._sequenceNumber = 0
self._lowercase = string.ascii_lowercase

def getNextToken(self):
ret = self._clientID + "_" + self._shadowName + "_" + str(self._sequenceNumber) + "_" + self._randomString(5)
self._sequenceNumber += 1
return ret

def _randomString(self, lengthOfString):
return "".join(random.choice(self._lowercase) for i in range(lengthOfString))
return uuid.uuid4().urn[self.URN_PREFIX_LENGTH:] # We only need the uuid digits, not the urn prefix


class _basicJSONParser:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
CHANGELOG
=========

1.1.2
=====
* bugfix:Issue:`#28 <https://github.com/aws/aws-iot-device-sdk-python/issues/28>`__
* bugfix:Issue:`#29 <https://github.com/aws/aws-iot-device-sdk-python/issues/29>`__
* bugfix:Pull request:`#32 <https://github.com/aws/aws-iot-device-sdk-python/pull/32>`__
* improvement:Pull request:`#38 <https://github.com/aws/aws-iot-device-sdk-python/pull/38>`__
* bugfix:Pull request:`#45 <https://github.com/aws/aws-iot-device-sdk-python/pull/45>`__
* improvement:Pull request:`#46 <https://github.com/aws/aws-iot-device-sdk-python/pull/46>`__

1.1.1
=====
* bugfix:Issue:`#23 <https://github.com/aws/aws-iot-device-sdk-python/issues/23>`__
Expand Down
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AWS IoT Python SDK for Internet of Things Service
Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.

This product includes software developed by
Amazon Inc (http://www.amazon.com/).
7 changes: 7 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,8 @@ Run the example like this:
python basicPubSub.py -e <endpoint> -r <rootCAFilePath> -c <certFilePath> -k <privateKeyFilePath>
# MQTT over WebSocket
python basicPubSub.py -e <endpoint> -r <rootCAFilePath> -w
# Customize client id and topic
python basicPubSub.py -e <endpoint> -r <rootCAFilePath> -c <certFilePath> -k <privateKeyFilePath> -id <clientId> -t <topic>
Source
******
Expand Down Expand Up @@ -541,6 +543,8 @@ Run the example like this:
.. code-block:: python
python basicPubSub_CognitoSTS.py -e <endpoint> -r <rootCAFilePath> -C <CognitoIdentityPoolID>
# Customize client id and topic
python basicPubsub_CognitoSTS.py -e <endpoint> -r <rootCAFilePath> -C <CognitoIdentityPoolID> -id <clientId> -t <topic>
Source
******
Expand Down Expand Up @@ -590,6 +594,7 @@ Then, start the basicShadowUpdater:
# MQTT over WebSocket
python basicShadowUpdater.py -e <endpoint> -r <rootCAFilePath> -w
After the basicShadowUpdater starts sending shadow update requests, you
should be able to see corresponding delta messages in the
basicShadowDeltaListener output.
Expand Down Expand Up @@ -621,6 +626,8 @@ Run the example like this:
python ThingShadowEcho.py -e <endpoint> -r <rootCAFilePath> -c <certFilePath> -k <privateKeyFilePath>
# MQTT over WebSocket
python ThingShadowEcho.py -e <endpoint> -r <rootCAFilePath> -w
# Customize client Id and thing name
python ThingShadowEcho.py -e <endpoint> -r <rootCAFilePath> -c <certFilePath> -k <privateKeyFilePath> -id <clientId> -n <thingName>
Now use the `AWS IoT console <https://console.aws.amazon.com/iot/>`__ or other MQTT
client to update the shadow desired state only. You should be able to see the reported state is updated to match
Expand Down
109 changes: 31 additions & 78 deletions samples/ThingShadowEcho/ThingShadowEcho.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import logging
import time
import json
import getopt
import argparse

class shadowCallbackContainer:
def __init__(self, deviceShadowInstance):
Expand All @@ -39,79 +39,32 @@ def customShadowCallback_Delta(self, payload, responseStatus, token):
self.deviceShadowInstance.shadowUpdate(newPayload, None, 5)
print("Sent.")

# Usage
usageInfo = """Usage:
Use certificate based mutual authentication:
python ThingShadowEcho.py -e <endpoint> -r <rootCAFilePath> -c <certFilePath> -k <privateKeyFilePath>
Use MQTT over WebSocket:
python ThingShadowEcho.py -e <endpoint> -r <rootCAFilePath> -w
Type "python ThingShadowEcho.py -h" for available options.
"""
# Help info
helpInfo = """-e, --endpoint
Your AWS IoT custom endpoint
-r, --rootCA
Root CA file path
-c, --cert
Certificate file path
-k, --key
Private key file path
-w, --websocket
Use MQTT over WebSocket
-h, --help
Help information
"""

# Read in command-line parameters
useWebsocket = False
host = ""
rootCAPath = ""
certificatePath = ""
privateKeyPath = ""
try:
opts, args = getopt.getopt(sys.argv[1:], "hwe:k:c:r:", ["help", "endpoint=", "key=","cert=","rootCA=", "websocket"])
if len(opts) == 0:
raise getopt.GetoptError("No input parameters!")
for opt, arg in opts:
if opt in ("-h", "--help"):
print(helpInfo)
exit(0)
if opt in ("-e", "--endpoint"):
host = arg
if opt in ("-r", "--rootCA"):
rootCAPath = arg
if opt in ("-c", "--cert"):
certificatePath = arg
if opt in ("-k", "--key"):
privateKeyPath = arg
if opt in ("-w", "--websocket"):
useWebsocket = True
except getopt.GetoptError:
print(usageInfo)
exit(1)
parser = argparse.ArgumentParser()
parser.add_argument("-e", "--endpoint", action="store", required=True, dest="host", help="Your AWS IoT custom endpoint")
parser.add_argument("-r", "--rootCA", action="store", required=True, dest="rootCAPath", help="Root CA file path")
parser.add_argument("-c", "--cert", action="store", dest="certificatePath", help="Certificate file path")
parser.add_argument("-k", "--key", action="store", dest="privateKeyPath", help="Private key file path")
parser.add_argument("-w", "--websocket", action="store_true", dest="useWebsocket", default=False,
help="Use MQTT over WebSocket")
parser.add_argument("-n", "--thingName", action="store", dest="thingName", default="Bot", help="Targeted thing name")
parser.add_argument("-id", "--clientId", action="store", dest="clientId", default="ThingShadowEcho", help="Targeted client id")

args = parser.parse_args()
host = args.host
rootCAPath = args.rootCAPath
certificatePath = args.certificatePath
privateKeyPath = args.privateKeyPath
useWebsocket = args.useWebsocket
thingName = args.thingName
clientId = args.clientId

if args.useWebsocket and args.certificatePath and args.privateKeyPath:
parser.error("X.509 cert authentication and WebSocket are mutual exclusive. Please pick one.")
exit(2)

# Missing configuration notification
missingConfiguration = False
if not host:
print("Missing '-e' or '--endpoint'")
missingConfiguration = True
if not rootCAPath:
print("Missing '-r' or '--rootCA'")
missingConfiguration = True
if not useWebsocket:
if not certificatePath:
print("Missing '-c' or '--cert'")
missingConfiguration = True
if not privateKeyPath:
print("Missing '-k' or '--key'")
missingConfiguration = True
if missingConfiguration:
if not args.useWebsocket and (not args.certificatePath or not args.privateKeyPath):
parser.error("Missing credentials for authentication.")
exit(2)

# Configure logging
Expand All @@ -125,11 +78,11 @@ def customShadowCallback_Delta(self, payload, responseStatus, token):
# Init AWSIoTMQTTShadowClient
myAWSIoTMQTTShadowClient = None
if useWebsocket:
myAWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient("ThingShadowEcho", useWebsocket=True)
myAWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient(clientId, useWebsocket=True)
myAWSIoTMQTTShadowClient.configureEndpoint(host, 443)
myAWSIoTMQTTShadowClient.configureCredentials(rootCAPath)
else:
myAWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient("ThingShadowEcho")
myAWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient(clientId)
myAWSIoTMQTTShadowClient.configureEndpoint(host, 8883)
myAWSIoTMQTTShadowClient.configureCredentials(rootCAPath, privateKeyPath, certificatePath)

Expand All @@ -142,12 +95,12 @@ def customShadowCallback_Delta(self, payload, responseStatus, token):
myAWSIoTMQTTShadowClient.connect()

# Create a deviceShadow with persistent subscription
Bot = myAWSIoTMQTTShadowClient.createShadowHandlerWithName("Bot", True)
shadowCallbackContainer_Bot = shadowCallbackContainer(Bot)
deviceShadowHandler = myAWSIoTMQTTShadowClient.createShadowHandlerWithName(thingName, True)
shadowCallbackContainer_Bot = shadowCallbackContainer(deviceShadowHandler)

# Listen on deltas
Bot.shadowRegisterDeltaCallback(shadowCallbackContainer_Bot.customShadowCallback_Delta)
deviceShadowHandler.shadowRegisterDeltaCallback(shadowCallbackContainer_Bot.customShadowCallback_Delta)

# Loop forever
while True:
pass
time.sleep(1)
Loading

0 comments on commit f1d0357

Please sign in to comment.