
.. This file is automatically generated. Do not edit this file directly.

Google Cloud IoT Core Python Samples
===============================================================================

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
   :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=iot/api-client/manager/README.rst


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.




.. _Google Cloud IoT Core: https://cloud.google.com/iot/docs


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.

.. _Authentication Getting Started Guide:
    https://cloud.google.com/docs/authentication/getting-started




Install Dependencies
++++++++++++++++++++

#. Clone python-docs-samples and change directory to the sample directory you want to use.

    .. code-block:: bash

        $ 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.

   .. _Python Development Environment Setup Guide:
       https://cloud.google.com/python/setup

#. Create a virtualenv. Samples are compatible with Python 3.6+.

    .. code-block:: bash

        $ virtualenv env
        $ source env/bin/activate

#. Install the dependencies needed to run the samples.

    .. code-block:: bash

        $ pip install -r requirements.txt

.. _pip: https://pip.pypa.io/
.. _virtualenv: https://virtualenv.pypa.io/






Samples
-------------------------------------------------------------------------------


Manager
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

.. image:: https://gstatic.com/cloudssh/images/open-btn.png
   :target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=iot/api-client/manager/manager.py,iot/api-client/manager/README.rst




To run this sample:

.. code-block:: bash

    $ 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.









.. _Google Cloud SDK: https://cloud.google.com/sdk/
