Skip to content

Commit

Permalink
docs(samples): Adds samples used in documentation (#266)
Browse files Browse the repository at this point in the history
  • Loading branch information
gguuss authored Apr 27, 2020
1 parent f075ba6 commit 38d8148
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 40 deletions.
63 changes: 26 additions & 37 deletions packages/google-cloud-iot/samples/README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,41 @@
[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
[//]: # "To regenerate it, use `python -m synthtool`."
<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 Internet of Things (IoT) Core: Node.js Samples](https://github.com/googleapis/nodejs-iot)

[![Open in Cloud Shell][shell_img]][shell_link]
This folder contains NodeJS samples that demonstrate an overview of the Google
Cloud IoT Core platform.

> Node.js idiomatic client for [Cloud IoT Core][product-docs].
## Quickstart

[Google Cloud Internet of Things (IoT) Core](https://cloud.google.com/iot/docs) is a fully managed service for securely connecting and managing IoT devices, from a few to millions. Ingest data from connected devices and build rich applications that integrate with the other big data services of Google Cloud Platform.
1. Install the Google Cloud SDK as described in [the Cloud IoT Core documentation](https://cloud.google.com/iot/docs/how-tos/getting-started#set_up_the_google_cloud_sdk_and_gcloud).
1. Create a Cloud Pub/Sub topic:

## Table of Contents
gcloud beta pubsub topics create projects/my-iot-project/topics/device-events

* [Before you begin](#before-you-begin)
* [Samples](#samples)
* [Quickstart](#quickstart)
1. Add the service account `cloud-iot@system.gserviceaccount.com` with the role `Publisher` 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.

## Before you begin
1. Create a registry:

Before running the samples, make sure you've followed the steps outlined in
[Using the client library](https://github.com/googleapis/nodejs-iot#using-the-client-library).
gcloud iot registries create "your-registry-id" \
--project=<your-project-id> \
--region=us-central1 \
--event-notification-config=topic=projects/<your-project-id>/topics/<pubsub-topic-name>

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

`npm install`
./scripts/generate_keys.sh

`cd ..`
1. Create a device.

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



### Quickstart

View the [source code](https://github.com/googleapis/nodejs-iot/blob/master/samples/quickstart.js).

[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-iot&page=editor&open_in_editor=samples/quickstart.js,samples/README.md)

__Usage:__


`node samples/quickstart.js`






[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
[shell_link]: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-iot&page=editor&open_in_editor=samples/README.md
[product-docs]: https://cloud.google.com/iot
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.
16 changes: 13 additions & 3 deletions packages/google-cloud-iot/samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,23 @@
"repository": "googleapis/nodejs-iot",
"private": true,
"scripts": {
"test": "mocha --timeout 10000"
"test": "mocha --timeout 60000 manager/system-test/manager.test.js http_example/system-test/cloudiot_http_example.test.js mqtt_example/system-test/cloudiot_mqtt_example.test.js"
},
"dependencies": {
"@google-cloud/iot": "^2.0.0"
"@google-cloud/iot": "^2.0.0",
"@google-cloud/pubsub": "^1.6.0",
"googleapis": "^47.0.0"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^7.0.0"
"hash_file": "^0.1.1",
"jsonwebtoken": "^8.5.0",
"mocha": "^7.1.1",
"mqtt": "^3.0.0",
"request": "^2.88.0",
"retry-request": "^4.0.0",
"tape": "^4.13.0",
"uuid": "^3.3.2",
"yargs": "^15.1.0"
}
}

0 comments on commit 38d8148

Please sign in to comment.