Skip to content

Commit

Permalink
add python Test HTTPS Script
Browse files Browse the repository at this point in the history
  • Loading branch information
knupGB committed Sep 10, 2024
1 parent 8d4c820 commit 412d472
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions PythonTestHTTPS_MQTT/main.py
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)

0 comments on commit 412d472

Please sign in to comment.