-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Splits the PubSub sample down into smaller connect samples that show how just how to make a connection. * Simplified command line parsing * Fixed tests not working correctly after simplified command line parsing * Added action support to command line parser * Added additional command groups * Split PubSub sample into smaller connect samples * Fixed codebuild tests to work with sample split * Adjusted code based on code review: * Added PubSub sample back to codebuild tests * Simplified connection samples by using utility functions in command_line_utils * Removed PKCS11 PubSub sample (since it's replaced by PKCS11 connect sample) * Added PKCS11 connection builder function to command_line_utils * Converted Windows Cert PubSub to Windows Cert Connect * Adjusted README to use consistent command format * Fixed diff being included in fleet provision sample
- Loading branch information
1 parent
d5480f1
commit e56d3e8
Showing
17 changed files
with
661 additions
and
539 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
env | ||
|
||
pushd $CODEBUILD_SRC_DIR/samples/ | ||
|
||
ENDPOINT=$(aws secretsmanager get-secret-value --secret-id "unit-test/endpoint" --query "SecretString" | cut -f2 -d":" | sed -e 's/[\\\"\}]//g') | ||
|
||
echo "Mqtt Direct test" | ||
python3 basic_connect.py --endpoint $ENDPOINT --key /tmp/privatekey.pem --cert /tmp/certificate.pem | ||
|
||
echo "Websocket test" | ||
python3 websocket_connect.py --endpoint $ENDPOINT --signing_region us-east-1 | ||
|
||
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# SPDX-License-Identifier: Apache-2.0. | ||
|
||
from uuid import uuid4 | ||
|
||
# This sample shows how to create a MQTT connection using a certificate file and key file. | ||
# This sample is intended to be used as a reference for making MQTT connections. | ||
|
||
# Parse arguments | ||
import command_line_utils | ||
cmdUtils = command_line_utils.CommandLineUtils("Basic Connect - Make a MQTT connection.") | ||
cmdUtils.add_common_mqtt_commands() | ||
cmdUtils.add_common_proxy_commands() | ||
cmdUtils.add_common_logging_commands() | ||
cmdUtils.register_command("key", "<path>", "Path to your key in PEM format.", True, str) | ||
cmdUtils.register_command("cert", "<path>", "Path to your client certificate in PEM format.", True, str) | ||
cmdUtils.register_command("port", "<int>", | ||
"Connection port for direct connection. " + | ||
"AWS IoT supports 433 and 8883 (optional, default=8883).", | ||
False, int) | ||
cmdUtils.register_command("client_id", "<str>", | ||
"Client ID to use for MQTT connection (optional, default='test-*').", | ||
default="test-" + str(uuid4())) | ||
# Needs to be called so the command utils parse the commands | ||
cmdUtils.get_args() | ||
|
||
# Callback when connection is accidentally lost. | ||
def on_connection_interrupted(connection, error, **kwargs): | ||
print("Connection interrupted. error: {}".format(error)) | ||
|
||
# Callback when an interrupted connection is re-established. | ||
def on_connection_resumed(connection, return_code, session_present, **kwargs): | ||
print("Connection resumed. return_code: {} session_present: {}".format(return_code, session_present)) | ||
|
||
|
||
if __name__ == '__main__': | ||
# Create a connection using a certificate and key. | ||
# Note: The data for the connection is gotten from cmdUtils. | ||
# (see build_direct_mqtt_connection for implementation) | ||
mqtt_connection = cmdUtils.build_direct_mqtt_connection(on_connection_interrupted, on_connection_resumed) | ||
|
||
print("Connecting to {} with client ID '{}'...".format( | ||
cmdUtils.get_command(cmdUtils.m_cmd_endpoint), cmdUtils.get_command("client_id"))) | ||
|
||
connect_future = mqtt_connection.connect() | ||
|
||
# Future.result() waits until a result is available | ||
connect_future.result() | ||
print("Connected!") | ||
|
||
# Disconnect | ||
print("Disconnecting...") | ||
disconnect_future = mqtt_connection.disconnect() | ||
disconnect_future.result() | ||
print("Disconnected!") |
Oops, something went wrong.