8000 python-iot/samples/api-client/manager at develop · ClearBlade/python-iot · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
 
 

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 3.6+.

    $ 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] [--algorithm {RS256,ES256}]
                  [--certificate_path CERTIFICATE_PATH]
                  [--cloud_region CLOUD_REGION] [--pubsub_topic PUBSUB_TOPIC]
                  [--config CONFIG] [--device_id DEVICE_ID]
                  [--ec_public_key_file EC_PUBLIC_KEY_FILE]
                  [--gateway_id GATEWAY_ID] [--member MEMBER] [--role ROLE]
                  [--send_command SEND_COMMAND] [--project_id PROJECT_ID]
                  [--registry_id REGISTRY_ID]
                  [--rsa_certificate_file RSA_CERTIFICATE_FILE]
                  [--service_account_json SERVICE_ACCOUNT_JSON]
                  [--version VERSION]
                  {bind-device-to-gateway,create-es256,create-gateway,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-devices-for-gateway,list-gateways,list-registries,patch-es256,patch-rs256,send-command,set-config,set-iam-permissions,unbind-device-from-gateway}
                  ...

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:
  {bind-device-to-gateway,create-es256,create-gateway,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-devices-for-gateway,list-gateways,list-registries,patch-es256,patch-rs256,send-command,set-config,set-iam-permissions,unbind-device-from-gateway}
    bind-device-to-gateway
                        Binds a device to a gateway.
    create-es256        Create a new device with the given id, using ES256 for
                        authentication.
    create-gateway      Create a gateway to bind devices to.
    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-devices-for-gateway
                        List devices bound to a gateway
    list-gateways       Lists gateways in a 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.
    send-command        Send a command to a 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.
    unbind-device-from-gateway
                        Unbinds a device to a gateway.

optional arguments:
  -h, --help            show this help message and exit
  --algorithm {RS256,ES256}
                        Which encryption algorithm to use to generate the JWT.
  --certificate_path CERTIFICATE_PATH
                        Path to public certificate.
  --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.
  --gateway_id GATEWAY_ID
                        Gateway identifier.
  --member MEMBER       Member used for IAM commands.
  --role ROLE           Role used for IAM commands.
  --send_command SEND_COMMAND
                        The command sent to the device
  --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.
0