-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Initial commit of sample #669
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # 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 gCloud CLI as described in [the device manager guide](https://cloud-dot-devsite.googleplex.com/iot/docs/device_manager_guide). | ||
|
Contributor
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. Is the reference directly to the dev docsite correct ? is n't there a public whitelisted url ?
Contributor
Author
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. There is not, I also do not have the timeline for the whitelist being removed but it should be shorter than most of our whitelist alphas.
Contributor
Author
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. Done |
||
| 2. Create a PubSub topic: | ||
|
|
||
| gcloud beta pubsub topics create projects/my-iot-project/topics/device-events | ||
|
|
||
| 3. Add the special account `[email protected]` 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. Create a device. | ||
|
|
||
| gcloud alpha iot devices create my-java-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. | ||
|
Contributor
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. link to |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #!/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 | ||
| openssl pkcs8 -topk8 -inform PEM -outform DER -in rsa_private.pem \ | ||
| -nocrypt > rsa_private_pkcs8 | ||
| openssl pkcs8 -topk8 -inform PEM -outform DER -in ec_private.pem \ | ||
| -nocrypt > ec_private_pkcs8 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Cloud IoT Core Java Device Management example | ||
|
|
||
| This sample app demonstrates device management for Google Cloud IoT Core. | ||
|
|
||
| Note that before you can run the 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 libraries and build the sample with | ||
| Maven: | ||
|
|
||
| mvn clean compile assembly:single | ||
|
|
||
| ## Running the sample | ||
|
|
||
| The following command summarizes the sample usage: | ||
|
|
||
| mvn exec:java \ | ||
| -Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \ | ||
| -Dexec.args="-project_id=my-project-id \ | ||
| -pubsub_topic=projects/my-project-id/topics/my-topic-id \ | ||
| -ec_public_key_file=/path/to/ec_public.pem \ | ||
| -rsa_certificate_file=/path/to/rsa_cert.pem" | ||
|
|
||
| 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 | ||
|
Contributor
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. using the shell script -> please provide explicit script name with link location. |
||
| run the sample as: | ||
|
|
||
| mvn exec:java \ | ||
| -Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \ | ||
| -Dexec.args="-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" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| <!-- | ||
| 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. | ||
| --> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <groupId>com.example.cloud</groupId> | ||
| <artifactId>cloudiot-manager-demo</artifactId> | ||
| <packaging>jar</packaging> | ||
| <version>1.0</version> | ||
| <name>cloudiot-manager-demo</name> | ||
| <url>http://maven.apache.org</url> | ||
|
|
||
| <!-- Start local repo --> | ||
| <repositories> | ||
|
||
| <!-- Use a local directory for the Cloud IoT Core API dependency. --> | ||
| <repository> | ||
| <id>project.local</id> | ||
| <name>project</name> | ||
| <url>file:./repo</url> | ||
| </repository> | ||
| </repositories> | ||
| <!-- End of extra repo --> | ||
|
|
||
| <properties> | ||
| <maven.compiler.source>1.7</maven.compiler.source> | ||
| <maven.compiler.target>1.7</maven.compiler.target> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.google.apis</groupId> | ||
| <artifactId>google-api-services-cloudiot</artifactId> | ||
| <version>v1beta1-rev20170418-1.22.0-SNAPSHOT</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.oauth-client</groupId> | ||
| <artifactId>google-oauth-client</artifactId> | ||
| <version>1.22.0</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.google.api-client</groupId> | ||
| <artifactId>google-api-client</artifactId> | ||
| <version>1.22.0</version> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>commons-cli</groupId> | ||
| <artifactId>commons-cli</artifactId> | ||
| <version>1.3</version> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <artifactId>maven-assembly-plugin</artifactId> | ||
| <configuration> | ||
| <archive> | ||
| <manifest> | ||
| <mainClass>com.example.cloudiot.Manage</mainClass> | ||
| </manifest> | ||
| </archive> | ||
| <descriptorRefs> | ||
| <descriptorRef>jar-with-dependencies</descriptorRef> | ||
| </descriptorRefs> | ||
| </configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <metadata> | ||
| <groupId>com.google.apis</groupId> | ||
| <artifactId>google-api-services-cloudiot</artifactId> | ||
| <versioning> | ||
| <versions> | ||
| <version>v1beta1-rev20170418-1.22.0-SNAPSHOT</version> | ||
| </versions> | ||
| <lastUpdated>20170502215244</lastUpdated> | ||
| </versioning> | ||
| </metadata> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <metadata modelVersion="1.1.0"> | ||
| <groupId>com.google.apis</groupId> | ||
| <artifactId>google-api-services-cloudiot</artifactId> | ||
| <version>v1beta1-rev20170418-1.22.0-SNAPSHOT</version> | ||
| <versioning> | ||
| <snapshot> | ||
| <timestamp>20170502.215244</timestamp> | ||
| <buildNumber>1</buildNumber> | ||
| </snapshot> | ||
| <lastUpdated>20170502215244</lastUpdated> | ||
| <snapshotVersions> | ||
| <snapshotVersion> | ||
| <extension>jar</extension> | ||
| <value>v1beta1-rev20170418-1.22.0-20170502.215244-1</value> | ||
| <updated>20170502215244</updated> | ||
| </snapshotVersion> | ||
| <snapshotVersion> | ||
| <extension>pom</extension> | ||
| <value>v1beta1-rev20170418-1.22.0-20170502.215244-1</value> | ||
| <updated>20170502215244</updated> | ||
| </snapshotVersion> | ||
| </snapshotVersions> | ||
| </versioning> | ||
| </metadata> |
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.
s/NodeJS/Java
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.
Done