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. 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.
  1. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+.

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

    $ pip install -r requirements.txt

Samples

Cloud IoT Hub

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

To run this sample:

$ python hub.py

usage: hub.py [-h] --registry_id REGISTRY_ID --device_id DEVICE_ID
              --gateway_id GATEWAY_ID [--cloud_region CLOUD_REGION]
              [--data DATA] [--project_id PROJECT_ID]
              [--service_account_json SERVICE_ACCOUNT_JSON]
              [--jwt_expires_minutes JWT_EXPIRES_MINUTES]
              [--certificate_path CERTIFICATE_PATH]
              [--num_messages NUM_MESSAGES]
              [--private_key_file PRIVATE_KEY_FILE] [--ca_certs CA_CERTS]
              [--algorithm {RS256,ES256}]
              {create_gateway,bind_device_to_gateway,unbind_device_from_gateway,list_devices_for_gateway,list_gateways,send_data_from_bound_device,listen_for_config_messages}
              ...

Example of using the Google Cloud IoT Core device manager to send telemetry
messages on behalf of other devices.

Usage example:

    python hub.py \
      --device_id=bound-device-id \
      --gateway_id=your-gateway-id \
      --project_id=your-project-id \
      --data="optional telemetry data" \
      --registry_id=your-registry-id \
      --service_account_json=/path/to/your/service_account.json \
      create_gateway

positional arguments:
  {create_gateway,bind_device_to_gateway,unbind_device_from_gateway,list_devices_for_gateway,list_gateways,send_data_from_bound_device,listen_for_config_messages}
    create_gateway      Create a gateway to bind devices to.
    bind_device_to_gateway
                        Binds a device to a gateway.
    unbind_device_from_gateway
                        Unbinds a device to a gateway.
    list_devices_for_gateway
                        List devices bound to a gateway
    list_gateways       Lists gateways in a registry
    send_data_from_bound_device
                        Sends data from a gateway on behalf of a device that
                        is bound to it.
    listen_for_config_messages
                        Listens for configuration messages on the hub and
                        bound devices.

optional arguments:
  -h, --help            show this help message and exit
  --registry_id REGISTRY_ID
                        Registry id. If not set, a name will be generated.
  --device_id DEVICE_ID
                        Device identifier.
  --gateway_id GATEWAY_ID
                        Gateway identifier.
  --cloud_region CLOUD_REGION
                        GCP cloud region
  --data DATA           The telemetry data sent on behalf of a device
  --project_id PROJECT_ID
                        GCP cloud project name.
  --service_account_json SERVICE_ACCOUNT_JSON
                        Path to service account json file.
  --jwt_expires_minutes JWT_EXPIRES_MINUTES
                        Expiration time (in minutes) for JWT tokens.
  --certificate_path CERTIFICATE_PATH
                        Path to public certificate.
  --num_messages NUM_MESSAGES
                        Number of messages to send.
  --private_key_file PRIVATE_KEY_FILE
                        Path to private key file.
  --ca_certs CA_CERTS   CA root from https://pki.google.com/roots.pem
  --algorithm {RS256,ES256}
                        Which encryption algorithm to use to generate the JWT.