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

Final additions in private beta #489

Merged
merged 11 commits into from
Sep 26, 2017
61 changes: 61 additions & 0 deletions iot/http_example/README.md
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
Copy link
Member

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.

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
279 changes: 279 additions & 0 deletions iot/http_example/cloudiot.rest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this file for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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"
}
Loading