Skip to content

Commit 5f4f2db

Browse files
authored
sample instructions for mqtt5-pubsub (#15)
sample instructions for mqtt5-pubsub
1 parent 338a20e commit 5f4f2db

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

samples/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Sample apps for the AWS IoT Device SDK v2 for Python
22

3+
* [MQTT5 PubSub](#mqtt5-pubsub)
34
* [PubSub](#pubsub)
45
* [Basic Connect](#basic-connect)
56
* [Websocket Connect](#websocket-connect)
@@ -22,6 +23,65 @@ Then change into the samples directory to run the Python commands to execute the
2223
python3 pubsub.py --help
2324
```
2425

26+
## MQTT5 PubSub
27+
This sample uses the
28+
[Message Broker](https://docs.aws.amazon.com/iot/latest/developerguide/iot-message-broker.html)
29+
for AWS IoT to send and receive messages
30+
through an MQTT5 connection. On startup, the device connects to the server,
31+
subscribes to a topic, and begins publishing messages to that topic.
32+
The device should receive those same messages back from the message broker,
33+
since it is subscribed to that same topic.
34+
Status updates are continually printed to the console.
35+
36+
Source: `samples/mqtt5_pubsub.py`
37+
38+
Your Thing's [Policy](https://docs.aws.amazon.com/iot/latest/developerguide/iot-policies.html) must provide privileges for this sample to connect, subscribe, publish, and receive. Make sure your policy allows a client ID of `test-*` to connect or use `--client_id <client ID here>` to send the client ID your policy supports.
39+
40+
<details>
41+
<summary>(see sample policy)</summary>
42+
<pre>
43+
{
44+
"Version": "2012-10-17",
45+
"Statement": [
46+
{
47+
"Effect": "Allow",
48+
"Action": [
49+
"iot:Publish",
50+
"iot:Receive"
51+
],
52+
"Resource": [
53+
"arn:aws:iot:<b>region</b>:<b>account</b>:topic/test/topic"
54+
]
55+
},
56+
{
57+
"Effect": "Allow",
58+
"Action": [
59+
"iot:Subscribe"
60+
],
61+
"Resource": [
62+
"arn:aws:iot:<b>region</b>:<b>account</b>:topicfilter/test/topic"
63+
]
64+
},
65+
{
66+
"Effect": "Allow",
67+
"Action": [
68+
"iot:Connect"
69+
],
70+
"Resource": [
71+
"arn:aws:iot:<b>region</b>:<b>account</b>:client/test-*"
72+
]
73+
}
74+
]
75+
}
76+
</pre>
77+
</details>
78+
79+
Run the sample like this:
80+
``` sh
81+
# For Windows: replace 'python3' with 'python'
82+
python3 mqtt5_pubsub.py --endpoint <endpoint> --ca_file <file> --cert <file> --key <file>
83+
```
84+
2585
## PubSub
2686

2787
This sample uses the

0 commit comments

Comments
 (0)