|
| 1 | +.. This file is automatically generated. Do not edit this file directly. |
| 2 | +
|
| 3 | +Google Cloud IoT Core API Python Samples |
| 4 | +=============================================================================== |
| 5 | + |
| 6 | +This directory contains samples for Google Cloud IoT Core API. `Google Cloud IoT Core`_ allows developers to easily integrate Publish and Subscribe functionality with devices and programmatically manage device authorization. |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +.. _Google Cloud IoT Core API: https://cloud.google.com/vision/docs |
| 12 | + |
| 13 | +Setup |
| 14 | +------------------------------------------------------------------------------- |
| 15 | + |
| 16 | + |
| 17 | +Authentication |
| 18 | +++++++++++++++ |
| 19 | + |
| 20 | +Authentication is typically done through `Application Default Credentials`_, |
| 21 | +which means you do not have to change the code to authenticate as long as |
| 22 | +your environment has credentials. You have a few options for setting up |
| 23 | +authentication: |
| 24 | + |
| 25 | +#. When running locally, use the `Google Cloud SDK`_ |
| 26 | + |
| 27 | + .. code-block:: bash |
| 28 | +
|
| 29 | + gcloud auth application-default login |
| 30 | +
|
| 31 | +
|
| 32 | +#. When running on App Engine or Compute Engine, credentials are already |
| 33 | + set-up. However, you may need to configure your Compute Engine instance |
| 34 | + with `additional scopes`_. |
| 35 | + |
| 36 | +#. You can create a `Service Account key file`_. This file can be used to |
| 37 | + authenticate to Google Cloud Platform services from any environment. To use |
| 38 | + the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to |
| 39 | + the path to the key file, for example: |
| 40 | + |
| 41 | + .. code-block:: bash |
| 42 | +
|
| 43 | + export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json |
| 44 | +
|
| 45 | +.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow |
| 46 | +.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using |
| 47 | +.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount |
| 48 | + |
| 49 | +Install Dependencies |
| 50 | +++++++++++++++++++++ |
| 51 | + |
| 52 | +#. Install `pip`_ and `virtualenv`_ if you do not already have them. |
| 53 | + |
| 54 | +#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. |
| 55 | + |
| 56 | + .. code-block:: bash |
| 57 | +
|
| 58 | + $ virtualenv env |
| 59 | + $ source env/bin/activate |
| 60 | +
|
| 61 | +#. Install the dependencies needed to run the samples. |
| 62 | + |
| 63 | + .. code-block:: bash |
| 64 | +
|
| 65 | + $ pip install -r requirements.txt |
| 66 | +
|
| 67 | +.. _pip: https://pip.pypa.io/ |
| 68 | +.. _virtualenv: https://virtualenv.pypa.io/ |
| 69 | + |
| 70 | +Samples |
| 71 | +------------------------------------------------------------------------------- |
| 72 | + |
| 73 | +Manager |
| 74 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 75 | + |
| 76 | + |
| 77 | + |
| 78 | +To run this sample: |
| 79 | + |
| 80 | +.. code-block:: bash |
| 81 | +
|
| 82 | + $ python manager.py |
| 83 | +
|
| 84 | + usage: manager.py [-h] --project_id PROJECT_ID --pubsub_topic PUBSUB_TOPIC |
| 85 | + --api_key API_KEY [--ec_public_key_file EC_PUBLIC_KEY_FILE] |
| 86 | + [--rsa_certificate_file RSA_CERTIFICATE_FILE] |
| 87 | + [--cloud_region CLOUD_REGION] |
| 88 | + [--service_account_json SERVICE_ACCOUNT_JSON] |
| 89 | + [--registry_id REGISTRY_ID] [--device_id DEVICE_ID] |
| 90 | + {create-es256,create-registry,create-rsa256,create-topic,create-unauth,delete-device,delete-registry,get,list,patch-es256,patch-rs256} |
| 91 | + ... |
| 92 | + |
| 93 | + Example of using the Google Cloud IoT Core device manager to administer |
| 94 | + devices. |
| 95 | + |
| 96 | + Usage example: |
| 97 | + |
| 98 | + python manager.py \ |
| 99 | + --project_id=my-project-id \ |
| 100 | + --pubsub_topic=projects/my-project-id/topics/my-topic-id \ |
| 101 | + --api_key=YOUR_API_KEY \ |
| 102 | + --ec_public_key_file=../ec_public.pem \ |
| 103 | + --rsa_certificate_file=../rsa_cert.pem \ |
| 104 | + --service_account_json=$HOME/service_account.json |
| 105 | + list |
| 106 | + |
| 107 | + positional arguments: |
| 108 | + {create-es256,create-registry,create-rsa256,create-topic,create-unauth,delete-device,delete-registry,get,list,patch-es256,patch-rs256} |
| 109 | + create-es256 Create a new device with the given id, using ES256 for |
| 110 | + authentication. |
| 111 | + create-registry Gets or creates a device registry. |
| 112 | + create-rsa256 Create a new device with the given id, using RS256 for |
| 113 | + authentication. |
| 114 | + create-topic Creates a PubSub Topic and grants access to Cloud IoT |
| 115 | + Core. |
| 116 | + create-unauth Create a new device without authentication. |
| 117 | + delete-device Delete the device with the given id. |
| 118 | + delete-registry Deletes the specified registry. |
| 119 | + get Retrieve the device with the given id. |
| 120 | + list List all devices in the registry. |
| 121 | + patch-es256 Patch the device to add an ES256 public key to the |
| 122 | + device. |
| 123 | + patch-rs256 Patch the device to add an RSA256 public key to the |
| 124 | + device. |
| 125 | + |
| 126 | + optional arguments: |
| 127 | + -h, --help show this help message and exit |
| 128 | + --project_id PROJECT_ID |
| 129 | + GCP cloud project name. |
| 130 | + --pubsub_topic PUBSUB_TOPIC |
| 131 | + Google Cloud Pub/Sub topic. Format is |
| 132 | + projects/project_id/topics/topic-id |
| 133 | + --api_key API_KEY Your API key. |
| 134 | + --ec_public_key_file EC_PUBLIC_KEY_FILE |
| 135 | + Path to public ES256 key file. |
| 136 | + --rsa_certificate_file RSA_CERTIFICATE_FILE |
| 137 | + Path to RS256 certificate file. |
| 138 | + --cloud_region CLOUD_REGION |
| 139 | + GCP cloud region |
| 140 | + --service_account_json SERVICE_ACCOUNT_JSON |
| 141 | + Path to service account json file. |
| 142 | + --registry_id REGISTRY_ID |
| 143 | + Registry id. If not set, a name will be generated. |
| 144 | + --device_id DEVICE_ID |
| 145 | + Device id. |
| 146 | +
|
| 147 | +
|
| 148 | +
|
| 149 | +
|
| 150 | +.. _Google Cloud SDK: https://cloud.google.com/sdk/ |
0 commit comments