1818 * Lists the registries for the configured project and region.
1919 */
2020function listRegistries ( ) {
21- console . log ( response ) ;
22- var projectId = 'your-project-id' ;
23- var cloudRegion = 'us-central1' ;
24- var parent = 'projects/' + projectId + '/locations/' + cloudRegion ;
21+ const projectId = 'your-project-id' ;
22+ const cloudRegion = 'us-central1' ;
23+ const parent = 'projects/' + projectId + '/locations/' + cloudRegion ;
2524
26- var response = CloudIoT . Projects . Locations . Registries . list ( parent ) ;
25+ const response = CloudIoT . Projects . Locations . Registries . list ( parent ) ;
26+ console . log ( response ) ;
2727 if ( response . deviceRegistries ) {
2828 response . deviceRegistries . forEach (
2929 function ( registry ) {
@@ -38,23 +38,23 @@ function listRegistries() {
3838 * Creates a registry.
3939 */
4040function createRegistry ( ) {
41- var cloudRegion = 'us-central1' ;
42- var name = 'your-registry-name' ;
43- var projectId = 'your-project-id' ;
44- var topic = 'your-pubsub-topic' ;
41+ const cloudRegion = 'us-central1' ;
42+ const name = 'your-registry-name' ;
43+ const projectId = 'your-project-id' ;
44+ const topic = 'your-pubsub-topic' ;
4545
46- var pubsubTopic = 'projects/' + projectId + '/topics/' + topic ;
46+ const pubsubTopic = 'projects/' + projectId + '/topics/' + topic ;
4747
48- var registry = {
48+ const registry = {
4949 'eventNotificationConfigs' : [ {
5050 // From - https://console.cloud.google.com/cloudpubsub
5151 pubsubTopicName : pubsubTopic
5252 } ] ,
5353 'id' : name
5454 } ;
55- var parent = 'projects/' + projectId + '/locations/' + cloudRegion ;
55+ const parent = 'projects/' + projectId + '/locations/' + cloudRegion ;
5656
57- var response = CloudIoT . Projects . Locations . Registries . create ( registry , parent ) ;
57+ const response = CloudIoT . Projects . Locations . Registries . create ( registry , parent ) ;
5858 console . log ( 'Created registry: ' + response . id ) ;
5959}
6060// [END apps_script_iot_create_registry]
@@ -64,14 +64,14 @@ function createRegistry() {
6464 * Describes a registry.
6565 */
6666function getRegistry ( ) {
67- var cloudRegion = 'us-central1' ;
68- var name = 'your-registry-name' ;
69- var projectId = 'your-project-id' ;
67+ const cloudRegion = 'us-central1' ;
68+ const name = 'your-registry-name' ;
69+ const projectId = 'your-project-id' ;
7070
71- var parent = 'projects/' + projectId + '/locations/' + cloudRegion ;
72- var registryName = parent + '/registries/' + name ;
71+ const parent = 'projects/' + projectId + '/locations/' + cloudRegion ;
72+ const registryName = parent + '/registries/' + name ;
7373
74- var response = CloudIoT . Projects . Locations . Registries . get ( registryName ) ;
74+ const response = CloudIoT . Projects . Locations . Registries . get ( registryName ) ;
7575 console . log ( 'Retrieved registry: ' + response . id ) ;
7676}
7777// [END apps_script_iot_get_registry]
@@ -81,14 +81,14 @@ function getRegistry() {
8181 * Deletes a registry.
8282 */
8383function deleteRegistry ( ) {
84- var cloudRegion = 'us-central1' ;
85- var name = 'your-registry-name' ;
86- var projectId = 'your-project-id' ;
84+ const cloudRegion = 'us-central1' ;
85+ const name = 'your-registry-name' ;
86+ const projectId = 'your-project-id' ;
8787
88- var parent = 'projects/' + projectId + '/locations/' + cloudRegion ;
89- var registryName = parent + '/registries/' + name ;
88+ const parent = 'projects/' + projectId + '/locations/' + cloudRegion ;
89+ const registryName = parent + '/registries/' + name ;
9090
91- var response = CloudIoT . Projects . Locations . Registries . remove ( registryName ) ;
91+ const response = CloudIoT . Projects . Locations . Registries . remove ( registryName ) ;
9292 // Successfully removed registry if exception was not thrown.
9393 console . log ( 'Deleted registry: ' + name ) ;
9494}
@@ -99,14 +99,14 @@ function deleteRegistry() {
9999 * Lists the devices in the given registry.
100100 */
101101function listDevicesForRegistry ( ) {
102- var cloudRegion = 'us-central1' ;
103- var name = 'your-registry-name' ;
104- var projectId = 'your-project-id' ;
102+ const cloudRegion = 'us-central1' ;
103+ const name = 'your-registry-name' ;
104+ const projectId = 'your-project-id' ;
105105
106- var parent = 'projects/' + projectId + '/locations/' + cloudRegion ;
107- var registryName = parent + '/registries/' + name ;
106+ const parent = 'projects/' + projectId + '/locations/' + cloudRegion ;
107+ const registryName = parent + '/registries/' + name ;
108108
109- var response = CloudIoT . Projects . Locations . Registries . Devices . list ( registryName ) ;
109+ const response = CloudIoT . Projects . Locations . Registries . Devices . list ( registryName ) ;
110110
111111 console . log ( 'Registry contains the following devices: ' ) ;
112112 if ( response . devices ) {
@@ -123,23 +123,23 @@ function listDevicesForRegistry() {
123123 * Creates a device without credentials.
124124 */
125125function createDevice ( ) {
126- var cloudRegion = 'us-central1' ;
127- var name = 'your-device-name' ;
128- var projectId = 'your-project-id' ;
129- var registry = 'your-registry-name' ;
126+ const cloudRegion = 'us-central1' ;
127+ const name = 'your-device-name' ;
128+ const projectId = 'your-project-id' ;
129+ const registry = 'your-registry-name' ;
130130
131131 console . log ( 'Creating device: ' + name + ' in Registry: ' + registry ) ;
132- var parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry ;
132+ const parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry ;
133133
134- var device = {
134+ const device = {
135135 id : name ,
136136 gatewayConfig : {
137137 gatewayType : 'NON_GATEWAY' ,
138138 gatewayAuthMethod : 'ASSOCIATION_ONLY'
139139 }
140140 } ;
141141
142- var response = CloudIoT . Projects . Locations . Registries . Devices . create ( device , parent ) ;
142+ const response = CloudIoT . Projects . Locations . Registries . Devices . create ( device , parent ) ;
143143 console . log ( 'Created device:' + response . name ) ;
144144}
145145// [END apps_script_iot_create_unauth_device]
@@ -153,21 +153,21 @@ function createRsaDevice() {
153153 // openssl req -x509 -newkey rsa:2048 -days 3650 -keyout rsa_private.pem \
154154 // -nodes -out rsa_cert.pem -subj "/CN=unused"
155155 //
156- // **NOTE** Be sure to insert the newline charaters in the string varant .
157- var cert =
156+ // **NOTE** Be sure to insert the newline charaters in the string constant .
157+ const cert =
158158 '-----BEGIN CERTIFICATE-----\n' +
159159 'your-PUBLIC-certificate-b64-bytes\n' +
160160 '...\n' +
161161 'more-PUBLIC-certificate-b64-bytes==\n' +
162162 '-----END CERTIFICATE-----\n' ;
163163
164- var cloudRegion = 'us-central1' ;
165- var name = 'your-device-name' ;
166- var projectId = 'your-project-id' ;
167- var registry = 'your-registry-name' ;
164+ const cloudRegion = 'us-central1' ;
165+ const name = 'your-device-name' ;
166+ const projectId = 'your-project-id' ;
167+ const registry = 'your-registry-name' ;
168168
169- var parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry ;
170- var device = {
169+ const parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry ;
170+ const device = {
171171 id : name ,
172172 gatewayConfig : {
173173 gatewayType : 'NON_GATEWAY' ,
@@ -181,7 +181,7 @@ function createRsaDevice() {
181181 } ]
182182 } ;
183183
184- var response = CloudIoT . Projects . Locations . Registries . Devices . create ( device , parent ) ;
184+ const response = CloudIoT . Projects . Locations . Registries . Devices . create ( device , parent ) ;
185185 console . log ( 'Created device:' + response . name ) ;
186186}
187187// [END apps_script_iot_create_rsa_device]
@@ -191,15 +191,15 @@ function createRsaDevice() {
191191 * Deletes a device from the given registry.
192192 */
193193function deleteDevice ( ) {
194- var cloudRegion = 'us-central1' ;
195- var name = 'your-device-name' ;
196- var projectId = 'your-project-id' ;
197- var registry = 'your-registry-name' ;
194+ const cloudRegion = 'us-central1' ;
195+ const name = 'your-device-name' ;
196+ const projectId = 'your-project-id' ;
197+ const registry = 'your-registry-name' ;
198198
199- var parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry ;
200- var deviceName = parent + '/devices/' + name ;
199+ const parent = 'projects/' + projectId + '/locations/' + cloudRegion + '/registries/' + registry ;
200+ const deviceName = parent + '/devices/' + name ;
201201
202- var response = CloudIoT . Projects . Locations . Registries . Devices . remove ( deviceName ) ;
202+ const response = CloudIoT . Projects . Locations . Registries . Devices . remove ( deviceName ) ;
203203 // If no exception thrown, device was successfully removed
204204 console . log ( 'Successfully deleted device: ' + deviceName ) ;
205205}
0 commit comments