Skip to content

Commit 59a55da

Browse files
committed
Initial commit of sample
1 parent 783a454 commit 59a55da

File tree

17 files changed

+1302
-0
lines changed

17 files changed

+1302
-0
lines changed

iot/api/README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Cloud IoT Core NodeJS Samples
2+
This folder contains NodeJS samples that demonstrate an overview of the
3+
Google Cloud IoT Core platform.
4+
5+
## Quickstart
6+
7+
1. Install the gCloud CLI as described in [the device manager guide](https://cloud-dot-devsite.googleplex.com/iot/docs/device_manager_guide).
8+
2. Create a PubSub topic:
9+
10+
gcloud beta pubsub topics create projects/my-iot-project/topics/device-events
11+
12+
3. Add the special account `[email protected]` to that
13+
PubSub topic from the [Cloud Developer Console](https://console.cloud.google.com)
14+
or by using the helper script in the /scripts folder.
15+
16+
4. Create a registry:
17+
18+
gcloud alpha iot registries create my-registry \
19+
--project=my-iot-project \
20+
--region=us-central1 \
21+
--pubsub-topic=projects/my-iot-project/topics/device-events
22+
23+
5. Use the `generate_keys.sh` script to generate your signing keys:
24+
25+
./generate_keys.sh
26+
27+
6. Create a device.
28+
29+
gcloud alpha iot devices create my-java-device \
30+
--project=my-iot-project \
31+
--region=us-central1 \
32+
--registry=my-registry \
33+
--public-key path=rsa_cert.pem,type=rs256
34+
35+
7. Connect a sample device using the sample app in the `mqtt_example` folder.
36+
8. Learn how to manage devices programatically with the sample app in the
37+
`manager` folder.
38+

iot/api/generate_keys.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# Copyright 2017 Google Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
openssl req -x509 -newkey rsa:2048 -keyout rsa_private.pem -nodes -out \
18+
rsa_cert.pem -subj "/CN=unused"
19+
openssl ecparam -genkey -name prime256v1 -noout -out ec_private.pem
20+
openssl ec -in ec_private.pem -pubout -out ec_public.pem
21+
openssl pkcs8 -topk8 -inform PEM -outform DER -in rsa_private.pem \
22+
-nocrypt > rsa_private_pkcs8
23+
openssl pkcs8 -topk8 -inform PEM -outform DER -in ec_private.pem \
24+
-nocrypt > ec_private_pkcs8

iot/api/manager/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Cloud IoT Core Java Device Management example
2+
3+
This sample app demonstrates device management for Google Cloud IoT Core.
4+
5+
Note that before you can run the sample, you must configure a Google Cloud
6+
PubSub topic for Cloud IoT as described in the parent README.
7+
8+
## Setup
9+
10+
Run the following command to install the libraries and build the sample with
11+
Maven:
12+
13+
mvn clean compile assembly:single
14+
15+
## Running the sample
16+
17+
The following command summarizes the sample usage:
18+
19+
mvn exec:java \
20+
-Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \
21+
-Dexec.args="-project_id=my-project-id \
22+
-pubsub_topic=projects/my-project-id/topics/my-topic-id \
23+
-ec_public_key_file=/path/to/ec_public.pem \
24+
-rsa_certificate_file=/path/to/rsa_cert.pem"
25+
26+
For example, if your project ID is `blue-jet-123`, your service account
27+
credentials are stored in your home folder in creds.json and you have generated
28+
your credentials using the shell script provided in the parent folder, you can
29+
run the sample as:
30+
31+
mvn exec:java \
32+
-Dexec.mainClass="com.google.cloud.iot.examples.DeviceRegistryExample" \
33+
-Dexec.args="-project_id=blue-jet-123 \
34+
-pubsub_topic=projects/blue-jet-123/topics/device-events \
35+
-ec_public_key_file=../ec_public.pem \
36+
-rsa_certificate_file=../rsa_cert.pem"

iot/api/manager/pom.xml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<!--
2+
Copyright 2017 Google Inc.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
17+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
18+
<modelVersion>4.0.0</modelVersion>
19+
<groupId>com.example.cloud</groupId>
20+
<artifactId>cloudiot-manager-demo</artifactId>
21+
<packaging>jar</packaging>
22+
<version>1.0</version>
23+
<name>cloudiot-manager-demo</name>
24+
<url>http://maven.apache.org</url>
25+
26+
<!-- Start local repo -->
27+
<repositories>
28+
<!-- Use a local directory for the Cloud IoT Core API dependency. -->
29+
<repository>
30+
<id>project.local</id>
31+
<name>project</name>
32+
<url>file:./repo</url>
33+
</repository>
34+
</repositories>
35+
<!-- End of extra repo -->
36+
37+
<properties>
38+
<maven.compiler.source>1.7</maven.compiler.source>
39+
<maven.compiler.target>1.7</maven.compiler.target>
40+
</properties>
41+
42+
<dependencies>
43+
<dependency>
44+
<groupId>com.google.apis</groupId>
45+
<artifactId>google-api-services-cloudiot</artifactId>
46+
<version>v1beta1-rev20170418-1.22.0-SNAPSHOT</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>com.google.oauth-client</groupId>
50+
<artifactId>google-oauth-client</artifactId>
51+
<version>1.22.0</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.google.api-client</groupId>
55+
<artifactId>google-api-client</artifactId>
56+
<version>1.22.0</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>commons-cli</groupId>
60+
<artifactId>commons-cli</artifactId>
61+
<version>1.3</version>
62+
</dependency>
63+
</dependencies>
64+
65+
<build>
66+
<plugins>
67+
<plugin>
68+
<artifactId>maven-assembly-plugin</artifactId>
69+
<configuration>
70+
<archive>
71+
<manifest>
72+
<mainClass>com.example.cloudiot.Manage</mainClass>
73+
</manifest>
74+
</archive>
75+
<descriptorRefs>
76+
<descriptorRef>jar-with-dependencies</descriptorRef>
77+
</descriptorRefs>
78+
</configuration>
79+
</plugin>
80+
</plugins>
81+
</build>
82+
</project>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<metadata>
3+
<groupId>com.google.apis</groupId>
4+
<artifactId>google-api-services-cloudiot</artifactId>
5+
<versioning>
6+
<versions>
7+
<version>v1beta1-rev20170418-1.22.0-SNAPSHOT</version>
8+
</versions>
9+
<lastUpdated>20170502215244</lastUpdated>
10+
</versioning>
11+
</metadata>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<metadata modelVersion="1.1.0">
3+
<groupId>com.google.apis</groupId>
4+
<artifactId>google-api-services-cloudiot</artifactId>
5+
<version>v1beta1-rev20170418-1.22.0-SNAPSHOT</version>
6+
<versioning>
7+
<snapshot>
8+
<timestamp>20170502.215244</timestamp>
9+
<buildNumber>1</buildNumber>
10+
</snapshot>
11+
<lastUpdated>20170502215244</lastUpdated>
12+
<snapshotVersions>
13+
<snapshotVersion>
14+
<extension>jar</extension>
15+
<value>v1beta1-rev20170418-1.22.0-20170502.215244-1</value>
16+
<updated>20170502215244</updated>
17+
</snapshotVersion>
18+
<snapshotVersion>
19+
<extension>pom</extension>
20+
<value>v1beta1-rev20170418-1.22.0-20170502.215244-1</value>
21+
<updated>20170502215244</updated>
22+
</snapshotVersion>
23+
</snapshotVersions>
24+
</versioning>
25+
</metadata>

0 commit comments

Comments
 (0)