Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
resources
README.rst
README.rst.in
manager.py
manager_test.py
requirements.txt

README.rst

Google Cloud IoT Core Python Samples

https://gstatic.com/cloudssh/images/open-btn.png

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 manage device authorization.

Setup

Authentication

This sample requires you to have authentication setup. Refer to the Authentication Getting Started Guide for instructions on setting up credentials for applications.

Install Dependencies

  1. 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
  2. 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.

  3. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.

    $ virtualenv env
    $ source env/bin/activate
  4. Install the dependencies needed to run the samples.

    $ pip install -r requirements.txt

Samples

Manager

https://gstatic.com/cloudssh/images/open-btn.png

To run this sample:

$ python manager.py

usage: manager.py [-h] [--cloud_region CLOUD_REGION]
                  [--pubsub_topic PUBSUB_TOPIC] [--config CONFIG]
                  [--device_id DEVICE_ID]
                  [--ec_public_key_file EC_PUBLIC_KEY_FILE]
                  [--project_id PROJECT_ID] [--registry_id REGISTRY_ID]
                  [--rsa_certificate_file RSA_CERTIFICATE_FILE]
                  [--service_account_json SERVICE_ACCOUNT_JSON]
                  [--version VERSION] [--member MEMBER] [--role ROLE]
                  {create-es256,create-registry,create-rsa256,create-topic,create-unauth,delete-device,delete-registry,get,get-config-versions,get-iam-permissions,get-registry,get-state,list,list-registries,patch-es256,patch-rs256,set-config,set-iam-permissions}
                  ...

Example of using the Google Cloud IoT Core device manager to administer
devices.

Usage example:

    python manager.py \
      --project_id=my-project-id \
      --cloud_region=us-central1 \
      --service_account_json=$HOME/service_account.json \
      list-registries

positional arguments:
  {create-es256,create-registry,create-rsa256,create-topic,create-unauth,delete-device,delete-registry,get,get-config-versions,get-iam-permissions,get-registry,get-state,list,list-registries,patch-es256,patch-rs256,set-config,set-iam-permissions}
    create-es256        Create a new device with the given id, using ES256 for
                        authentication.
    create-registry     Gets or creates a device registry.
    create-rsa256       Create a new device with the given id, using RS256 for
                        authentication.
    create-topic        Creates a PubSub Topic and grants access to Cloud IoT
                        Core.
    create-unauth       Create a new device without authentication.
    delete-device       Delete the device with the given id.
    delete-registry     Deletes the specified registry.
    get                 Retrieve the device with the given id.
    get-config-versions
                        Lists versions of a device config in descending order
                        (newest first).
    get-iam-permissions
                        Retrieves IAM permissions for the given registry.
    get-registry        Retrieves a device registry.
    get-state           Retrieve a device's state blobs.
    list                List all devices in the registry.
    list-registries     List all registries in the project.
    patch-es256         Patch the device to add an ES256 public key to the
                        device.
    patch-rs256         Patch the device to add an RSA256 public key to the
                        device.
    set-config          Patch the device to add an RSA256 public key to the
                        device.
    set-iam-permissions
                        Sets IAM permissions for the given registry to a
                        single role/member.

optional arguments:
  -h, --help            show this help message and exit
  --cloud_region CLOUD_REGION
                        GCP cloud region
  --pubsub_topic PUBSUB_TOPIC
                        Google Cloud Pub/Sub topic. Format is
                        projects/project_id/topics/topic-id
  --config CONFIG       Configuration sent to a device.
  --device_id DEVICE_ID
                        Device id.
  --ec_public_key_file EC_PUBLIC_KEY_FILE
                        Path to public ES256 key file.
  --project_id PROJECT_ID
                        GCP cloud project name.
  --registry_id REGISTRY_ID
                        Registry id. If not set, a name will be generated.
  --rsa_certificate_file RSA_CERTIFICATE_FILE
                        Path to RS256 certificate file.
  --service_account_json SERVICE_ACCOUNT_JSON
                        Path to service account json file.
  --version VERSION     Version number for setting device configuration.
  --member MEMBER       Member used for IAM commands.
  --role ROLE           Role used for IAM commands.
You can’t perform that action at this time.