Skip to content

Commit

Permalink
Initial commit of sample
Browse files Browse the repository at this point in the history
  • Loading branch information
gguuss committed May 16, 2017
1 parent 248c772 commit dd78c5c
Show file tree
Hide file tree
Showing 12 changed files with 844 additions and 0 deletions.
29 changes: 29 additions & 0 deletions iot/api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Cloud IoT Core Python Samples
This folder contains Python samples that demonstrate an overview of the
Google Cloud IoT Core platform.

## Quickstart
1. Install the gCloud CLI as described in [the device manager guide](https://cloud-dot-devsite.googleplex.com/iot/docs/device_manager_guide).
2. Create a PubSub topic:

gcloud beta pubsub topics create projects/my-iot-project/topics/device-events

3. Add the service account `cloud-iot@system.gserviceaccount.com` to that
PubSub topic from the [Cloud Developer Console](https://console.cloud.google.com)
or by using the helper script in the /scripts folder.

4. Create a registry:

gcloud alpha iot registries create my-registry \
--project=my-iot-project \
--region=us-central1 \
--pubsub-topic=projects/my-iot-project/topics/device-events

5. Use the `generate_keys.sh` script to generate your signing keys:

./generate_keys.sh

6. Connect a sample device using the sample app in the `mqtt_example` folder.
7. Learn how to manage devices programatically with the sample app in the
`manager` folder.

20 changes: 20 additions & 0 deletions iot/api/generate_keys.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

openssl req -x509 -newkey rsa:2048 -keyout rsa_private.pem -nodes -out \
rsa_cert.pem -subj "/CN=unused"
openssl ecparam -genkey -name prime256v1 -noout -out ec_private.pem
openssl ec -in ec_private.pem -pubout -out ec_public.pem
40 changes: 40 additions & 0 deletions iot/api/manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Cloud IoT Core Device Manager Python Sample

This sample application shows you how to manage devices programmatically using
Python.


# Setup

1. Use virtualenv to create a local Python environment.

virtualenv env && source env/bin/activate

2. Install the dependencies

pip install -r requirements.txt


# Running the sample

The following snippet summarizes usage for the device manager sample:

usage: cloudiot_device_manager_example.py [-h] \
--project_id PROJECT_ID \
--pubsub_topic PUBSUB_TOPIC \
--api_key API_KEY \
[--ec_public_key_file EC_PUBLIC_KEY_FILE] \
[--rsa_certificate_file RSA_CERTIFICATE_FILE] \
[--cloud_region CLOUD_REGION] \
[--service_account_json SERVICE_ACCOUNT_JSON] \
[--registry_id REGISTRY_ID]


For example, if your project-id is `blue-jet-123` and your service account
credentials are stored in `creds.json` in your home folder, the following
command would run the sample:

python cloudiot_device_manager_example.py \
--project_id blue-jet-123 \
--api_key=YOUR_API_KEY \
--service_account_json $HOME/creds.json
Loading

0 comments on commit dd78c5c

Please sign in to comment.