@@ -8,6 +8,10 @@ This sample app demonstrates device management for Google Cloud IoT Core.
8
8
Note that before you can run the sample, you must configure a Google Cloud
9
9
PubSub topic for Cloud IoT as described in [ the parent README] ( ../README.md ) .
10
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
+
11
15
## Setup
12
16
Run the following command to install the libraries and build the sample with
13
17
Maven:
@@ -24,7 +28,7 @@ The following description summarizes the sample usage:
24
28
25
29
Cloud IoT Core Commandline Example (Device / Registry management):
26
30
27
- --cloud_region <arg> GCP cloud region.
31
+ --cloud_region <arg> GCP cloud region (default us-central1) .
28
32
--command <arg> Command to run:
29
33
create-iot-topic
30
34
create-rsa
@@ -58,85 +62,109 @@ run the sample as:
58
62
Create a PubSub topic, ` hello-java ` , for the project, ` blue-jet-123 ` :
59
63
60
64
mvn exec:java \
61
- -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
62
- -Dexec.args="-project_id=blue-jet-123 \
63
- -command=create-iot-topic \
64
- -pubsub_topic=hello-java "
65
+ -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
66
+ -Dexec.args="-project_id=blue-jet-123 \
67
+ -command=create-iot-topic \
68
+ -pubsub_topic=hello-java"
65
69
66
70
Create an ES device:
67
71
68
- java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
69
- com.example.cloud.iot.examples.DeviceRegistryExample \
70
- -project_id=blue-jet-123 -pubsub_topic=hello-java \
71
- -registry_name=hello-java -ec_public_key_file ../ec_public.pem \
72
- -device_id="java-device-0" -command=create-es
72
+ mvn exec:java \
73
+ -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
74
+ -Dexec.args="-project_id=blue-jet-123 \
75
+ -pubsub_topic=hello-java \
76
+ -cloud_region=us-central1 \
77
+ -registry_name=hello-java \
78
+ -ec_public_key_file ../ec_public.pem \
79
+ -device_id=java-device-0 \
80
+ -command=create-es"
73
81
74
82
Create an RSA device:
75
83
76
- java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
77
- com.example.cloud.iot.examples.DeviceRegistryExample \
78
- -project_id=blue-jet-123 -pubsub_topic=hello-java \
79
- -registry_name=hello-java -rsa_certificate_file ../rsa_cert.pem \
80
- -device_id="java-device-1" -command=create-rsa
84
+ mvn exec:java \
85
+ -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
86
+ -Dexec.args="-project_id=blue-jet-123 \
87
+ -pubsub_topic=hello-java \
88
+ -registry_name=hello-java \
89
+ -rsa_certificate_file ../rsa_cert.pem \
90
+ -device_id=java-device-1 \
91
+ -command=create-rsa"
81
92
82
93
Create a device without authorization:
83
94
84
- java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
85
- com.example.cloud.iot.examples.DeviceRegistryExample \
86
- -project_id=blue-jet-123 -pubsub_topic=hello-java \
87
- -registry_name=hello-java -device_id="java-device-3" \
88
- -command=create-unauth
95
+ mvn exec:java \
96
+ -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
97
+ -Dexec.args="-project_id=blue-jet-123 \
98
+ -pubsub_topic=hello-java \
99
+ -registry_name=hello-java \
100
+ -device_id=java-device-3 \
101
+ -command=create-unauth"
89
102
90
103
Create a device registry:
91
104
92
- java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
93
- com.example.cloud.iot.examples.DeviceRegistryExample \
94
- -project_id=blue-jet-123 -pubsub_topic=hello-java \
95
- -registry_name=hello-java -command=create-registry
105
+ mvn exec:java \
106
+ -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
107
+ -Dexec.args="-project_id=blue-jet-123 \
108
+ -pubsub_topic=hello-java \
109
+ -registry_name=hello-java \
110
+ -command=create-registry"
96
111
97
112
Delete a device registry:
98
113
99
- java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
100
- com.example.cloud.iot.examples.DeviceRegistryExample \
101
- -project_id=blue-jet-123 -pubsub_topic=hello-java \
102
- -registry_name=hello-java -command=delete-registry
114
+ mvn exec:java \
115
+ -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
116
+ -Dexec.args="-project_id=blue-jet-123 \
117
+ -pubsub_topic=hello-java \
118
+ -registry_name=hello-java \
119
+ -command=delete-registry"
103
120
104
121
Get a device registry:
105
122
106
- java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
107
- com.example.cloud.iot.examples.DeviceRegistryExample \
108
- -project_id=blue-jet-123 -pubsub_topic=hello-java \
109
- -registry_name=hello-java -command=get-registry
123
+ mvn exec:java \
124
+ -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
125
+ -Dexec.args="-project_id=blue-jet-123 \
126
+ -pubsub_topic=hello-java \
127
+ -registry_name=hello-java \
128
+ -command=get-registry"
110
129
111
130
List devices:
112
131
113
- java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
114
- com.example.cloud.iot.examples.DeviceRegistryExample \
115
- -project_id=blue-jet-123 -pubsub_topic=hello-java \
116
- -registry_name=hello-java -command=list-devices
132
+ mvn exec:java \
133
+ -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
134
+ -Dexec.args="-project_id=blue-jet-123 \
135
+ -pubsub_topic=hello-java \
136
+ -registry_name=hello-java \
137
+ -command=list-devices"
117
138
118
139
List device registries:
119
140
120
- java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
121
- com.example.cloud.iot.examples.DeviceRegistryExample \
122
- -project_id=blue-jet-123 -pubsub_topic=hello-java \
123
- -registry_name=hello-java -command=list-registries
141
+ mvn exec:java \
142
+ -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
143
+ -Dexec.args="-project_id=blue-jet-123 \
144
+ -pubsub_topic=hello-java \
145
+ -registry_name=hello-java \
146
+ -command=list-registries"
124
147
125
148
Patch a device with ES:
126
149
127
- java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
128
- com.example.cloud.iot.examples.DeviceRegistryExample \
129
- -project_id=blue-jet-123 -pubsub_topic=hello-java \
130
- -registry_name=hello-java -ec_public_key_file ../ec_public.pem \
131
- -device_id="java-device-1" -command=patch-device-es
150
+ mvn exec:java \
151
+ -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
152
+ -Dexec.args="-project_id=blue-jet-123 \
153
+ -pubsub_topic=hello-java \
154
+ -registry_name=hello-java \
155
+ -ec_public_key_file ../ec_public.pem \
156
+ -device_id=java-device-1 -command=patch-device-es"
132
157
133
158
Patch a device with RSA:
134
159
135
- java -cp target/cloudiot-manager-demo-1.0-jar-with-dependencies.jar \
136
- com.example.cloud.iot.examples.DeviceRegistryExample \
137
- -project_id=blue-jet-123 -pubsub_topic=hello-java \
138
- -registry_name=hello-java -rsa_certificate_file ../rsa_cert.pem \
139
- -device_id="java-device-0" -command=patch-device-rsa
160
+ mvn exec:java \
161
+ -Dexec.mainClass="com.example.cloud.iot.examples.DeviceRegistryExample" \
162
+ -Dexec.args="-project_id=blue-jet-123 \
163
+ -pubsub_topic=hello-java \
164
+ -registry_name=hello-java \
165
+ -rsa_certificate_file ../rsa_cert.pem \
166
+ -device_id=java-device-0 \
167
+ -command=patch-device-rsa"
140
168
141
169
142
170
# Cloud IoT Core Java HTTP example
@@ -169,16 +197,17 @@ The following command summarizes the sample usage:
169
197
-algorithm=<RS256|ES256>"
170
198
```
171
199
172
- For example, if your project ID is ` blue-jet-123 ` , your service account
173
- credentials are stored in your home folder in creds.json and you have generated
174
- your credentials using the [ ` generate_keys.sh ` ] ( ../generate_keys.sh ) script
200
+ For example, if your project ID is ` blue-jet-123 ` , the Cloud region associated
201
+ with your device registry is europe-west1, and you have generated your
202
+ credentials using the [ ` generate_keys.sh ` ] ( ../generate_keys.sh ) script
175
203
provided in the parent folder, you can run the sample as:
176
204
177
205
```
178
206
mvn exec:java \
179
207
-Dexec.mainClass="com.example.cloud.iot.examples.HttpExample" \
180
208
-Dexec.args="-project_id=blue-jet-123 \
181
209
-registry_id=my-registry \
210
+ -cloud_region=europe-west1 \
182
211
-device_id=my-java-device \
183
212
-private_key_file=../rsa_private_pkcs8 \
184
213
-algorithm=RS256"
@@ -191,6 +220,7 @@ To publish state messages, run the sample as follows:
191
220
-Dexec.mainClass="com.example.cloud.iot.examples.HttpExample" \
192
221
-Dexec.args="-project_id=blue-jet-123 \
193
222
-registry_id=my-registry \
223
+ -cloud_region=us-central1 \
194
224
-device_id=my-java-device \
195
225
-private_key_file=../rsa_private_pkcs8 \
196
226
-message_type=state \
@@ -238,19 +268,21 @@ The following command summarizes the sample usage:
238
268
-Dexec.mainClass="com.example.cloud.iot.examples.MqttExample" \
239
269
-Dexec.args="-project_id=my-iot-project \
240
270
-registry_id=my-registry \
271
+ -cloud_region=us-central1 \
241
272
-device_id=my-device \
242
273
-private_key_file=rsa_private_pkcs8 \
243
274
-algorithm=RS256"
244
275
245
- For example, if your project ID is ` blue-jet-123 ` , your service account
246
- credentials are stored in your home folder in creds.json and you have generated
247
- your credentials using the [ ` generate_keys.sh ` ] ( ../generate_keys.sh ) script
276
+ For example, if your project ID is ` blue-jet-123 ` , your device registry is
277
+ located in the ` asia-east1 ` region, and you have generated your
278
+ credentials using the [ ` generate_keys.sh ` ] ( ../generate_keys.sh ) script
248
279
provided in the parent folder, you can run the sample as:
249
280
250
281
mvn exec:java \
251
282
-Dexec.mainClass="com.example.cloud.iot.examples.MqttExample" \
252
283
-Dexec.args="-project_id=blue-jet-123 \
253
284
-registry_id=my-registry \
285
+ -cloud_region=asia-east1 \
254
286
-device_id=my-device \
255
287
-private_key_file=../rsa_private_pkcs8 \
256
288
-algorithm=RS256"
0 commit comments