Skip to content

Mqtt5 Service Client #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ jobs:
- name: run Shadow sample
run: |
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_shadow_cfg.json
- name: run MQTT5 Shadow sample
run: |
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_mqtt5_shadow_cfg.json
- name: configure AWS credentials (Jobs)
uses: aws-actions/configure-aws-credentials@v1
with:
Expand All @@ -287,6 +290,9 @@ jobs:
- name: run Jobs sample
run: |
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_jobs_cfg.json
- name: run MQTT5 Jobs sample
run: |
python3 ${{ env.CI_UTILS_FOLDER }}/run_sample_ci.py --file ${{ env.CI_SAMPLES_CFG_FOLDER }}/ci_run_mqtt5_jobs_cfg.json
- name: configure AWS credentials (Fleet provisioning)
uses: aws-actions/configure-aws-credentials@v1
with:
Expand All @@ -298,6 +304,12 @@ jobs:
Sample_UUID=$(python3 -c "import uuid; print (uuid.uuid4())")
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}
python3 ${{ env.CI_UTILS_FOLDER }}/delete_iot_thing_ci.py --thing_name "Fleet_Thing_${Sample_UUID}" --region "us-east-1"
- name: run MQTT5 Fleet Provisioning sample
run: |
echo "Generating UUID for IoT thing"
Sample_UUID=$(python3 -c "import uuid; print (uuid.uuid4())")
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}
python3 ${{ env.CI_UTILS_FOLDER }}/delete_iot_thing_ci.py --thing_name "Fleet_Thing_${Sample_UUID}" --region "us-east-1"
- name: configure AWS credentials (Greengrass)
uses: aws-actions/configure-aws-credentials@v1
with:
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/ci_run_mqtt5_fleet_provisioning_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"language": "Python",
"sample_file": "./aws-iot-device-sdk-python-v2/samples/fleetprovisioning_mqtt5.py",
"sample_region": "us-east-1",
"sample_main_class": "",
"arguments": [
{
"name": "--endpoint",
"secret": "ci/endpoint"
},
{
"name": "--cert",
"secret": "ci/FleetProvisioning/cert",
"filename": "tmp_certificate.pem"
},
{
"name": "--key",
"secret": "ci/FleetProvisioning/key",
"filename": "tmp_key.pem"
},
{
"name": "--template_name",
"data": "CI_FleetProvisioning_Template"
},
{
"name": "--template_parameters",
"data": "{\"SerialNumber\":\"$INPUT_UUID\"}"
}
]
}
26 changes: 26 additions & 0 deletions .github/workflows/ci_run_mqtt5_jobs_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"language": "Python",
"sample_file": "./aws-iot-device-sdk-python-v2/samples/jobs_mqtt5.py",
"sample_region": "us-east-1",
"sample_main_class": "",
"arguments": [
{
"name": "--endpoint",
"secret": "ci/endpoint"
},
{
"name": "--cert",
"secret": "ci/Jobs/cert",
"filename": "tmp_certificate.pem"
},
{
"name": "--key",
"secret": "ci/Jobs/key",
"filename": "tmp_key.pem"
},
{
"name": "--thing_name",
"data": "CI_Jobs_Thing"
}
]
}
30 changes: 30 additions & 0 deletions .github/workflows/ci_run_mqtt5_shadow_cfg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"language": "Python",
"sample_file": "./aws-iot-device-sdk-python-v2/samples/shadow_mqtt5.py",
"sample_region": "us-east-1",
"sample_main_class": "",
"arguments": [
{
"name": "--endpoint",
"secret": "ci/endpoint"
},
{
"name": "--cert",
"secret": "ci/Shadow/cert",
"filename": "tmp_certificate.pem"
},
{
"name": "--key",
"secret": "ci/Shadow/key",
"filename": "tmp_key.pem"
},
{
"name": "--thing_name",
"data": "CI_Shadow_Thing"
},
{
"name": "--is_ci",
"data": "true"
}
]
}
12 changes: 9 additions & 3 deletions awsiot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
'mqtt5_client_builder',
]

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

def __init__(self, mqtt_connection: mqtt.Connection):
self._mqtt_connection = mqtt_connection # type: mqtt.Connection
def __init__(self, mqtt_connection: mqtt.Connection or mqtt5.Client):
if isinstance(mqtt_connection, mqtt.Connection):
self._mqtt_connection = mqtt_connection # type: mqtt.Connection
elif isinstance(mqtt_connection, mqtt5.Client):
self._mqtt_connection = mqtt_connection.new_connection()
self._mqtt5_client = mqtt_connection
else:
assert("The service client could only take mqtt.Connection and mqtt5.Client as argument")

@property
def mqtt_connection(self) -> mqtt.Connection:
Expand Down
1 change: 1 addition & 0 deletions codebuild/samples/shadow-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "ci/endpoint" --query

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

popd
3 changes: 3 additions & 0 deletions samples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
* [Cognito Connect](./cognito_connect.md)
* [X509 Connect](./x509_connect.md)
* [Shadow](./shadow.md)
* [MQTT5 Shadow](./shadow_mqtt5.md)
* [Jobs](./jobs.md)
* [MQTT5 Jobs](./jobs_mqtt5.md)
* [Fleet Provisioning](./fleetprovisioning.md)
* [MQTT5 Fleet Provisioning](./fleetprovisioning_mqtt5.md)
* [Greengrass Discovery](./basic_discovery.md)
* [Greengrass IPC](./ipc_greengrass.md)

Expand Down
Loading