-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
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,38 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
# | ||
# | ||
# https://docs.aws.amazon.com/iot/latest/developerguide/http.html | ||
# | ||
|
||
import requests | ||
import argparse | ||
|
||
# define command-line parameters | ||
parser = argparse.ArgumentParser(description="Send messages through an HTTPS connection.") | ||
parser.add_argument('--endpoint', required=True, help="Your AWS IoT data custom endpoint, not including a port. " + | ||
"Ex: \"abcdEXAMPLExyz-ats.iot.us-east-1.amazonaws.com\"") | ||
parser.add_argument('--cert', required=True, help="File path to your client certificate, in PEM format.") | ||
parser.add_argument('--key', required=True, help="File path to your private key, in PEM format.") | ||
parser.add_argument('--topic', required=True, default="test/topic", help="Topic to publish messages to.") | ||
parser.add_argument('--message', default="Hello World!", help="Message to publish. " + | ||
"Specify empty string to publish nothing.") | ||
|
||
# parse and load command-line parameter values | ||
args = parser.parse_args() | ||
|
||
# create and format values for HTTPS request | ||
publish_url = 'https://' + args.endpoint + ':8443/topics/' + args.topic + '?qos=1' | ||
publish_msg = args.message.encode('utf-8') | ||
|
||
# make request | ||
publish = requests.request('POST', | ||
publish_url, | ||
data=publish_msg, | ||
cert=[args.cert, args.key]) | ||
|
||
# print results | ||
print("Response status: ", str(publish.status_code)) | ||
if publish.status_code == 200: | ||
print("Response body:", publish.text) |