@@ -38,83 +38,83 @@ var publishChainInProgress = false;
3838
3939console . log ( 'Google Cloud IoT Core MQTT example.' ) ;
4040var argv = require ( `yargs` )
41- . options ( {
42- projectId : {
43- default : process . env . GCLOUD_PROJECT || process . env . GOOGLE_CLOUD_PROJECT ,
44- description : 'The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT environment variables.' ,
45- requiresArg : true ,
46- type : 'string'
47- } ,
48- cloudRegion : {
49- default : 'us-central1' ,
50- description : 'GCP cloud region.' ,
51- requiresArg : true ,
52- type : 'string'
53- } ,
54- registryId : {
55- description : 'Cloud IoT registry ID.' ,
56- requiresArg : true ,
57- demandOption : true ,
58- type : 'string'
59- } ,
60- deviceId : {
61- description : 'Cloud IoT device ID.' ,
62- requiresArg : true ,
63- demandOption : true ,
64- type : 'string'
65- } ,
66- privateKeyFile : {
67- description : 'Path to private key file.' ,
68- requiresArg : true ,
69- demandOption : true ,
70- type : 'string'
71- } ,
72- algorithm : {
73- description : 'Encryption algorithm to generate the JWT.' ,
74- requiresArg : true ,
75- demandOption : true ,
76- choices : [ 'RS256' , 'ES256' ] ,
77- type : 'string'
78- } ,
79- numMessages : {
80- default : 100 ,
81- description : 'Number of messages to publish.' ,
82- requiresArg : true ,
83- type : 'number'
84- } ,
85- tokenExpMins : {
86- default : 20 ,
87- description : 'Minutes to JWT token expiration.' ,
88- requiresArg : true ,
89- type : 'number'
90- } ,
91- mqttBridgeHostname : {
92- default : 'mqtt.googleapis.com' ,
93- description : 'MQTT bridge hostname.' ,
94- requiresArg : true ,
95- type : 'string'
96- } ,
97- mqttBridgePort : {
98- default : 8883 ,
99- description : 'MQTT bridge port.' ,
100- requiresArg : true ,
101- type : 'number'
102- } ,
103- messageType : {
104- default : 'events' ,
105- description : 'Message type to publish.' ,
106- requiresArg : true ,
107- choices : [ 'events' , 'state' ] ,
108- type : 'string'
109- }
110- } )
111- . example ( `node $0 cloudiot_mqtt_example_nodejs.js --projectId=blue-jet-123 --registryId=my-registry --deviceId=my-node-device --privateKeyFile=../rsa_private.pem --algorithm=RS256` )
112- . wrap ( 120 )
113- . recommendCommands ( )
114- . epilogue ( `For more information, see https://cloud.google.com/iot-core/docs` )
115- . help ( )
116- . strict ( )
117- . argv ;
41+ . options ( {
42+ projectId : {
43+ default : process . env . GCLOUD_PROJECT || process . env . GOOGLE_CLOUD_PROJECT ,
44+ description : 'The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT environment variables.' ,
45+ requiresArg : true ,
46+ type : 'string'
47+ } ,
48+ cloudRegion : {
49+ default : 'us-central1' ,
50+ description : 'GCP cloud region.' ,
51+ requiresArg : true ,
52+ type : 'string'
53+ } ,
54+ registryId : {
55+ description : 'Cloud IoT registry ID.' ,
56+ requiresArg : true ,
57+ demandOption : true ,
58+ type : 'string'
59+ } ,
60+ deviceId : {
61+ description : 'Cloud IoT device ID.' ,
62+ requiresArg : true ,
63+ demandOption : true ,
64+ type : 'string'
65+ } ,
66+ privateKeyFile : {
67+ description : 'Path to private key file.' ,
68+ requiresArg : true ,
69+ demandOption : true ,
70+ type : 'string'
71+ } ,
72+ algorithm : {
73+ description : 'Encryption algorithm to generate the JWT.' ,
74+ requiresArg : true ,
75+ demandOption : true ,
76+ choices : [ 'RS256' , 'ES256' ] ,
77+ type : 'string'
78+ } ,
79+ numMessages : {
80+ default : 100 ,
81+ description : 'Number of messages to publish.' ,
82+ requiresArg : true ,
83+ type : 'number'
84+ } ,
85+ tokenExpMins : {
86+ default : 20 ,
87+ description : 'Minutes to JWT token expiration.' ,
88+ requiresArg : true ,
89+ type : 'number'
90+ } ,
91+ mqttBridgeHostname : {
92+ default : 'mqtt.googleapis.com' ,
93+ description : 'MQTT bridge hostname.' ,
94+ requiresArg : true ,
95+ type : 'string'
96+ } ,
97+ mqttBridgePort : {
98+ default : 8883 ,
99+ description : 'MQTT bridge port.' ,
100+ requiresArg : true ,
101+ type : 'number'
102+ } ,
103+ messageType : {
104+ default : 'events' ,
105+ description : 'Message type to publish.' ,
106+ requiresArg : true ,
107+ choices : [ 'events' , 'state' ] ,
108+ type : 'string'
109+ }
110+ } )
111+ . example ( `node $0 cloudiot_mqtt_example_nodejs.js --projectId=blue-jet-123 \\\n\t --registryId=my-registry --deviceId=my-node-device \\\n\t --privateKeyFile=../rsa_private.pem --algorithm=RS256 \\\n\t --cloudRegion=us-central1 ` )
112+ . wrap ( 120 )
113+ . recommendCommands ( )
114+ . epilogue ( `For more information, see https://cloud.google.com/iot-core/docs` )
115+ . help ( )
116+ . strict ( )
117+ . argv ;
118118
119119// Create a Cloud IoT Core JWT for the given project id, signed with the given
120120// private key.
@@ -125,7 +125,7 @@ function createJwt (projectId, privateKeyFile, algorithm) {
125125 // audience field should always be set to the GCP project id.
126126 const token = {
127127 'iat' : parseInt ( Date . now ( ) / 1000 ) ,
128- 'exp' : parseInt ( Date . now ( ) / 1000 ) + 20 * 60 , // 20 minutes
128+ 'exp' : parseInt ( Date . now ( ) / 1000 ) + 20 * 60 , // 20 minutes
129129 'aud' : projectId
130130 } ;
131131 const privateKey = fs . readFileSync ( privateKeyFile ) ;
0 commit comments