Skip to content

Instantly share code, notes, and snippets.

@whelmed
Created July 13, 2019 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whelmed/5f8e8f793ed03da268defa4cbc80afd9 to your computer and use it in GitHub Desktop.
Save whelmed/5f8e8f793ed03da268defa4cbc80afd9 to your computer and use it in GitHub Desktop.
Cloud IoT Core Test
#!/bin/bash
set -e
REGISTRY_ID=YOUR_ID_HERE
REGION=us-YOUR_REGION_HERE
PROJECT_ID=YOUR_PROJECT_HERE
DEVICE_ID=YOUR_DEVICE_ID_HERE
echo "Creating RSA Key for device authentication"
openssl genpkey -algorithm RSA -out rsa_private.pem -pkeyopt rsa_keygen_bits:2048
openssl rsa -in rsa_private.pem -pubout -out rsa_public.pem
echo "Fetching Google root certificate"
wget https://pki.google.com/roots.pem
echo "Fetching GCP demo applications from https://github.com/GoogleCloudPlatform/python-docs-samples.git"
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
echo "Creating and activating Python 2.7 virtual environment"
virtualenv env
source env/bin/activate
pip install -r python-docs-samples/iot/api-client/mqtt_example/requirements.txt
python python-docs-samples/iot/api-client/mqtt_example/cloudiot_mqtt_example.py \
--registry_id=$REGISTRY_ID \
--cloud_region=$REGION \
--project_id=$PROJECT_ID \
--device_id=$DEVICE_ID \
--algorithm=RS256 \
--private_key_file=rsa_private.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment