Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions iot/http_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,18 @@ Options:
--privateKeyFile <key_file> Path to private key file.
--algorithm <algorithm> Encryption algorithm to generate the JWT.
Either RS256 (RSA) or ES256 (Eliptic Curve)
--cloudRegion [region] GCP cloud region
--cloudRegion [region] GCP cloud region (e.g. us-central1, europe-west1)
--numMessages [num] Number of messages to publish.
--tokenExpMins [num] Minutes to JWT token expiration.
--httpBridgeAddress [address] HTTP bridge address.
--messageType [events|state] The message type to publish.

For example, if your project ID is `blue-jet-123`, your service account
credentials are stored in your home folder in creds.json and you have generated
your credentials using the shell script provided in the parent folder, you can
run the sample as:
For example, if your project ID is `blue-jet-123`, your region is
asia-east1, and you have generated your credentials using the shell script
provided in the parent folder, you can run the sample as:

node cloudiot_http_example_nodejs.js \
--cloudRegion=asia-east1 \
--projectId=blue-jet-123 \
--registryId=my-registry \
--deviceId=my-node-device \
Expand Down
9 changes: 5 additions & 4 deletions iot/manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ Run the following command to install the library dependencies for NodeJS:

Examples:
node manager.js createEs256Device my-es-device my-registry ../ec_public.pem
node manager.js createRegistry my-registry my-iot-topic --serviceAccount=$HOME/creds_iot.json
--project_id=my-project-id
node manager.js createRegistry my-registry my-iot-topic \
--serviceAccount=$HOME/creds_iot.json \
--projectId=my-project-id --cloudRegion=from-console
node manager.js createRsa256Device my-rsa-device my-registry ../rsa_cert.pem
node manager.js createUnauthDevice my-device my-registry
node manager.js deleteDevice my-device my-registry
node manager.js deleteRegistry my-device my-registry
node manager.js getDevice my-device my-registry
node manager.js getDeviceState my-device my-registry
node manager.js getRegistry my-registry
node manager.js getRegistry my-registry -cloudRegion europe-west1
node manager.js listDevices my-node-registry
node manager.js listRegistries
node manager.js listRegistries -c asia-east1 -p your-project -s path/svc.json
node manager.js patchRsa256 my-device my-registry ../rsa_cert.pem
node manager.js patchEs256 my-device my-registry ../ec_public.pem
node manager.js setConfig my-device my-registry "test" 0
Expand Down
8 changes: 4 additions & 4 deletions iot/manager/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ function getDeviceConfigs (client, deviceId, registryId, projectId,
// [END iot_get_device_configs]
}

// Retrieve the given device's state from the registry.
// Send configuration data to device.
function setDeviceConfig (client, deviceId, registryId, projectId,
cloudRegion, data, version) {
// [START iot_set_device_config]
Expand Down Expand Up @@ -1009,7 +1009,7 @@ require(`yargs`) // eslint-disable-line
}
)
.example(`node $0 createEs256Device my-es-device my-registry ../ec_public.pem`)
.example(`node $0 createRegistry my-registry my-iot-topic --serviceAccount=$HOME/creds_iot.json --project_id=my-project-id`)
.example(`node $0 createRegistry my-registry my-iot-topic --serviceAccount=$secure/svc.json --projectId=my-project-id`)
.example(`node $0 createRsa256Device my-rsa-device my-registry ../rsa_cert.pem`)
.example(`node $0 createUnauthDevice my-device my-registry`)
.example(`node $0 deleteDevice my-device my-registry`)
Expand All @@ -1018,8 +1018,8 @@ require(`yargs`) // eslint-disable-line
.example(`node $0 getDeviceState my-device my-registry`)
.example(`node $0 getIamPolicy my-registry`)
.example(`node $0 getRegistry my-registry`)
.example(`node $0 listDevices my-node-registry`)
.example(`node $0 listRegistries`)
.example(`node $0 listDevices -s path/svc.json -p your-project-id -c asia-east1 my-registry`)
.example(`node $0 listRegistries -s path/svc.json -p your-project-id -c europe-west1`)
.example(`node $0 patchRsa256 my-device my-registry ../rsa_cert.pem`)
.example(`node $0 patchEs256 my-device my-registry ../ec_public.pem`)
.example(`node $0 setConfig my-device my-registry "test" 0`)
Expand Down
26 changes: 13 additions & 13 deletions iot/mqtt_example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ The following command summarizes the sample usage:

Options:

--projectId The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT
environment variables.
--cloudRegion GCP cloud region.
--registryId Cloud IoT registry ID.
--deviceId Cloud IoT device ID.
--privateKeyFile Path to private key file.
--algorithm Encryption algorithm to generate the JWT.
--numMessages Number of messages to publish.
--tokenExpMins Minutes to JWT token expiration.
--mqttBridgeHostname MQTT bridge hostname.
--mqttBridgePort MQTT bridge port.
--messageType Message type to publish.
--help Show help
--projectId The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT
environment variables.
--cloudRegion GCP cloud region.
--registryId Cloud IoT registry ID.
--deviceId Cloud IoT device ID.
--privateKeyFile Path to private key file.
--algorithm Encryption algorithm to generate the JWT.
--numMessages Number of messages to publish.
--tokenExpMins Minutes to JWT token expiration.
--mqttBridgeHostname MQTT bridge hostname.
--mqttBridgePort MQTT bridge port.
--messageType Message type to publish.
--help Show help


For example, if your project ID is `blue-jet-123`, your service account
Expand Down
156 changes: 78 additions & 78 deletions iot/mqtt_example/cloudiot_mqtt_example_nodejs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,83 +38,83 @@ var publishChainInProgress = false;

console.log('Google Cloud IoT Core MQTT example.');
var argv = require(`yargs`)
.options({
projectId: {
default: process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT,
description: 'The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT environment variables.',
requiresArg: true,
type: 'string'
},
cloudRegion: {
default: 'us-central1',
description: 'GCP cloud region.',
requiresArg: true,
type: 'string'
},
registryId: {
description: 'Cloud IoT registry ID.',
requiresArg: true,
demandOption: true,
type: 'string'
},
deviceId: {
description: 'Cloud IoT device ID.',
requiresArg: true,
demandOption: true,
type: 'string'
},
privateKeyFile: {
description: 'Path to private key file.',
requiresArg: true,
demandOption: true,
type: 'string'
},
algorithm: {
description: 'Encryption algorithm to generate the JWT.',
requiresArg: true,
demandOption: true,
choices: ['RS256', 'ES256'],
type: 'string'
},
numMessages: {
default: 100,
description: 'Number of messages to publish.',
requiresArg: true,
type: 'number'
},
tokenExpMins: {
default: 20,
description: 'Minutes to JWT token expiration.',
requiresArg: true,
type: 'number'
},
mqttBridgeHostname: {
default: 'mqtt.googleapis.com',
description: 'MQTT bridge hostname.',
requiresArg: true,
type: 'string'
},
mqttBridgePort: {
default: 8883,
description: 'MQTT bridge port.',
requiresArg: true,
type: 'number'
},
messageType: {
default: 'events',
description: 'Message type to publish.',
requiresArg: true,
choices: ['events', 'state'],
type: 'string'
}
})
.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`)
.wrap(120)
.recommendCommands()
.epilogue(`For more information, see https://cloud.google.com/iot-core/docs`)
.help()
.strict()
.argv;
.options({
projectId: {
default: process.env.GCLOUD_PROJECT || process.env.GOOGLE_CLOUD_PROJECT,
description: 'The Project ID to use. Defaults to the value of the GCLOUD_PROJECT or GOOGLE_CLOUD_PROJECT environment variables.',
requiresArg: true,
type: 'string'
},
cloudRegion: {
default: 'us-central1',
description: 'GCP cloud region.',
requiresArg: true,
type: 'string'
},
registryId: {
description: 'Cloud IoT registry ID.',
requiresArg: true,
demandOption: true,
type: 'string'
},
deviceId: {
description: 'Cloud IoT device ID.',
requiresArg: true,
demandOption: true,
type: 'string'
},
privateKeyFile: {
description: 'Path to private key file.',
requiresArg: true,
demandOption: true,
type: 'string'
},
algorithm: {
description: 'Encryption algorithm to generate the JWT.',
requiresArg: true,
demandOption: true,
choices: ['RS256', 'ES256'],
type: 'string'
},
numMessages: {
default: 100,
description: 'Number of messages to publish.',
requiresArg: true,
type: 'number'
},
tokenExpMins: {
default: 20,
description: 'Minutes to JWT token expiration.',
requiresArg: true,
type: 'number'
},
mqttBridgeHostname: {
default: 'mqtt.googleapis.com',
description: 'MQTT bridge hostname.',
requiresArg: true,
type: 'string'
},
mqttBridgePort: {
default: 8883,
description: 'MQTT bridge port.',
requiresArg: true,
type: 'number'
},
messageType: {
default: 'events',
description: 'Message type to publish.',
requiresArg: true,
choices: ['events', 'state'],
type: 'string'
}
})
.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`)
.wrap(120)
.recommendCommands()
.epilogue(`For more information, see https://cloud.google.com/iot-core/docs`)
.help()
.strict()
.argv;

// Create a Cloud IoT Core JWT for the given project id, signed with the given
// private key.
Expand All @@ -125,7 +125,7 @@ function createJwt (projectId, privateKeyFile, algorithm) {
// audience field should always be set to the GCP project id.
const token = {
'iat': parseInt(Date.now() / 1000),
'exp': parseInt(Date.now() / 1000) + 20 * 60, // 20 minutes
'exp': parseInt(Date.now() / 1000) + 20 * 60, // 20 minutes
'aud': projectId
};
const privateKey = fs.readFileSync(privateKeyFile);
Expand Down
36 changes: 18 additions & 18 deletions iot/mqtt_example/system-test/cloudiot_mqtt_example_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ test(`should receive configuration message`, async (t) => {

let output = await tools.runAsync(`${helper} setupIotTopic ${topicName}`, cwd);
await tools.runAsync(
`${helper} createRegistry ${localRegName} ${topicName}`, cwd);
`${helper} createRegistry ${localRegName} ${topicName}`, cwd);
await tools.runAsync(
`${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd);
`${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd);

output = await tools.runAsync(
`${cmd} --messageType=events --registryId="${localRegName}" --deviceId="${localDevice}" ${cmdSuffix}`,
cwd);
`${cmd} --messageType=events --registryId="${localRegName}" --deviceId="${localDevice}" ${cmdSuffix}`,
cwd);
t.regex(output, new RegExp(`message received`));

// Check / cleanup
await tools.runAsync(
`${helper} getDeviceState ${localDevice} ${localRegName}`, cwd);
`${helper} getDeviceState ${localDevice} ${localRegName}`, cwd);
await tools.runAsync(
`${helper} deleteDevice ${localDevice} ${localRegName}`, cwd);
`${helper} deleteDevice ${localDevice} ${localRegName}`, cwd);
await tools.runAsync(`${helper} deleteRegistry ${localRegName}`, cwd);
});

Expand All @@ -76,20 +76,20 @@ test(`should send event message`, async (t) => {
const localRegName = `${registryName}-rsa256`;
await tools.runAsync(`${helper} setupIotTopic ${topicName}`, cwd);
await tools.runAsync(
`${helper} createRegistry ${localRegName} ${topicName}`, cwd);
`${helper} createRegistry ${localRegName} ${topicName}`, cwd);
await tools.runAsync(
`${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd);
`${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd);

const output = await tools.runAsync(
`${cmd} --messageType=events --registryId="${localRegName}" --deviceId="${localDevice}" ${cmdSuffix}`,
cwd);
`${cmd} --messageType=events --registryId="${localRegName}" --deviceId="${localDevice}" ${cmdSuffix}`,
cwd);
t.regex(output, new RegExp(`Publishing message:`));

// Check / cleanup
await tools.runAsync(
`${helper} getDeviceState ${localDevice} ${localRegName}`, cwd);
`${helper} getDeviceState ${localDevice} ${localRegName}`, cwd);
await tools.runAsync(
`${helper} deleteDevice ${localDevice} ${localRegName}`, cwd);
`${helper} deleteDevice ${localDevice} ${localRegName}`, cwd);
await tools.runAsync(`${helper} deleteRegistry ${localRegName}`, cwd);
});

Expand All @@ -98,19 +98,19 @@ test(`should send event message`, async (t) => {
const localRegName = `${registryName}-rsa256`;
await tools.runAsync(`${helper} setupIotTopic ${topicName}`, cwd);
await tools.runAsync(
`${helper} createRegistry ${localRegName} ${topicName}`, cwd);
`${helper} createRegistry ${localRegName} ${topicName}`, cwd);
await tools.runAsync(
`${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd);
`${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd);

const output = await tools.runAsync(
`${cmd} --messageType=state --registryId="${localRegName}" --deviceId="${localDevice}" ${cmdSuffix}`,
cwd);
`${cmd} --messageType=state --registryId="${localRegName}" --deviceId="${localDevice}" ${cmdSuffix}`,
cwd);
t.regex(output, new RegExp(`Publishing message:`));

// Check / cleanup
await tools.runAsync(
`${helper} getDeviceState ${localDevice} ${localRegName}`, cwd);
`${helper} getDeviceState ${localDevice} ${localRegName}`, cwd);
await tools.runAsync(
`${helper} deleteDevice ${localDevice} ${localRegName}`, cwd);
`${helper} deleteDevice ${localDevice} ${localRegName}`, cwd);
await tools.runAsync(`${helper} deleteRegistry ${localRegName}`, cwd);
});