This directory contains samples for Google Cloud IoT Core. Google Cloud IoT Core allows developers to easily integrate Publish and Subscribe functionality with devices and programmatically authorize devices.
Before you run the sample, you must retrieve the Google root certificate. For example, wget https://pki.goog/roots.pem
or curl https://pki.goog/roots.pem > roots.pem
.
This sample requires you to have authentication setup. Refer to the Authentication Getting Started Guide for instructions on setting up credentials for applications.
Clone python-docs-samples and change directory to the sample directory you want to use.
$ git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
Install pip and virtualenv if you do not already have them. You may want to refer to the Python Development Environment Setup Guide for Google Cloud Platform for instructions.
Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.
$ virtualenv env $ source env/bin/activate
Install the dependencies needed to run the samples.
$ pip install -r requirements.txt
To run this sample:
$ python gcs_example_mqtt_device.py
usage: gcs_example_mqtt_device.py [-h] --project_id PROJECT_ID --registry_id
REGISTRY_ID --device_id DEVICE_ID
--private_key_file PRIVATE_KEY_FILE
--algorithm {RS256,ES256}
[--cloud_region CLOUD_REGION]
[--ca_certs CA_CERTS]
[--num_messages NUM_MESSAGES]
[--mqtt_bridge_hostname MQTT_BRIDGE_HOSTNAME]
[--mqtt_bridge_port MQTT_BRIDGE_PORT]
Example Google Cloud IoT MQTT device connection code.
optional arguments:
-h, --help show this help message and exit
--project_id PROJECT_ID
GCP cloud project name.
--registry_id REGISTRY_ID
Cloud IoT registry id
--device_id DEVICE_ID
Cloud IoT device id
--private_key_file PRIVATE_KEY_FILE
Path to private key file.
--algorithm {RS256,ES256}
Which encryption algorithm to use to generate the JWT.
--cloud_region CLOUD_REGION
GCP cloud region
--ca_certs CA_CERTS CA root certificate. Get from
https://pki.google.com/roots.pem
--num_messages NUM_MESSAGES
Number of messages to publish.
--mqtt_bridge_hostname MQTT_BRIDGE_HOSTNAME
MQTT bridge hostname.
--mqtt_bridge_port MQTT_BRIDGE_PORT
MQTT bridge port.
To run this sample:
$ python gcs_send_to_device.py
usage: gcs_send_to_device.py [-h] --project_id PROJECT_ID --bucket_name
BUCKET_NAME --gcs_file_name GCS_FILE_NAME
--source_file_name SOURCE_FILE_NAME
--destination_file_name DESTINATION_FILE_NAME
--registry_id REGISTRY_ID --device_id DEVICE_ID
[--service_account_json SERVICE_ACCOUNT_JSON]
[--cloud_region CLOUD_REGION]
Example of uploading a config (file) to Google Cloud Storage, then sending the
bucket name and file name for the config to a Cloud IoT Core device.
optional arguments:
-h, --help show this help message and exit
--project_id PROJECT_ID
GCP project name.
--bucket_name BUCKET_NAME
The name of the bucket containing the file.
--gcs_file_name GCS_FILE_NAME
The name of the file to be sent.
--source_file_name SOURCE_FILE_NAME
The name of file on the local file system.
--destination_file_name DESTINATION_FILE_NAME
The file to write to on the device.
--registry_id REGISTRY_ID
The registry for the device.
--device_id DEVICE_ID
The device to which to send the config update.
--service_account_json SERVICE_ACCOUNT_JSON
Path to service account json file.
--cloud_region CLOUD_REGION
Cloud region