-
Notifications
You must be signed in to change notification settings - Fork 2k
Final additions in private beta #489
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e47f4c3
Final additions in private beta
gguuss e670a34
Changes to registry create
gguuss 4c83c85
Adds HTTP client and state support for MQTT
gguuss d4ecd50
Removes extra code and discovery doc
gguuss 915d197
Add product link to readme, options to yargs.
gguuss 02fa580
Merge branch 'master' into iot-snippets
gguuss 562e952
Add license to package.json
gguuss 9e8af84
Adds includecode blocks to MQTT / HTTP
gguuss 7682821
Merge branch 'iot-snippets' of https://github.com/GoogleCloudPlatform…
gguuss ddc4231
Fix lint
gguuss 930b9fd
Adds comment on state vs event frequency
gguuss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,61 @@ | ||
<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 HTTP example | ||
|
||
This sample app publishes messages to Cloud Pub/Sub or states using the HTTP | ||
bridge provided as part of Google Cloud IoT Core. | ||
|
||
Note that before you can run this sample, you must register a device 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_http_example_nodejs [options] | ||
|
||
Example Google Cloud IoT Core HTTP device connection code. | ||
|
||
Options: | ||
|
||
-h, --help output usage information | ||
--project_id <project_id> GCP cloud project name. | ||
--registry_id <registry_id> Cloud IoT Core registry id. | ||
--device_id <device_id> Cloud IoT Core device id. | ||
--private_key_file <key_file> Path to private key file. | ||
--algorithm <algorithm> Encryption algorithm to generate the JWT. Either RS256 or ES256 | ||
--cloud_region [region] GCP cloud region | ||
--num_messages [num] Number of messages to publish. | ||
--http_bridge_address [address] HTTP bridge address. | ||
--message_type [events|state] The message type to publish. | ||
|
||
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_http_example_nodejs.js \ | ||
--project_id=blue-jet-123 \ | ||
--registry_id=my-registry \ | ||
--device_id=my-node-device \ | ||
--private_key_file=../rsa_private.pem \ | ||
--algorithm=RS256 | ||
|
||
# Reading Cloud Pub/Sub messages written by the sample client | ||
|
||
1. Create a subscription to your topic. | ||
|
||
gcloud beta pubsub subscriptions create \ | ||
projects/your-project-id/subscriptions/my-subscription \ | ||
--topic device-events | ||
|
||
2. Read messages published to the topic | ||
|
||
gcloud beta pubsub subscriptions pull --auto-ack \ | ||
projects/my-iot-project/subscriptions/my-subscription |
This file contains hidden or 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,279 @@ | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is this file for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed, the device API was to be exposed as Apiary via device REST discovery. |
||
"rootUrl": "https://cloudiot-device.googleapis.com/", | ||
"basePath": "", | ||
"ownerDomain": "google.com", | ||
"name": "cloudiot", | ||
"batchPath": "batch", | ||
"revision": "20170909", | ||
"id": "cloudiot:v1beta1", | ||
"documentationLink": "https://cloud.google.com/iot", | ||
"title": "Google Cloud IoT API", | ||
"discoveryVersion": "v1", | ||
"ownerName": "Google", | ||
"version_module": true, | ||
"resources": { | ||
"projects": { | ||
"resources": { | ||
"locations": { | ||
"resources": { | ||
"registries": { | ||
"resources": { | ||
"devices": { | ||
"methods": { | ||
"setState": { | ||
"flatPath": "v1beta1/projects/{projectsId}/locations/{locationsId}/registries/{registriesId}/devices/{devicesId}:setState", | ||
"id": "cloudiot.projects.locations.registries.devices.setState", | ||
"path": "v1beta1/{+name}:setState", | ||
"description": "Sets the state of a device.", | ||
"request": { | ||
"$ref": "HttpSetDeviceStateRequest" | ||
}, | ||
"response": { | ||
"$ref": "Empty" | ||
}, | ||
"parameterOrder": [ | ||
"name" | ||
], | ||
"httpMethod": "POST", | ||
"parameters": { | ||
"name": { | ||
"type": "string", | ||
"required": true, | ||
"pattern": "^projects/[^/]+/locations/[^/]+/registries/[^/]+/devices/[^/]+$", | ||
"location": "path", | ||
"description": "The name of the device. For example,\n`projects/p0/locations/us-central1/registries/registry0/devices/device0`." | ||
} | ||
} | ||
}, | ||
"getConfig": { | ||
"response": { | ||
"$ref": "HttpDeviceConfig" | ||
}, | ||
"parameterOrder": [ | ||
"name" | ||
], | ||
"httpMethod": "GET", | ||
"parameters": { | ||
"name": { | ||
"location": "path", | ||
"description": "The name of the device. For example,\n`projects/p0/locations/us-central1/registries/registry0/devices/device0`.", | ||
"type": "string", | ||
"required": true, | ||
"pattern": "^projects/[^/]+/locations/[^/]+/registries/[^/]+/devices/[^/]+$" | ||
}, | ||
"localVersion": { | ||
"type": "string", | ||
"location": "query", | ||
"format": "int64", | ||
"description": "If zero, returns the current device configuration from Cloud IoT Core.\nIf nonzero, specifies the local version of the configuration on the device.\nThe server returns config data only if a higher (newer) version is\navailable from Cloud IoT Core.\nIf this value is higher than the latest version available in Cloud IoT\nCore, returns an `OUT_OF_RANGE` error." | ||
} | ||
}, | ||
"flatPath": "v1beta1/projects/{projectsId}/locations/{locationsId}/registries/{registriesId}/devices/{devicesId}/config", | ||
"id": "cloudiot.projects.locations.registries.devices.getConfig", | ||
"path": "v1beta1/{+name}/config", | ||
"description": "Gets the configuration of a device." | ||
}, | ||
"publishEvent": { | ||
"httpMethod": "POST", | ||
"parameterOrder": [ | ||
"name" | ||
], | ||
"response": { | ||
"$ref": "HttpPublishEventResponse" | ||
}, | ||
"parameters": { | ||
"name": { | ||
"type": "string", | ||
"required": true, | ||
"pattern": "^projects/[^/]+/locations/[^/]+/registries/[^/]+/devices/[^/]+$", | ||
"location": "path", | ||
"description": "The name of the device. For example,\n`projects/p0/locations/us-central1/registries/registry0/devices/device0`." | ||
} | ||
}, | ||
"flatPath": "v1beta1/projects/{projectsId}/locations/{locationsId}/registries/{registriesId}/devices/{devicesId}:publishEvent", | ||
"path": "v1beta1/{+name}:publishEvent", | ||
"id": "cloudiot.projects.locations.registries.devices.publishEvent", | ||
"description": "Publishes a telemetry event for a device.", | ||
"request": { | ||
"$ref": "HttpPublishEventRequest" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"parameters": { | ||
"upload_protocol": { | ||
"location": "query", | ||
"description": "Upload protocol for media (e.g. \"raw\", \"multipart\").", | ||
"type": "string" | ||
}, | ||
"prettyPrint": { | ||
"default": "true", | ||
"type": "boolean", | ||
"location": "query", | ||
"description": "Returns response with indentations and line breaks." | ||
}, | ||
"fields": { | ||
"location": "query", | ||
"description": "Selector specifying which fields to include in a partial response.", | ||
"type": "string" | ||
}, | ||
"uploadType": { | ||
"type": "string", | ||
"location": "query", | ||
"description": "Legacy upload protocol for media (e.g. \"media\", \"multipart\")." | ||
}, | ||
"callback": { | ||
"type": "string", | ||
"location": "query", | ||
"description": "JSONP" | ||
}, | ||
"$.xgafv": { | ||
"type": "string", | ||
"enumDescriptions": [ | ||
"v1 error format", | ||
"v2 error format" | ||
], | ||
"location": "query", | ||
"enum": [ | ||
"1", | ||
"2" | ||
], | ||
"description": "V1 error format." | ||
}, | ||
"alt": { | ||
"type": "string", | ||
"enumDescriptions": [ | ||
"Responses with Content-Type of application/json", | ||
"Media download with context-dependent Content-Type", | ||
"Responses with Content-Type of application/x-protobuf" | ||
], | ||
"location": "query", | ||
"description": "Data format for response.", | ||
"default": "json", | ||
"enum": [ | ||
"json", | ||
"media", | ||
"proto" | ||
] | ||
}, | ||
"key": { | ||
"location": "query", | ||
"description": "API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.", | ||
"type": "string" | ||
}, | ||
"access_token": { | ||
"location": "query", | ||
"description": "OAuth access token.", | ||
"type": "string" | ||
}, | ||
"quotaUser": { | ||
"type": "string", | ||
"location": "query", | ||
"description": "Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters." | ||
}, | ||
"pp": { | ||
"default": "true", | ||
"type": "boolean", | ||
"location": "query", | ||
"description": "Pretty-print response." | ||
}, | ||
"oauth_token": { | ||
"location": "query", | ||
"description": "OAuth 2.0 token for the current user.", | ||
"type": "string" | ||
}, | ||
"bearer_token": { | ||
"type": "string", | ||
"location": "query", | ||
"description": "OAuth bearer token." | ||
} | ||
}, | ||
"schemas": { | ||
"HttpPublishEventResponse": { | ||
"type": "object", | ||
"properties": {}, | ||
"id": "HttpPublishEventResponse", | ||
"description": "Response for `PublishEvent`." | ||
}, | ||
"HttpSetDeviceStateRequest": { | ||
"type": "object", | ||
"properties": { | ||
"state": { | ||
"$ref": "HttpDeviceState", | ||
"description": "The device state." | ||
} | ||
}, | ||
"id": "HttpSetDeviceStateRequest", | ||
"description": "Request for `SetDeviceState`." | ||
}, | ||
"HttpDeviceConfig": { | ||
"type": "object", | ||
"properties": { | ||
"version": { | ||
"type": "string", | ||
"format": "int64", | ||
"description": "The version of the configuration in Cloud IoT Core." | ||
}, | ||
"binaryData": { | ||
"format": "byte", | ||
"description": "Data in binary format.", | ||
"type": "string" | ||
} | ||
}, | ||
"id": "HttpDeviceConfig", | ||
"description": "The device configuration obtained from Cloud IoT Core." | ||
}, | ||
"HttpDeviceState": { | ||
"type": "object", | ||
"properties": { | ||
"binaryData": { | ||
"type": "string", | ||
"format": "byte", | ||
"description": "Data in binary format." | ||
} | ||
}, | ||
"id": "HttpDeviceState", | ||
"description": "The device state reported to Cloud IoT Core." | ||
}, | ||
"HttpPublishEventRequest": { | ||
"type": "object", | ||
"properties": { | ||
"subFolder": { | ||
"type": "string", | ||
"description": "Optional subfolder for the telemetry event. This can be used to classify\ntypes of events, and is included in the Pub/Sub message attributes." | ||
}, | ||
"binaryData": { | ||
"format": "byte", | ||
"description": "Payload data in binary format.", | ||
"type": "string" | ||
} | ||
}, | ||
"id": "HttpPublishEventRequest", | ||
"description": "Request for `PublishEvent`." | ||
}, | ||
"Empty": { | ||
"description": "A generic empty message that you can re-use to avoid defining duplicated\nempty messages in your APIs. A typical example is to use it as the request\nor the response type of an API method. For instance:\n\n service Foo {\n rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);\n }\n\nThe JSON representation for `Empty` is empty JSON object `{}`.", | ||
"type": "object", | ||
"properties": {}, | ||
"id": "Empty" | ||
} | ||
}, | ||
"icons": { | ||
"x32": "http://www.google.com/images/icons/product/search-32.gif", | ||
"x16": "http://www.google.com/images/icons/product/search-16.gif" | ||
}, | ||
"protocol": "rest", | ||
"version": "v1beta1", | ||
"baseUrl": "https://cloudiot-device.googleapis.com/", | ||
"canonicalName": "Cloud Iot", | ||
"servicePath": "", | ||
"description": "Registers and manages IoT (Internet of Things) devices that connect to the Google Cloud Platform.\n", | ||
"kind": "discovery#restDescription" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what "Cloud Pub/Sub or states" means.