1
- # Cloud IoT Core Java Command Sample
1
+ # Cloud IoT Core Java Gateway Command Sample
2
2
3
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
4
<img alt =" Open in Cloud Shell " src =" http://gstatic.com/cloudssh/images/open-btn.png " ></a >
5
5
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.
7
8
8
9
Note that before you can run the sample, you must configure a Google Cloud
9
10
PubSub topic for Cloud IoT as described in [ the parent README] ( ../README.md ) .
@@ -16,81 +17,45 @@ the sample every time you run it.
16
17
Run the following command to install the libraries and build the sample with
17
18
Maven:
18
19
19
- mvn clean compile assembly: single
20
+ mvn clean compile assembly:single
20
21
21
22
## Running the sample
22
23
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
59
25
60
- ## Setup
61
-
62
- Run the following command to install the dependencies using Maven:
63
26
64
- mvn clean compile
27
+ mvn exec:java -Dexec.mainClass="com.example.cloud.iot.examples.DeviceGatewayExample"
65
28
66
- ## Running the sample
29
+ The following description summarizes the sample usage:
67
30
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.
0 commit comments