Skip to content

Commit a1d9d32

Browse files
munkhuushmglgguuss
authored andcommitted
Update Beta samples (GoogleCloudPlatform#1295)
* Updates Beta samples
1 parent 1e7c8d7 commit a1d9d32

17 files changed

+1432
-2348
lines changed
Lines changed: 38 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# Cloud IoT Core Java Command Sample
1+
# Cloud IoT Core Java Gateway Command Sample
22

33
<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">
44
<img alt="Open in Cloud Shell" src ="http://gstatic.com/cloudssh/images/open-btn.png"></a>
55

6-
This sample app demonstrates sending a command to a Cloud IoT Core device.
6+
This sample app demonstrates sending telemetry data on behalf of a device using
7+
a Gateway.
78

89
Note that before you can run the sample, you must configure a Google Cloud
910
PubSub topic for Cloud IoT as described in [the parent README](../README.md).
@@ -16,81 +17,45 @@ the sample every time you run it.
1617
Run the following command to install the libraries and build the sample with
1718
Maven:
1819

19-
mvn clean compile assembly:single
20+
mvn clean compile assembly:single
2021

2122
## Running the sample
2223

23-
The following description summarizes the sample usage:
24-
25-
usage: DeviceRegistryExample [--cloud_region <arg>] --command <arg>
26-
[--data <arg>] [--device_id <arg>] [--project_id <arg>]
27-
[--registry_name <arg>]
28-
Cloud IoT Core Commandline Example (Device / Registry management):
29-
30-
--cloud_region <arg> GCP cloud region.
31-
--command <arg> Command to run:
32-
send-command
33-
--data <arg> The command data (string or JSON) to send to
34-
the specified device.
35-
--device_id <arg> Name for your Device.
36-
--project_id <arg> GCP cloud project name.
37-
--registry_name <arg> Name for your Device Registry.
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-
mvn exec:java \
45-
-Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
46-
-Dexec.args="-project_id=blue-jet-123 \
47-
-registry_name=your-registry-id \
48-
-device_id=your-device-id \
49-
-command=send-command \
50-
-data=hello"
51-
52-
# Cloud IoT Core Java MQTT Command example
53-
54-
This sample app receives commands sent by the command app.
55-
56-
Note that before you can run the sample, you must configure a Google Cloud
57-
PubSub topic for Cloud IoT Core and register a device as described in the
58-
[parent README](../README.md).
24+
The following command will run the sample
5925

60-
## Setup
61-
62-
Run the following command to install the dependencies using Maven:
6326

64-
mvn clean compile
27+
mvn exec:java -Dexec.mainClass="com.example.cloud.iot.examples.DeviceGatewayExample"
6528

66-
## Running the sample
29+
The following description summarizes the sample usage:
6730

68-
The following command summarizes the sample usage:
69-
70-
usage: DeviceRegistryExample [--cloud_region <arg>] --command <arg>
71-
[--command_data <arg>] [--device_id <arg>] [--project_id <arg>]
72-
[--registry_name <arg>]
73-
Cloud IoT Core Commandline Example (Device / Registry management):
74-
75-
--cloud_region <arg> GCP cloud region.
76-
--command <arg> Command to run:
77-
send-command
78-
--command_data <arg> The command data (string or JSON) to send to
79-
the specified device.
80-
--device_id <arg> Name for your Device.
81-
--project_id <arg> GCP cloud project name.
82-
--registry_name <arg> Name for your Device Registry.
83-
84-
For example, if your project ID is `blue-jet-123`, your device registry is
85-
located in the `asia-east1` region, and you have generated your
86-
credentials using the [`generate_keys.sh`](../generate_keys.sh) script
87-
provided in the parent folder, you can run the sample as:
88-
89-
mvn exec:java \
90-
-Dexec.mainClass="com.example.cloud.iot.examples.MqttExample" \
91-
-Dexec.args="-project_id=blue-jet-123 \
92-
-registry_id=my-registry \
93-
-cloud_region=asia-east1 \
94-
-device_id=my-device \
95-
-private_key_file=../rsa_private_pkcs8 \
96-
-algorithm=RS256"
31+
usage: DeviceGatewayExample [--cloud_region <arg>] --command <arg>
32+
[--device_id <arg>] [--project_id <arg>] [--registry_name <arg>]
33+
[--telemetry_data <arg>]
34+
Cloud IoT Core Commandline Example (Device Gateways):
35+
36+
--cloud_region <arg> GCP cloud region.
37+
--command <arg> Command to run:
38+
send-delegate-telemetry
39+
--device_id <arg> Name for the delegate device.
40+
--project_id <arg> GCP cloud project name.
41+
--registry_name <arg> Name for your Device Registry.
42+
--telemetry_data <arg> The telemetry data (string or JSON) to send
43+
on behalf of the delegated device.
44+
45+
https://cloud.google.com/iot-core
46+
47+
The following example shows using the sample to send the telemetry data `hello`
48+
on behalf of the device `some-device-id`:
49+
50+
mvn exec:java -Dexec.mainClass="com.example.cloud.iot.examples.DeviceGatewayExample" \
51+
-Dexec.args="-cloud_region=us-central1 \
52+
-project_id=blue-jet-123 \
53+
-command=send-delegate-telemetry \
54+
-device_id=your-device-id \
55+
-telemetry_data=hello \
56+
-device_id=some-device-id \
57+
-registry_name=my-registry"
58+
59+
## Troubleshooting
60+
Make sure to bind your device before trying to attach it. If your device is not
61+
bound to the gateway, the call to attach the device will not return.

iot/api-client/beta-features/manager/pom.xml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
Copyright 2018 Google LLC
2+
Copyright 2018 Google Inc.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -33,12 +33,6 @@
3333
<version>1.0.8</version>
3434
</parent>
3535
<repositories>
36-
<!-- Use a local directory for the Text API dependency. -->
37-
<repository>
38-
<id>project.local</id>
39-
<name>project</name>
40-
<url>file:${project.basedir}/./repo</url>
41-
</repository>
4236
</repositories>
4337
<properties>
4438
<maven.compiler.target>1.8</maven.compiler.target>
@@ -66,11 +60,13 @@
6660
<artifactId>joda-time</artifactId>
6761
<version>2.1</version>
6862
</dependency>
63+
6964
<dependency>
7065
<groupId>com.google.apis</groupId>
7166
<artifactId>google-api-services-cloudiot</artifactId>
72-
<version>v1-rev49-1.25.0</version>
67+
<version>v1-rev20181120-1.27.0</version>
7368
</dependency>
69+
7470
<dependency>
7571
<groupId>com.google.cloud</groupId>
7672
<artifactId>google-cloud-pubsub</artifactId>
@@ -79,7 +75,7 @@
7975
<dependency>
8076
<groupId>com.google.oauth-client</groupId>
8177
<artifactId>google-oauth-client</artifactId>
82-
<version>1.22.0</version>
78+
<version>1.23.0</version>
8379
</dependency>
8480
<dependency>
8581
<groupId>com.google.guava</groupId>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-----BEGIN EC PRIVATE KEY-----
2+
MHcCAQEEIK9PAsoXug32KzMJiah9Nuy9yNZJdpDYfIeUt3olsRZ9oAoGCCqGSM49
3+
AwEHoUQDQgAES+slfwEIqd6EqRy5sDtFJXzW+D+i5tDWD5EVFA0loXkisKpgEvww
4+
fCx6xwSNatAevzpmFFqsvp6ouEop7RqRLw==
5+
-----END EC PRIVATE KEY-----
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
-----BEGIN PUBLIC KEY-----
2-
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEJ/zj75PhGtoayWD9pm/IbXRXi9ai
3-
RQDMFQ87sOOQIWDTxnsHFplqb8cDCtO1h5QsutcAVTPZL0CZiqIg5j7b1w==
2+
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAES+slfwEIqd6EqRy5sDtFJXzW+D+i
3+
5tDWD5EVFA0loXkisKpgEvwwfCx6xwSNatAevzpmFFqsvp6ouEop7RqRLw==
44
-----END PUBLIC KEY-----

0 commit comments

Comments
 (0)