Skip to content

Commit 47c6a93

Browse files
gguussdpebot
authored andcommitted
Cloud iot core (#946)
* Initial commit. * Changes oauth2 client * Fixes google.auth and addresses changes in v1beta1
1 parent 215b46e commit 47c6a93

12 files changed

+892
-0
lines changed

iot/api-client/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Cloud IoT Core Python Samples
2+
This folder contains Python samples that demonstrate an overview of the
3+
Google Cloud IoT Core platform.
4+
5+
## Quickstart
6+
1. Install the gCloud CLI as described in [the device manager guide](https://cloud.google.com/iot/docs/device_manager_guide).
7+
2. Create a PubSub topic:
8+
9+
gcloud beta pubsub topics create projects/my-iot-project/topics/device-events
10+
11+
3. Add the service account `[email protected]` to that
12+
PubSub topic from the [Cloud Developer Console](https://console.cloud.google.com)
13+
or by using the helper script in the /scripts folder.
14+
15+
4. Create a registry:
16+
17+
gcloud alpha iot registries create my-registry \
18+
--project=my-iot-project \
19+
--region=us-central1 \
20+
--pubsub-topic=projects/my-iot-project/topics/device-events
21+
22+
5. Use the `generate_keys.sh` script to generate your signing keys:
23+
24+
./generate_keys.sh
25+
26+
6. Register a device:
27+
28+
gcloud alpha iot devices create my-python-device \
29+
--project=my-iot-project \
30+
--region=us-central1 \
31+
--registry=my-registry \
32+
--public-key path=rsa_cert.pem,type=rs256
33+
34+
7. Connect a sample device using the sample app in the `mqtt_example` folder.
35+
8. Learn how to manage devices programatically with the sample app in the
36+
`manager` folder.
37+

iot/api-client/generate_keys.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017 Google Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
openssl req -x509 -newkey rsa:2048 -keyout rsa_private.pem -nodes -out \
18+
rsa_cert.pem -subj "/CN=unused"
19+
openssl ecparam -genkey -name prime256v1 -noout -out ec_private.pem
20+
openssl ec -in ec_private.pem -pubout -out ec_public.pem

iot/api-client/manager/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Cloud IoT Core Device Manager Python Sample
2+
3+
This sample application shows you how to manage devices programmatically using
4+
Python.
5+
6+
7+
# Setup
8+
9+
1. Use virtualenv to create a local Python environment.
10+
11+
virtualenv env && source env/bin/activate
12+
13+
2. Install the dependencies
14+
15+
pip install -r requirements.txt
16+
17+
18+
# Running the sample
19+
20+
The following snippet summarizes usage for the device manager sample:
21+
22+
usage: cloudiot_device_manager_example.py [-h] \
23+
--project_id PROJECT_ID \
24+
--pubsub_topic PUBSUB_TOPIC \
25+
--api_key API_KEY \
26+
[--ec_public_key_file EC_PUBLIC_KEY_FILE] \
27+
[--rsa_certificate_file RSA_CERTIFICATE_FILE] \
28+
[--cloud_region CLOUD_REGION] \
29+
[--service_account_json SERVICE_ACCOUNT_JSON] \
30+
[--registry_id REGISTRY_ID]
31+
32+
33+
For example, if your project-id is `blue-jet-123` and your service account
34+
credentials are stored in `creds.json` in your home folder, the following
35+
command would run the sample:
36+
37+
python cloudiot_device_manager_example.py \
38+
--project_id blue-jet-123 \
39+
--pubsub_topic projects/blue-jet-123/topics/device-events \
40+
--ec_public_key ../ec_public.pem \
41+
--rsa_certificate_file ../rsa_cert.pem \
42+
--api_key YOUR_API_KEY \
43+
--service_account_json $HOME/creds.json

0 commit comments

Comments
 (0)