-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
883 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# 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.google.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. Register a device: | ||
|
||
gcloud alpha iot devices create my-python-device \ | ||
--project=my-iot-project \ | ||
--region=us-central1 \ | ||
--registry=my-registry \ | ||
--public-key path=rsa_cert.pem,type=rs256 | ||
|
||
7. Connect a sample device using the sample app in the `mqtt_example` folder. | ||
8. Learn how to manage devices programatically with the sample app in the | ||
`manager` folder. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# 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 \ | ||
--pubsub_topic projects/blue-jet-123/topics/device-events \ | ||
--ec_public_key ../ec_public.pem \ | ||
--rsa_certificate_file ../rsa_cert.pem \ | ||
--api_key YOUR_API_KEY \ | ||
--service_account_json $HOME/creds.json |
Oops, something went wrong.