@@ -87,6 +87,12 @@ def create_rs256_device(
87
87
"""Create a new device with the given id, using RS256 for
88
88
authentication."""
89
89
# [START iot_create_rsa_device]
90
+ # project_id = 'YOUR_PROJECT_ID'
91
+ # cloud_region = 'us-central1'
92
+ # registry_id = 'your-registry-id'
93
+ # device_id = 'your-device-id'
94
+ # certificate_file = 'path/to/certificate.pem'
95
+
90
96
client = iot_v1 .DeviceManagerClient ()
91
97
92
98
parent = client .registry_path (project_id , cloud_region , registry_id )
@@ -115,6 +121,12 @@ def create_es256_device(
115
121
"""Create a new device with the given id, using ES256 for
116
122
authentication."""
117
123
# [START iot_create_es_device]
124
+ # project_id = 'YOUR_PROJECT_ID'
125
+ # cloud_region = 'us-central1'
126
+ # registry_id = 'your-registry-id'
127
+ # device_id = 'your-device-id'
128
+ # public_key_file = 'path/to/certificate.pem'
129
+
118
130
client = iot_v1 .DeviceManagerClient ()
119
131
120
132
parent = client .registry_path (project_id , cloud_region , registry_id )
@@ -142,6 +154,11 @@ def create_device(
142
154
device_id ):
143
155
"""Create a device to bind to a gateway if it does not exist."""
144
156
# [START iot_create_device]
157
+ # project_id = 'YOUR_PROJECT_ID'
158
+ # cloud_region = 'us-central1'
159
+ # registry_id = 'your-registry-id'
160
+ # device_id = 'your-device-id'
161
+
145
162
# Check that the device doesn't already exist
146
163
client = iot_v1 .DeviceManagerClient ()
147
164
@@ -177,6 +194,10 @@ def create_unauth_device(
177
194
device_id ):
178
195
"""Create a new device without authentication."""
179
196
# [START iot_create_unauth_device]
197
+ # project_id = 'YOUR_PROJECT_ID'
198
+ # cloud_region = 'us-central1'
199
+ # registry_id = 'your-registry-id'
200
+ # device_id = 'your-device-id'
180
201
client = iot_v1 .DeviceManagerClient ()
181
202
182
203
parent = client .registry_path (project_id , cloud_region , registry_id )
@@ -194,6 +215,10 @@ def delete_device(
194
215
device_id ):
195
216
"""Delete the device with the given id."""
196
217
# [START iot_delete_device]
218
+ # project_id = 'YOUR_PROJECT_ID'
219
+ # cloud_region = 'us-central1'
220
+ # registry_id = 'your-registry-id'
221
+ # device_id = 'your-device-id'
197
222
print ('Delete device' )
198
223
client = iot_v1 .DeviceManagerClient ()
199
224
@@ -208,6 +233,9 @@ def delete_registry(
208
233
service_account_json , project_id , cloud_region , registry_id ):
209
234
"""Deletes the specified registry."""
210
235
# [START iot_delete_registry]
236
+ # project_id = 'YOUR_PROJECT_ID'
237
+ # cloud_region = 'us-central1'
238
+ # registry_id = 'your-registry-id'
211
239
print ('Delete registry' )
212
240
213
241
client = iot_v1 .DeviceManagerClient ()
@@ -228,6 +256,10 @@ def get_device(
228
256
device_id ):
229
257
"""Retrieve the device with the given id."""
230
258
# [START iot_get_device]
259
+ # project_id = 'YOUR_PROJECT_ID'
260
+ # cloud_region = 'us-central1'
261
+ # registry_id = 'your-registry-id'
262
+ # device_id = 'your-device-id'
231
263
print ('Getting device' )
232
264
client = iot_v1 .DeviceManagerClient ()
233
265
device_path = client .device_path (
@@ -271,6 +303,10 @@ def get_state(
271
303
device_id ):
272
304
"""Retrieve a device's state blobs."""
273
305
# [START iot_get_device_state]
306
+ # project_id = 'YOUR_PROJECT_ID'
307
+ # cloud_region = 'us-central1'
308
+ # registry_id = 'your-registry-id'
309
+ # device_id = 'your-device-id'
274
310
client = iot_v1 .DeviceManagerClient ()
275
311
device_path = client .device_path (
276
312
project_id , cloud_region , registry_id , device_id )
@@ -291,6 +327,9 @@ def list_devices(
291
327
service_account_json , project_id , cloud_region , registry_id ):
292
328
"""List all devices in the registry."""
293
329
# [START iot_list_devices]
330
+ # project_id = 'YOUR_PROJECT_ID'
331
+ # cloud_region = 'us-central1'
332
+ # registry_id = 'your-registry-id'
294
333
print ('Listing devices' )
295
334
296
335
client = iot_v1 .DeviceManagerClient ()
@@ -307,6 +346,8 @@ def list_devices(
307
346
def list_registries (service_account_json , project_id , cloud_region ):
308
347
"""List all registries in the project."""
309
348
# [START iot_list_registries]
349
+ # project_id = 'YOUR_PROJECT_ID'
350
+ # cloud_region = 'us-central1'
310
351
print ('Listing Registries' )
311
352
client = iot_v1 .DeviceManagerClient ()
312
353
parent = client .location_path (project_id , cloud_region )
@@ -327,6 +368,10 @@ def create_registry(
327
368
""" Creates a registry and returns the result. Returns an empty result if
328
369
the registry already exists."""
329
370
# [START iot_create_registry]
371
+ # project_id = 'YOUR_PROJECT_ID'
372
+ # cloud_region = 'us-central1'
373
+ # pubsub_topic = 'your-pubsub-topic'
374
+ # registry_id = 'your-registry-id'
330
375
client = iot_v1 .DeviceManagerClient ()
331
376
parent = client .location_path (project_id , cloud_region )
332
377
@@ -357,6 +402,9 @@ def get_registry(
357
402
service_account_json , project_id , cloud_region , registry_id ):
358
403
""" Retrieves a device registry."""
359
404
# [START iot_get_registry]
405
+ # project_id = 'YOUR_PROJECT_ID'
406
+ # cloud_region = 'us-central1'
407
+ # registry_id = 'your-registry-id'
360
408
client = iot_v1 .DeviceManagerClient ()
361
409
registry_path = client .registry_path (project_id , cloud_region , registry_id )
362
410
@@ -368,6 +416,10 @@ def open_registry(
368
416
service_account_json , project_id , cloud_region , pubsub_topic ,
369
417
registry_id ):
370
418
"""Gets or creates a device registry."""
419
+ # project_id = 'YOUR_PROJECT_ID'
420
+ # cloud_region = 'us-central1'
421
+ # pubsub_topic = 'your-pubsub-topic'
422
+ # registry_id = 'your-registry-id'
371
423
print ('Creating registry' )
372
424
373
425
response = create_registry (
@@ -392,6 +444,11 @@ def patch_es256_auth(
392
444
device_id , public_key_file ):
393
445
"""Patch the device to add an ES256 public key to the device."""
394
446
# [START iot_patch_es]
447
+ # project_id = 'YOUR_PROJECT_ID'
448
+ # cloud_region = 'us-central1'
449
+ # registry_id = 'your-registry-id'
450
+ # device_id = 'your-device-id'
451
+ # public_key_file = 'path/to/certificate.pem'
395
452
print ('Patch device with ES256 certificate' )
396
453
397
454
client = iot_v1 .DeviceManagerClient ()
@@ -427,6 +484,11 @@ def patch_rsa256_auth(
427
484
public_key_file ):
428
485
"""Patch the device to add an RSA256 public key to the device."""
429
486
# [START iot_patch_rsa]
487
+ # project_id = 'YOUR_PROJECT_ID'
488
+ # cloud_region = 'us-central1'
489
+ # registry_id = 'your-registry-id'
490
+ # device_id = 'your-device-id'
491
+ # public_key_file = 'path/to/certificate.pem'
430
492
print ('Patch device with RSA256 certificate' )
431
493
432
494
client = iot_v1 .DeviceManagerClient ()
@@ -462,6 +524,12 @@ def set_config(
462
524
service_account_json , project_id , cloud_region , registry_id , device_id ,
463
525
version , config ):
464
526
# [START iot_set_device_config]
527
+ # project_id = 'YOUR_PROJECT_ID'
528
+ # cloud_region = 'us-central1'
529
+ # registry_id = 'your-registry-id'
530
+ # device_id = 'your-device-id'
531
+ # version = '0'
532
+ # config= 'your-config-data'
465
533
print ('Set device configuration' )
466
534
client = iot_v1 .DeviceManagerClient ()
467
535
device_path = client .device_path (
@@ -478,6 +546,10 @@ def get_config_versions(
478
546
device_id ):
479
547
"""Lists versions of a device config in descending order (newest first)."""
480
548
# [START iot_get_device_configs]
549
+ # project_id = 'YOUR_PROJECT_ID'
550
+ # cloud_region = 'us-central1'
551
+ # registry_id = 'your-registry-id'
552
+ # device_id = 'your-device-id'
481
553
client = iot_v1 .DeviceManagerClient ()
482
554
device_path = client .device_path (
483
555
project_id , cloud_region , registry_id , device_id )
@@ -498,6 +570,9 @@ def get_iam_permissions(
498
570
service_account_json , project_id , cloud_region , registry_id ):
499
571
"""Retrieves IAM permissions for the given registry."""
500
572
# [START iot_get_iam_policy]
573
+ # project_id = 'YOUR_PROJECT_ID'
574
+ # cloud_region = 'us-central1'
575
+ # registry_id = 'your-registry-id'
501
576
client = iot_v1 .DeviceManagerClient ()
502
577
503
578
registry_path = client .registry_path (project_id , cloud_region , registry_id )
@@ -513,6 +588,11 @@ def set_iam_permissions(
513
588
member ):
514
589
"""Sets IAM permissions for the given registry to a single role/member."""
515
590
# [START iot_set_iam_policy]
591
+ # project_id = 'YOUR_PROJECT_ID'
592
+ # cloud_region = 'us-central1'
593
+ # registry_id = 'your-registry-id'
594
+ # role = 'viewer'
595
+ # member = 'group:[email protected] '
516
596
client = iot_v1 .DeviceManagerClient ()
517
597
registry_path = client .registry_path (project_id , cloud_region , registry_id )
518
598
@@ -549,6 +629,13 @@ def create_gateway(
549
629
gateway_id , certificate_file , algorithm ):
550
630
"""Create a gateway to bind devices to."""
551
631
# [START iot_create_gateway]
632
+ # project_id = 'YOUR_PROJECT_ID'
633
+ # cloud_region = 'us-central1'
634
+ # registry_id = 'your-registry-id'
635
+ # device_id = 'your-device-id'
636
+ # gateway_id = 'your-gateway-id'
637
+ # certificate_file = 'path/to/certificate.pem'
638
+ # algorithm = 'ES256'
552
639
# Check that the gateway doesn't already exist
553
640
exists = False
554
641
client = iot_v1 .DeviceManagerClient ()
@@ -602,6 +689,11 @@ def bind_device_to_gateway(
602
689
gateway_id ):
603
690
"""Binds a device to a gateway."""
604
691
# [START iot_bind_device_to_gateway]
692
+ # project_id = 'YOUR_PROJECT_ID'
693
+ # cloud_region = 'us-central1'
694
+ # registry_id = 'your-registry-id'
695
+ # device_id = 'your-device-id'
696
+ # gateway_id = 'your-gateway-id'
605
697
client = iot_v1 .DeviceManagerClient ()
606
698
607
699
create_device (
@@ -621,6 +713,11 @@ def unbind_device_from_gateway(
621
713
gateway_id ):
622
714
"""Unbinds a device to a gateway."""
623
715
# [START iot_unbind_device_from_gateway]
716
+ # project_id = 'YOUR_PROJECT_ID'
717
+ # cloud_region = 'us-central1'
718
+ # registry_id = 'your-registry-id'
719
+ # device_id = 'your-device-id'
720
+ # gateway_id = 'your-gateway-id'
624
721
client = iot_v1 .DeviceManagerClient ()
625
722
626
723
parent = client .registry_path (project_id , cloud_region , registry_id )
@@ -635,6 +732,9 @@ def list_gateways(
635
732
service_account_json , project_id , cloud_region , registry_id ):
636
733
"""Lists gateways in a registry"""
637
734
# [START iot_list_gateways]
735
+ # project_id = 'YOUR_PROJECT_ID'
736
+ # cloud_region = 'us-central1'
737
+ # registry_id = 'your-registry-id'
638
738
client = iot_v1 .DeviceManagerClient ()
639
739
640
740
path = client .registry_path (project_id , cloud_region , registry_id )
@@ -655,6 +755,10 @@ def list_devices_for_gateway(
655
755
gateway_id ):
656
756
"""List devices bound to a gateway"""
657
757
# [START iot_list_devices_for_gateway]
758
+ # project_id = 'YOUR_PROJECT_ID'
759
+ # cloud_region = 'us-central1'
760
+ # registry_id = 'your-registry-id'
761
+ # gateway_id = 'your-gateway-id'
658
762
client = iot_v1 .DeviceManagerClient ()
659
763
660
764
path = client .registry_path (project_id , cloud_region , registry_id )
0 commit comments