Skip to content

Commit f1d0357

Browse files
committed
Release of version 1.1.2
1 parent 0505f65 commit f1d0357

File tree

12 files changed

+205
-416
lines changed

12 files changed

+205
-416
lines changed

AWSIoTPythonSDK/MQTTLib.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def configureLastWill(self, topic, payload, QoS):
9494
**Syntax**
9595
9696
.. code:: python
97+
9798
myAWSIoTMQTTClient.configureLastWill("last/Will/Topic", "lastWillPayload", 0)
9899
99100
**Parameters**
@@ -120,7 +121,8 @@ def clearLastWill(self):
120121
121122
**Syntax**
122123
123-
..code:: python
124+
.. code:: python
125+
124126
myAWSIoTMQTTClient.clearLastWill()
125127
126128
**Parameter**
@@ -438,8 +440,8 @@ def publish(self, topic, payload, QoS):
438440
439441
# Publish a QoS0 message "myPayload" to topic "myToppic"
440442
myAWSIoTMQTTClient.publish("myTopic", "myPayload", 0)
441-
# Publish a QoS1 message "myPayload2" to topic "myTopic/sub"
442-
myAWSIoTMQTTClient.publish("myTopic/sub", "myPayload", 1)
443+
# Publish a QoS1 message "myPayloadWithQos1" to topic "myTopic/sub"
444+
myAWSIoTMQTTClient.publish("myTopic/sub", "myPayloadWithQos1", 1)
443445
444446
**Parameters**
445447
@@ -582,6 +584,7 @@ def configureLastWill(self, topic, payload, QoS):
582584
**Syntax**
583585
584586
.. code:: python
587+
585588
myAWSIoTMQTTClient.configureLastWill("last/Will/Topic", "lastWillPayload", 0)
586589
587590
**Parameters**
@@ -608,7 +611,8 @@ def clearLastWill(self):
608611
609612
**Syntax**
610613
611-
..code:: python
614+
.. code:: python
615+
612616
myAWSIoTShadowMQTTClient.clearLastWill()
613617
614618
**Parameter**
@@ -784,7 +788,7 @@ def connect(self, keepAliveIntervalSecond=30):
784788
"""
785789
**Description**
786790
787-
Connect to AWS IoT, with user-specific keeoalive interval configuration.
791+
Connect to AWS IoT, with user-specific keepalive interval configuration.
788792
789793
**Syntax**
790794

AWSIoTPythonSDK/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import os
22
import sys
33

4-
__version__ = "1.1.1"
4+
__version__ = "1.1.2"
55

66

AWSIoTPythonSDK/core/protocol/paho/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,13 @@ def reconnect(self):
804804
ssl.match_hostname(self._ssl.getpeercert(), self._host)
805805

806806
self._sock = sock
807-
self._sock.setblocking(0)
807+
808+
if self._ssl and not self._useSecuredWebsocket:
809+
self._ssl.setblocking(0) # For X.509 cert mutual auth.
810+
elif not self._ssl:
811+
self._sock.setblocking(0) # For plain socket
812+
else:
813+
pass # For MQTT over WebSocket
808814

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

AWSIoTPythonSDK/core/shadow/deviceShadow.py

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

16-
import sys
1716
import json
18-
import string
19-
import random
2017
import logging
18+
import uuid
2119
from threading import Timer, Lock, Thread
2220

2321

2422
class _shadowRequestToken:
2523

24+
URN_PREFIX_LENGTH = 9
25+
2626
def __init__(self, srcShadowName, srcClientID):
2727
self._shadowName = srcShadowName
2828
self._clientID = srcClientID
29-
self._sequenceNumber = 0
30-
self._lowercase = string.ascii_lowercase
3129

3230
def getNextToken(self):
33-
ret = self._clientID + "_" + self._shadowName + "_" + str(self._sequenceNumber) + "_" + self._randomString(5)
34-
self._sequenceNumber += 1
35-
return ret
36-
37-
def _randomString(self, lengthOfString):
38-
return "".join(random.choice(self._lowercase) for i in range(lengthOfString))
31+
return uuid.uuid4().urn[self.URN_PREFIX_LENGTH:] # We only need the uuid digits, not the urn prefix
3932

4033

4134
class _basicJSONParser:

CHANGELOG.rst

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

5+
1.1.2
6+
=====
7+
* bugfix:Issue:`#28 <https://github.com/aws/aws-iot-device-sdk-python/issues/28>`__
8+
* bugfix:Issue:`#29 <https://github.com/aws/aws-iot-device-sdk-python/issues/29>`__
9+
* bugfix:Pull request:`#32 <https://github.com/aws/aws-iot-device-sdk-python/pull/32>`__
10+
* improvement:Pull request:`#38 <https://github.com/aws/aws-iot-device-sdk-python/pull/38>`__
11+
* bugfix:Pull request:`#45 <https://github.com/aws/aws-iot-device-sdk-python/pull/45>`__
12+
* improvement:Pull request:`#46 <https://github.com/aws/aws-iot-device-sdk-python/pull/46>`__
13+
514
1.1.1
615
=====
716
* bugfix:Issue:`#23 <https://github.com/aws/aws-iot-device-sdk-python/issues/23>`__

NOTICE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AWS IoT Python SDK for Internet of Things Service
2-
Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33

44
This product includes software developed by
55
Amazon Inc (http://www.amazon.com/).

README.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,8 @@ Run the example like this:
510510
python basicPubSub.py -e <endpoint> -r <rootCAFilePath> -c <certFilePath> -k <privateKeyFilePath>
511511
# MQTT over WebSocket
512512
python basicPubSub.py -e <endpoint> -r <rootCAFilePath> -w
513+
# Customize client id and topic
514+
python basicPubSub.py -e <endpoint> -r <rootCAFilePath> -c <certFilePath> -k <privateKeyFilePath> -id <clientId> -t <topic>
513515
514516
Source
515517
******
@@ -541,6 +543,8 @@ Run the example like this:
541543
.. code-block:: python
542544
543545
python basicPubSub_CognitoSTS.py -e <endpoint> -r <rootCAFilePath> -C <CognitoIdentityPoolID>
546+
# Customize client id and topic
547+
python basicPubsub_CognitoSTS.py -e <endpoint> -r <rootCAFilePath> -C <CognitoIdentityPoolID> -id <clientId> -t <topic>
544548
545549
Source
546550
******
@@ -590,6 +594,7 @@ Then, start the basicShadowUpdater:
590594
# MQTT over WebSocket
591595
python basicShadowUpdater.py -e <endpoint> -r <rootCAFilePath> -w
592596
597+
593598
After the basicShadowUpdater starts sending shadow update requests, you
594599
should be able to see corresponding delta messages in the
595600
basicShadowDeltaListener output.
@@ -621,6 +626,8 @@ Run the example like this:
621626
python ThingShadowEcho.py -e <endpoint> -r <rootCAFilePath> -c <certFilePath> -k <privateKeyFilePath>
622627
# MQTT over WebSocket
623628
python ThingShadowEcho.py -e <endpoint> -r <rootCAFilePath> -w
629+
# Customize client Id and thing name
630+
python ThingShadowEcho.py -e <endpoint> -r <rootCAFilePath> -c <certFilePath> -k <privateKeyFilePath> -id <clientId> -n <thingName>
624631
625632
Now use the `AWS IoT console <https://console.aws.amazon.com/iot/>`__ or other MQTT
626633
client to update the shadow desired state only. You should be able to see the reported state is updated to match

samples/ThingShadowEcho/ThingShadowEcho.py

Lines changed: 31 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import logging
2121
import time
2222
import json
23-
import getopt
23+
import argparse
2424

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

42-
# Usage
43-
usageInfo = """Usage:
44-
45-
Use certificate based mutual authentication:
46-
python ThingShadowEcho.py -e <endpoint> -r <rootCAFilePath> -c <certFilePath> -k <privateKeyFilePath>
47-
48-
Use MQTT over WebSocket:
49-
python ThingShadowEcho.py -e <endpoint> -r <rootCAFilePath> -w
50-
Type "python ThingShadowEcho.py -h" for available options.
51-
52-
53-
"""
54-
# Help info
55-
helpInfo = """-e, --endpoint
56-
Your AWS IoT custom endpoint
57-
-r, --rootCA
58-
Root CA file path
59-
-c, --cert
60-
Certificate file path
61-
-k, --key
62-
Private key file path
63-
-w, --websocket
64-
Use MQTT over WebSocket
65-
-h, --help
66-
Help information
67-
68-
69-
"""
70-
7142
# Read in command-line parameters
72-
useWebsocket = False
73-
host = ""
74-
rootCAPath = ""
75-
certificatePath = ""
76-
privateKeyPath = ""
77-
try:
78-
opts, args = getopt.getopt(sys.argv[1:], "hwe:k:c:r:", ["help", "endpoint=", "key=","cert=","rootCA=", "websocket"])
79-
if len(opts) == 0:
80-
raise getopt.GetoptError("No input parameters!")
81-
for opt, arg in opts:
82-
if opt in ("-h", "--help"):
83-
print(helpInfo)
84-
exit(0)
85-
if opt in ("-e", "--endpoint"):
86-
host = arg
87-
if opt in ("-r", "--rootCA"):
88-
rootCAPath = arg
89-
if opt in ("-c", "--cert"):
90-
certificatePath = arg
91-
if opt in ("-k", "--key"):
92-
privateKeyPath = arg
93-
if opt in ("-w", "--websocket"):
94-
useWebsocket = True
95-
except getopt.GetoptError:
96-
print(usageInfo)
97-
exit(1)
43+
parser = argparse.ArgumentParser()
44+
parser.add_argument("-e", "--endpoint", action="store", required=True, dest="host", help="Your AWS IoT custom endpoint")
45+
parser.add_argument("-r", "--rootCA", action="store", required=True, dest="rootCAPath", help="Root CA file path")
46+
parser.add_argument("-c", "--cert", action="store", dest="certificatePath", help="Certificate file path")
47+
parser.add_argument("-k", "--key", action="store", dest="privateKeyPath", help="Private key file path")
48+
parser.add_argument("-w", "--websocket", action="store_true", dest="useWebsocket", default=False,
49+
help="Use MQTT over WebSocket")
50+
parser.add_argument("-n", "--thingName", action="store", dest="thingName", default="Bot", help="Targeted thing name")
51+
parser.add_argument("-id", "--clientId", action="store", dest="clientId", default="ThingShadowEcho", help="Targeted client id")
52+
53+
args = parser.parse_args()
54+
host = args.host
55+
rootCAPath = args.rootCAPath
56+
certificatePath = args.certificatePath
57+
privateKeyPath = args.privateKeyPath
58+
useWebsocket = args.useWebsocket
59+
thingName = args.thingName
60+
clientId = args.clientId
61+
62+
if args.useWebsocket and args.certificatePath and args.privateKeyPath:
63+
parser.error("X.509 cert authentication and WebSocket are mutual exclusive. Please pick one.")
64+
exit(2)
9865

99-
# Missing configuration notification
100-
missingConfiguration = False
101-
if not host:
102-
print("Missing '-e' or '--endpoint'")
103-
missingConfiguration = True
104-
if not rootCAPath:
105-
print("Missing '-r' or '--rootCA'")
106-
missingConfiguration = True
107-
if not useWebsocket:
108-
if not certificatePath:
109-
print("Missing '-c' or '--cert'")
110-
missingConfiguration = True
111-
if not privateKeyPath:
112-
print("Missing '-k' or '--key'")
113-
missingConfiguration = True
114-
if missingConfiguration:
66+
if not args.useWebsocket and (not args.certificatePath or not args.privateKeyPath):
67+
parser.error("Missing credentials for authentication.")
11568
exit(2)
11669

11770
# Configure logging
@@ -125,11 +78,11 @@ def customShadowCallback_Delta(self, payload, responseStatus, token):
12578
# Init AWSIoTMQTTShadowClient
12679
myAWSIoTMQTTShadowClient = None
12780
if useWebsocket:
128-
myAWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient("ThingShadowEcho", useWebsocket=True)
81+
myAWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient(clientId, useWebsocket=True)
12982
myAWSIoTMQTTShadowClient.configureEndpoint(host, 443)
13083
myAWSIoTMQTTShadowClient.configureCredentials(rootCAPath)
13184
else:
132-
myAWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient("ThingShadowEcho")
85+
myAWSIoTMQTTShadowClient = AWSIoTMQTTShadowClient(clientId)
13386
myAWSIoTMQTTShadowClient.configureEndpoint(host, 8883)
13487
myAWSIoTMQTTShadowClient.configureCredentials(rootCAPath, privateKeyPath, certificatePath)
13588

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

14497
# Create a deviceShadow with persistent subscription
145-
Bot = myAWSIoTMQTTShadowClient.createShadowHandlerWithName("Bot", True)
146-
shadowCallbackContainer_Bot = shadowCallbackContainer(Bot)
98+
deviceShadowHandler = myAWSIoTMQTTShadowClient.createShadowHandlerWithName(thingName, True)
99+
shadowCallbackContainer_Bot = shadowCallbackContainer(deviceShadowHandler)
147100

148101
# Listen on deltas
149-
Bot.shadowRegisterDeltaCallback(shadowCallbackContainer_Bot.customShadowCallback_Delta)
102+
deviceShadowHandler.shadowRegisterDeltaCallback(shadowCallbackContainer_Bot.customShadowCallback_Delta)
150103

151104
# Loop forever
152105
while True:
153-
pass
106+
time.sleep(1)

0 commit comments

Comments
 (0)