Skip to content

Commit 3f13a41

Browse files
authored
Mqtt5 Service Client (#501)
* service client update * update service client for mqtt5 * update awscrt with adapter release * minor changes * remove future to avoid block on exit * run mqtt5 shadow in codebuild pipeline * remove unused var * test with pythondevmode off * test with python version * set a reference to mqtt5_client to avoid python garbage collection * update awscrt to latest
1 parent 241d496 commit 3f13a41

14 files changed

+1987
-4
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,9 @@ jobs:
279279
- name: run Shadow sample
280280
run: |
281281
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_shadow_cfg.json
282+
- name: run MQTT5 Shadow sample
283+
run: |
284+
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_mqtt5_shadow_cfg.json
282285
- name: configure AWS credentials (Jobs)
283286
uses: aws-actions/configure-aws-credentials@v1
284287
with:
@@ -287,6 +290,9 @@ jobs:
287290
- name: run Jobs sample
288291
run: |
289292
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_jobs_cfg.json
293+
- name: run MQTT5 Jobs sample
294+
run: |
295+
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_mqtt5_jobs_cfg.json
290296
- name: configure AWS credentials (Fleet provisioning)
291297
uses: aws-actions/configure-aws-credentials@v1
292298
with:
@@ -298,6 +304,12 @@ jobs:
298304
Sample_UUID=$(python3 -c "import uuid; print (uuid.uuid4())")
299305
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_fleet_provisioning_cfg.json --input_uuid ${Sample_UUID}
300306
python3 ${{ env.CI_UTILS_FOLDER }}/delete_iot_thing_ci.py --thing_name "Fleet_Thing_${Sample_UUID}" --region "us-east-1"
307+
- name: run MQTT5 Fleet Provisioning sample
308+
run: |
309+
echo "Generating UUID for IoT thing"
310+
Sample_UUID=$(python3 -c "import uuid; print (uuid.uuid4())")
311+
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_mqtt5_fleet_provisioning_cfg.json --input_uuid ${Sample_UUID}
312+
python3 ${{ env.CI_UTILS_FOLDER }}/delete_iot_thing_ci.py --thing_name "Fleet_Thing_${Sample_UUID}" --region "us-east-1"
301313
- name: configure AWS credentials (Greengrass)
302314
uses: aws-actions/configure-aws-credentials@v1
303315
with:
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"language": "Python",
3+
"sample_file": "./aws-iot-device-sdk-python-v2/samples/fleetprovisioning_mqtt5.py",
4+
"sample_region": "us-east-1",
5+
"sample_main_class": "",
6+
"arguments": [
7+
{
8+
"name": "--endpoint",
9+
"secret": "ci/endpoint"
10+
},
11+
{
12+
"name": "--cert",
13+
"secret": "ci/FleetProvisioning/cert",
14+
"filename": "tmp_certificate.pem"
15+
},
16+
{
17+
"name": "--key",
18+
"secret": "ci/FleetProvisioning/key",
19+
"filename": "tmp_key.pem"
20+
},
21+
{
22+
"name": "--template_name",
23+
"data": "CI_FleetProvisioning_Template"
24+
},
25+
{
26+
"name": "--template_parameters",
27+
"data": "{\"SerialNumber\":\"$INPUT_UUID\"}"
28+
}
29+
]
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"language": "Python",
3+
"sample_file": "./aws-iot-device-sdk-python-v2/samples/jobs_mqtt5.py",
4+
"sample_region": "us-east-1",
5+
"sample_main_class": "",
6+
"arguments": [
7+
{
8+
"name": "--endpoint",
9+
"secret": "ci/endpoint"
10+
},
11+
{
12+
"name": "--cert",
13+
"secret": "ci/Jobs/cert",
14+
"filename": "tmp_certificate.pem"
15+
},
16+
{
17+
"name": "--key",
18+
"secret": "ci/Jobs/key",
19+
"filename": "tmp_key.pem"
20+
},
21+
{
22+
"name": "--thing_name",
23+
"data": "CI_Jobs_Thing"
24+
}
25+
]
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"language": "Python",
3+
"sample_file": "./aws-iot-device-sdk-python-v2/samples/shadow_mqtt5.py",
4+
"sample_region": "us-east-1",
5+
"sample_main_class": "",
6+
"arguments": [
7+
{
8+
"name": "--endpoint",
9+
"secret": "ci/endpoint"
10+
},
11+
{
12+
"name": "--cert",
13+
"secret": "ci/Shadow/cert",
14+
"filename": "tmp_certificate.pem"
15+
},
16+
{
17+
"name": "--key",
18+
"secret": "ci/Shadow/key",
19+
"filename": "tmp_key.pem"
20+
},
21+
{
22+
"name": "--thing_name",
23+
"data": "CI_Shadow_Thing"
24+
},
25+
{
26+
"name": "--is_ci",
27+
"data": "true"
28+
}
29+
]
30+
}

awsiot/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
'mqtt5_client_builder',
1212
]
1313

14-
from awscrt import mqtt
14+
from awscrt import mqtt, mqtt5
1515
from concurrent.futures import Future
1616
import json
1717
from typing import Any, Callable, Dict, Optional, Tuple, TypeVar
@@ -32,8 +32,14 @@ class MqttServiceClient:
3232
mqtt_connection: MQTT connection to use
3333
"""
3434

35-
def __init__(self, mqtt_connection: mqtt.Connection):
36-
self._mqtt_connection = mqtt_connection # type: mqtt.Connection
35+
def __init__(self, mqtt_connection: mqtt.Connection or mqtt5.Client):
36+
if isinstance(mqtt_connection, mqtt.Connection):
37+
self._mqtt_connection = mqtt_connection # type: mqtt.Connection
38+
elif isinstance(mqtt_connection, mqtt5.Client):
39+
self._mqtt_connection = mqtt_connection.new_connection()
40+
self._mqtt5_client = mqtt_connection
41+
else:
42+
assert("The service client could only take mqtt.Connection and mqtt5.Client as argument")
3743

3844
@property
3945
def mqtt_connection(self) -> mqtt.Connection:

codebuild/samples/shadow-linux.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "ci/endpoint" --query
1111

1212
echo "Shadow test"
1313
python3 shadow.py --endpoint $ENDPOINT --key /tmp/privatekey.pem --cert /tmp/certificate.pem --thing_name CI_CodeBuild_Thing --is_ci true
14+
python3 shadow_mqtt5.py --endpoint $ENDPOINT --key /tmp/privatekey.pem --cert /tmp/certificate.pem --thing_name CI_CodeBuild_Thing --is_ci true
1415

1516
popd

samples/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@
1414
* [Cognito Connect](./cognito_connect.md)
1515
* [X509 Connect](./x509_connect.md)
1616
* [Shadow](./shadow.md)
17+
* [MQTT5 Shadow](./shadow_mqtt5.md)
1718
* [Jobs](./jobs.md)
19+
* [MQTT5 Jobs](./jobs_mqtt5.md)
1820
* [Fleet Provisioning](./fleetprovisioning.md)
21+
* [MQTT5 Fleet Provisioning](./fleetprovisioning_mqtt5.md)
1922
* [Greengrass Discovery](./basic_discovery.md)
2023
* [Greengrass IPC](./ipc_greengrass.md)
2124

0 commit comments

Comments
 (0)