Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial commit of sample #394

Merged
merged 1 commit into from
May 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions iot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# Google Cloud IoT Core NodeJS Samples

This folder contains NodeJS samples that demonstrate an overview of the Google
Cloud IoT Core platform.

## Quickstart

1. Install the Google Cloud SDK as described in [the device manager guide](/iot/docs/device_manager_guide#install_the_gcloud_cli).
1. Create a Cloud Pub/Sub topic:

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

1. Add the service account `cloud-iot@system.gserviceaccount.com` to that
Cloud Pub/Sub topic from the [Cloud Developer Console](https://console.cloud.google.com)
or by setting the `GOOGLE_CLOUD_PROJECT` environment variable and using the
helper script in the `scripts/` folder.

1. 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

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

./scripts/generate_keys.sh

1. Create a device.

gcloud alpha iot devices create my-node-device \
--project=my-iot-project \
--region=us-central1 \
--registry=my-registry \
--public-key path=rsa_cert.pem,type=rs256

1. Connect a sample device using the sample app in the `mqtt_example` folder.
1. Learn how to manage devices programatically with the sample app in the
`manager` folder.
47 changes: 47 additions & 0 deletions iot/manager/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>

# Google Cloud IoT Core NodeJS Device Management example

This sample app demonstrates device management for Google Cloud IoT Core.

Note that before you run this sample, you must configure a Google Cloud PubSub
topic for Cloud IoT as described in the parent README.

# Setup

Run the following command to install the library dependencies for NodeJS:

npm install

# Running the sample

The following command summarizes the sample usage:

Usage: cloudiot_device_manager_example [options]

Example Google Cloud IoT device manager integration

Options:

-h, --help output usage information
--project_id <project_id> GCP cloud project name.
--pubsub_topic <pubsub_topic> Cloud Pub/Sub topic to use.
--api_key <api_key> Your API key.
--ec_public_key_file <ec_public_key_file> Path to EC public key.
--rsa_certificate_file <rsa_certificate_file> Path to RSA certificate file.
--cloud_region <cloud_region> GCP cloud region.
--service_account_json <service_account_json> Path to service account JSON file.
--registry_id <registry_id> Custom registry id. If not provided, a unique registry id will be generated.

For example, if your project ID is `blue-jet-123`, your service account
credentials are stored in your home folder in creds.json and you have generated
your credentials using the shell script provided in the parent folder, you can
run the sample as:

node cloudiot_device_manager_example.js \
--service_account_json=$HOME/creds.json \
--api_key=YOUR_CLIENT_ID \
--project_id=blue-jet-123 \
--pubsub_topic=projects/blue-jet-123/topics/device-events \
--ec_public_key_file=../ec_public.pem \
--rsa_certificate_file=../rsa_cert.pem
Loading