Skip to content

Commit db73e1e

Browse files
authored
codelab initial push (GoogleCloudPlatform#1354)
* codelab initial push * Update iot/api-client/codelab/README.md Co-Authored-By: munkhuushmgl <45373284+munkhuushmgl@users.noreply.github.com> * Update iot/api-client/codelab/manager/README.md Co-Authored-By: munkhuushmgl <45373284+munkhuushmgl@users.noreply.github.com> * fixed nits * 2019 added
1 parent 3466297 commit db73e1e

File tree

8 files changed

+1177
-0
lines changed

8 files changed

+1177
-0
lines changed

iot/api-client/codelab/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Java Codelabs
2+
3+
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=iot/api-client/manager/README.md">
4+
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
5+
6+
This folder contains Java samples that demonstrate an overview of the
7+
Google Cloud IoT Core platform.
8+
9+
## Quickstart
10+
11+
1. From the [Google Cloud IoT Core section](https://console.cloud.google.com/iot/)
12+
of the Google Cloud console, create a device registry.
13+
2. Use the [`generate_keys.sh`](generate_keys.sh) script to generate your signing keys:
14+
15+
./generate_keys.sh
16+
17+
3. Add a device using the file `rsa_cert.pem`, specifying RS256_X509 and using the
18+
text copy of the public key starting with the ----START---- block of the certificate.
19+
20+
cat rsa_cert.pem
21+
22+
4. Connect a device using the HTTP or MQTT device samples in the [manager](./manager) folder.
23+
24+
5. Programmattically control device configuration and using the device manager sample in the [manager](./manager) folder.
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Cloud IoT Core Commands Java Codelab
2+
3+
<a href="https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/java-docs-samples&page=editor&open_in_editor=iot/api-client/manager/README.md">
4+
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
5+
6+
This sample app demonstrates device management for Google Cloud IoT Core.
7+
8+
Note that before you can run the sample, you must configure a Google Cloud
9+
PubSub topic for Cloud IoT as described in [the parent README](../README.md).
10+
11+
Before running the samples, you can set the `GOOGLE_CLOUD_PROJECT` and
12+
`GOOGLE_APPLICATION_CREDENTIALS` environment variables to avoid passing them to
13+
the sample every time you run it.
14+
15+
## Setup
16+
Run the following command to install the libraries and build the sample with
17+
Maven:
18+
19+
mvn clean compile assembly:single
20+
21+
## Running the sample
22+
23+
The following description summarizes the sample usage:
24+
25+
usage: MqttCommandsDemo [--cloud_region <arg>] --project_id <arg>
26+
--registry_id <arg> --device_id <arg>
27+
28+
Cloud IoT Core Commandline Example (MQTT Device / Commands codelab):
29+
30+
--cloud_region <arg> GCP cloud region (default us-central1).
31+
--private_key_file <arg> Path to RS256 private key file.
32+
--algorithm <arg> Encryption algorithm to use to generate the JWT.
33+
--project_id <arg> GCP cloud project name.
34+
--registry_id <arg> Name for your Device Registry.
35+
--device_id <arg> ID for your Device.
36+
37+
https://cloud.google.com/iot-core
38+
39+
For example, if your project ID is `blue-jet-123`, your service account
40+
credentials are stored in your home folder in creds.json and you have generated
41+
your credentials using the shell script provided in the parent folder, you can
42+
run the sample as:
43+
44+
# Cloud IoT Core Java MQTT example
45+
46+
This sample app publishes data to Cloud Pub/Sub using the MQTT bridge provided
47+
as part of Google Cloud IoT Core.
48+
49+
Note that before you can run the sample, you must configure a Google Cloud
50+
PubSub topic for Cloud IoT Core and register a device as described in the
51+
[parent README](../README.md).
52+
53+
## Setup
54+
55+
Run the following command to install the dependencies using Maven:
56+
57+
mvn clean compile
58+
59+
## Running the sample
60+
61+
The following command summarizes the sample usage:
62+
63+
mvn exec:java \
64+
-Dexec.mainClass="com.example.cloud.iot.examples.MqttCommandsDemo" \
65+
-Dexec.args="-project_id=my-iot-project \
66+
-registry_id=my-registry \
67+
-cloud_region=us-central1 \
68+
-device_id=my-device \
69+
-private_key_file=rsa_private_pkcs8 \
70+
-algorithm=RS256"
71+
72+
Run mqtt example:
73+
74+
mvn exec:java \
75+
-Dexec.mainClass="com.example.cloud.iot.examples.MqttCommandsDemo" \
76+
-Dexec.args="-project_id=blue-jet-123 \
77+
-registry_id=my-registry \
78+
-cloud_region=asia-east1 \
79+
-device_id=my-device \
80+
-private_key_file=../rsa_private_pkcs8 \
81+
-algorithm=RS256"
82+
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<!--
2+
Copyright 2019 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+
<!--
27+
The parent pom defines common style checks and testing strategies for our samples.
28+
Removing or replacing it should not affect the execution of the samples in anyway.
29+
-->
30+
<parent>
31+
<groupId>com.google.cloud.samples</groupId>
32+
<artifactId>shared-configuration</artifactId>
33+
<version>1.0.9</version>
34+
</parent>
35+
<properties>
36+
<maven.compiler.target>1.8</maven.compiler.target>
37+
<maven.compiler.source>1.8</maven.compiler.source>
38+
</properties>
39+
40+
<dependencies>
41+
<dependency>
42+
<groupId>com.googlecode.lanterna</groupId>
43+
<artifactId>lanterna</artifactId>
44+
<version>3.0.1</version>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.eclipse.paho</groupId>
49+
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
50+
<version>1.2.0</version>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.json</groupId>
54+
<artifactId>json</artifactId>
55+
<version>20090211</version>
56+
</dependency>
57+
<dependency>
58+
<groupId>io.jsonwebtoken</groupId>
59+
<artifactId>jjwt</artifactId>
60+
<version>0.7.0</version>
61+
</dependency>
62+
<dependency>
63+
<groupId>joda-time</groupId>
64+
<artifactId>joda-time</artifactId>
65+
<version>2.1</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>com.google.apis</groupId>
69+
<artifactId>google-api-services-cloudiot</artifactId>
70+
<version>v1-rev20181120-1.27.0</version>
71+
</dependency>
72+
<dependency>
73+
<groupId>com.google.cloud</groupId>
74+
<artifactId>google-cloud-pubsub</artifactId>
75+
<version>0.24.0-beta</version>
76+
</dependency>
77+
<dependency>
78+
<groupId>com.google.oauth-client</groupId>
79+
<artifactId>google-oauth-client</artifactId>
80+
<version>1.23.0</version>
81+
</dependency>
82+
<dependency>
83+
<groupId>com.google.guava</groupId>
84+
<artifactId>guava</artifactId>
85+
<version>23.0</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>com.google.api-client</groupId>
89+
<artifactId>google-api-client</artifactId>
90+
<version>1.23.0</version>
91+
</dependency>
92+
<dependency>
93+
<groupId>commons-cli</groupId>
94+
<artifactId>commons-cli</artifactId>
95+
<version>1.3</version>
96+
</dependency>
97+
98+
<!-- Test dependencies -->
99+
<dependency>
100+
<groupId>junit</groupId>
101+
<artifactId>junit</artifactId>
102+
<version>4.12</version>
103+
<scope>test</scope>
104+
</dependency>
105+
<dependency>
106+
<groupId>com.google.truth</groupId>
107+
<artifactId>truth</artifactId>
108+
<version>0.34</version>
109+
<scope>test</scope>
110+
</dependency>
111+
</dependencies>
112+
113+
<build>
114+
<plugins>
115+
<plugin>
116+
<artifactId>maven-assembly-plugin</artifactId>
117+
<configuration>
118+
<archive>
119+
<manifest>
120+
<mainClass>com.example.cloudiot.Manage</mainClass>
121+
</manifest>
122+
</archive>
123+
<descriptorRefs>
124+
<descriptorRef>jar-with-dependencies</descriptorRef>
125+
</descriptorRefs>
126+
</configuration>
127+
</plugin>
128+
</plugins>
129+
</build>
130+
</project>

0 commit comments

Comments
 (0)