Constructor

DeviceManagerClient

new DeviceManagerClient(options)

Construct an instance of DeviceManagerClient.

Parameter

options

Optional

object

The configuration object. See the subsequent parameters for more details.

Values in options have the following properties:

Parameter

credentials

Optional

object

Credentials object.

credentials.client_email

Optional

string

credentials.private_key

Optional

string

email

Optional

string

Account email address. Required when using a .pem or .p12 keyFilename.

keyFilename

Optional

string

Full path to the a .json, .pem, or .p12 key downloaded from the Google Developers Console. If you provide a path to a JSON file, the projectId option below is not necessary. NOTE: .pem and .p12 require you to specify options.email as well.

port

Optional

number

The port on which to connect to the remote host.

projectId

Optional

string

The project ID from the Google Developer's Console, e.g. 'grape-spaceship-123'. We will also check the environment variable GCLOUD_PROJECT for your project ID. If your app is running in an environment which supports Application Default Credentials, your project ID will be detected automatically.

promise

Optional

function()

Custom promise module to use instead of native Promises.

servicePath

Optional

string

The domain name of the API remote host.

Properties

port

static

The port for this API service.

scopes

static

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static

The DNS address for this API service.

Methods

bindDeviceToGateway

bindDeviceToGateway(request, options, callback) returns Promise

Associates the device with the gateway.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

The name of the registry. For example, projects/example-project/locations/us-central1/registries/my-registry.

gatewayId

string

The value of gateway_id can be either the device numeric ID or the user-defined device identifier.

deviceId

string

The device to associate with the specified gateway. The value of device_id can be either the device numeric ID or the user-defined device identifier.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing BindDeviceToGatewayResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing BindDeviceToGatewayResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedParent = client.registryPath('[PROJECT]', '[LOCATION]', '[REGISTRY]');
const gatewayId = '';
const deviceId = '';
const request = {
  parent: formattedParent,
  gatewayId: gatewayId,
  deviceId: deviceId,
};
client.bindDeviceToGateway(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

createDevice

createDevice(request, options, callback) returns Promise

Creates a device in a device registry.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

The name of the device registry where this device should be created. For example, projects/example-project/locations/us-central1/registries/my-registry.

device

Object

The device registration details. The field name must be empty. The server generates name from the device registry id and the parent field.

This object should have the same structure as Device

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Device.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Device. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedParent = client.registryPath('[PROJECT]', '[LOCATION]', '[REGISTRY]');
const device = {};
const request = {
  parent: formattedParent,
  device: device,
};
client.createDevice(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

createDeviceRegistry

createDeviceRegistry(request, options, callback) returns Promise

Creates a device registry that contains devices.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

The project and cloud region where this device registry must be created. For example, projects/example-project/locations/us-central1.

deviceRegistry

Object

The device registry. The field name must be empty. The server will generate that field from the device registry id provided and the parent field.

This object should have the same structure as DeviceRegistry

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing DeviceRegistry.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing DeviceRegistry. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
const deviceRegistry = {};
const request = {
  parent: formattedParent,
  deviceRegistry: deviceRegistry,
};
client.createDeviceRegistry(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

deleteDevice

deleteDevice(request, options, callback) returns Promise

Deletes a device.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

The name of the device. For example, projects/p0/locations/us-central1/registries/registry0/devices/device0 or projects/p0/locations/us-central1/registries/registry0/devices/{num_id}.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error)

The function which will be called with the result of the API call.

Returns

Promise 

  • The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedName = client.devicePath('[PROJECT]', '[LOCATION]', '[REGISTRY]', '[DEVICE]');
client.deleteDevice({name: formattedName}).catch(err => {
  console.error(err);
});

deleteDeviceRegistry

deleteDeviceRegistry(request, options, callback) returns Promise

Deletes a device registry configuration.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

The name of the device registry. For example, projects/example-project/locations/us-central1/registries/my-registry.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error)

The function which will be called with the result of the API call.

Returns

Promise 

  • The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedName = client.registryPath('[PROJECT]', '[LOCATION]', '[REGISTRY]');
client.deleteDeviceRegistry({name: formattedName}).catch(err => {
  console.error(err);
});

devicePath

devicePath(project, location, registry, device) returns String

Return a fully-qualified device resource name string.

Parameter

project

String

location

String

registry

String

device

String

Returns

String 

getDevice

getDevice(request, options, callback) returns Promise

Gets details about a device.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

The name of the device. For example, projects/p0/locations/us-central1/registries/registry0/devices/device0 or projects/p0/locations/us-central1/registries/registry0/devices/{num_id}.

fieldMask

Optional

Object

The fields of the Device resource to be returned in the response. If the field mask is unset or empty, all fields are returned.

This object should have the same structure as FieldMask

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Device.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Device. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedName = client.devicePath('[PROJECT]', '[LOCATION]', '[REGISTRY]', '[DEVICE]');
client.getDevice({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getDeviceRegistry

getDeviceRegistry(request, options, callback) returns Promise

Gets a device registry configuration.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

The name of the device registry. For example, projects/example-project/locations/us-central1/registries/my-registry.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing DeviceRegistry.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing DeviceRegistry. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedName = client.registryPath('[PROJECT]', '[LOCATION]', '[REGISTRY]');
client.getDeviceRegistry({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getIamPolicy

getIamPolicy(request, options, callback) returns Promise

Gets the access control policy for a resource. Returns an empty policy if the resource exists and does not have a policy set.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

resource

string

REQUIRED: The resource for which the policy is being requested. resource is usually specified as a path. For example, a Project resource is specified as projects/{project}.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Policy.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Policy. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedResource = client.registryPath('[PROJECT]', '[LOCATION]', '[REGISTRY]');
client.getIamPolicy({resource: formattedResource})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

getProjectId

getProjectId(callback)

Return the project ID used by this class.

Parameter

callback

function(Error, string)

the callback to be called with the current project Id.

listDeviceConfigVersions

listDeviceConfigVersions(request, options, callback) returns Promise

Lists the last few versions of the device configuration in descending order (i.e.: newest first).

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

The name of the device. For example, projects/p0/locations/us-central1/registries/registry0/devices/device0 or projects/p0/locations/us-central1/registries/registry0/devices/{num_id}.

numVersions

Optional

number

The number of versions to list. Versions are listed in decreasing order of the version number. The maximum number of versions retained is 10. If this value is zero, it will return all the versions available.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing ListDeviceConfigVersionsResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing ListDeviceConfigVersionsResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedName = client.devicePath('[PROJECT]', '[LOCATION]', '[REGISTRY]', '[DEVICE]');
client.listDeviceConfigVersions({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

listDeviceRegistries

listDeviceRegistries(request, options, callback) returns Promise

Lists device registries.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

The project and cloud region path. For example, projects/example-project/locations/us-central1.

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Array, nullable Object, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is Array of DeviceRegistry.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListDeviceRegistriesResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is Array of DeviceRegistry.

    When autoPaginate: false is specified through options, the array has three elements. The first element is Array of DeviceRegistry in a single response. The second element is the next request object if the response indicates the next page exists, or null. The third element is an object representing ListDeviceRegistriesResponse.

    The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

// Iterate over all elements.
const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');

client.listDeviceRegistries({parent: formattedParent})
  .then(responses => {
    const resources = responses[0];
    for (const resource of resources) {
      // doThingsWith(resource)
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');


const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (const resource of resources) {
    // doThingsWith(resource);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listDeviceRegistries(nextRequest, options).then(callback);
  }
}
client.listDeviceRegistries({parent: formattedParent}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listDeviceRegistriesStream

listDeviceRegistriesStream(request, options) returns Stream

Equivalent to listDeviceRegistries, but returns a NodeJS Stream object.

This fetches the paged responses for listDeviceRegistries continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

The project and cloud region path. For example, projects/example-project/locations/us-central1.

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

See also
https://nodejs.org/api/stream.html
Returns

Stream 

An object stream which emits an object representing DeviceRegistry on 'data' event.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedParent = client.locationPath('[PROJECT]', '[LOCATION]');
client.listDeviceRegistriesStream({parent: formattedParent})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

listDevices

listDevices(request, options, callback) returns Promise

List devices in a device registry.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

The device registry path. Required. For example, projects/my-project/locations/us-central1/registries/my-registry.

deviceNumIds

Optional

Array of number

A list of device numeric IDs. If empty, this field is ignored. Maximum IDs: 10,000.

deviceIds

Optional

Array of string

A list of device string IDs. For example, ['device0', 'device12']. If empty, this field is ignored. Maximum IDs: 10,000

fieldMask

Optional

Object

The fields of the Device resource to be returned in the response. The fields id and num_id are always returned, along with any other fields specified.

This object should have the same structure as FieldMask

gatewayListOptions

Optional

Object

Options related to gateways.

This object should have the same structure as GatewayListOptions

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Array, nullable Object, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is Array of Device.

When autoPaginate: false is specified through options, it contains the result in a single response. If the response indicates the next page exists, the third parameter is set to be used for the next request object. The fourth parameter keeps the raw response object of an object representing ListDevicesResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is Array of Device.

    When autoPaginate: false is specified through options, the array has three elements. The first element is Array of Device in a single response. The second element is the next request object if the response indicates the next page exists, or null. The third element is an object representing ListDevicesResponse.

    The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

// Iterate over all elements.
const formattedParent = client.registryPath('[PROJECT]', '[LOCATION]', '[REGISTRY]');

client.listDevices({parent: formattedParent})
  .then(responses => {
    const resources = responses[0];
    for (const resource of resources) {
      // doThingsWith(resource)
    }
  })
  .catch(err => {
    console.error(err);
  });

// Or obtain the paged response.
const formattedParent = client.registryPath('[PROJECT]', '[LOCATION]', '[REGISTRY]');


const options = {autoPaginate: false};
const callback = responses => {
  // The actual resources in a response.
  const resources = responses[0];
  // The next request if the response shows that there are more responses.
  const nextRequest = responses[1];
  // The actual response object, if necessary.
  // const rawResponse = responses[2];
  for (const resource of resources) {
    // doThingsWith(resource);
  }
  if (nextRequest) {
    // Fetch the next page.
    return client.listDevices(nextRequest, options).then(callback);
  }
}
client.listDevices({parent: formattedParent}, options)
  .then(callback)
  .catch(err => {
    console.error(err);
  });

listDevicesStream

listDevicesStream(request, options) returns Stream

Equivalent to listDevices, but returns a NodeJS Stream object.

This fetches the paged responses for listDevices continuously and invokes the callback registered for 'data' event for each element in the responses.

The returned object has 'end' method when no more elements are required.

autoPaginate option will be ignored.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

The device registry path. Required. For example, projects/my-project/locations/us-central1/registries/my-registry.

deviceNumIds

Optional

Array of number

A list of device numeric IDs. If empty, this field is ignored. Maximum IDs: 10,000.

deviceIds

Optional

Array of string

A list of device string IDs. For example, ['device0', 'device12']. If empty, this field is ignored. Maximum IDs: 10,000

fieldMask

Optional

Object

The fields of the Device resource to be returned in the response. The fields id and num_id are always returned, along with any other fields specified.

This object should have the same structure as FieldMask

gatewayListOptions

Optional

Object

Options related to gateways.

This object should have the same structure as GatewayListOptions

pageSize

Optional

number

The maximum number of resources contained in the underlying API response. If page streaming is performed per-resource, this parameter does not affect the return value. If page streaming is performed per-page, this determines the maximum number of resources in a page.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

See also
https://nodejs.org/api/stream.html
Returns

Stream 

An object stream which emits an object representing Device on 'data' event.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedParent = client.registryPath('[PROJECT]', '[LOCATION]', '[REGISTRY]');
client.listDevicesStream({parent: formattedParent})
  .on('data', element => {
    // doThingsWith(element)
  }).on('error', err => {
    console.log(err);
  });

listDeviceStates

listDeviceStates(request, options, callback) returns Promise

Lists the last few versions of the device state in descending order (i.e.: newest first).

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

The name of the device. For example, projects/p0/locations/us-central1/registries/registry0/devices/device0 or projects/p0/locations/us-central1/registries/registry0/devices/{num_id}.

numStates

Optional

number

The number of states to list. States are listed in descending order of update time. The maximum number of states retained is 10. If this value is zero, it will return all the states available.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing ListDeviceStatesResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing ListDeviceStatesResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedName = client.devicePath('[PROJECT]', '[LOCATION]', '[REGISTRY]', '[DEVICE]');
client.listDeviceStates({name: formattedName})
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

locationPath

locationPath(project, location) returns String

Return a fully-qualified location resource name string.

Parameter

project

String

location

String

Returns

String 

matchDeviceFromDeviceName

matchDeviceFromDeviceName(deviceName) returns String

Parse the deviceName from a device resource.

Parameter

deviceName

String

A fully-qualified path representing a device resources.

Returns

String 

  • A string representing the device.

matchLocationFromDeviceName

matchLocationFromDeviceName(deviceName) returns String

Parse the deviceName from a device resource.

Parameter

deviceName

String

A fully-qualified path representing a device resources.

Returns

String 

  • A string representing the location.

matchLocationFromLocationName

matchLocationFromLocationName(locationName) returns String

Parse the locationName from a location resource.

Parameter

locationName

String

A fully-qualified path representing a location resources.

Returns

String 

  • A string representing the location.

matchLocationFromRegistryName

matchLocationFromRegistryName(registryName) returns String

Parse the registryName from a registry resource.

Parameter

registryName

String

A fully-qualified path representing a registry resources.

Returns

String 

  • A string representing the location.

matchProjectFromDeviceName

matchProjectFromDeviceName(deviceName) returns String

Parse the deviceName from a device resource.

Parameter

deviceName

String

A fully-qualified path representing a device resources.

Returns

String 

  • A string representing the project.

matchProjectFromLocationName

matchProjectFromLocationName(locationName) returns String

Parse the locationName from a location resource.

Parameter

locationName

String

A fully-qualified path representing a location resources.

Returns

String 

  • A string representing the project.

matchProjectFromRegistryName

matchProjectFromRegistryName(registryName) returns String

Parse the registryName from a registry resource.

Parameter

registryName

String

A fully-qualified path representing a registry resources.

Returns

String 

  • A string representing the project.

matchRegistryFromDeviceName

matchRegistryFromDeviceName(deviceName) returns String

Parse the deviceName from a device resource.

Parameter

deviceName

String

A fully-qualified path representing a device resources.

Returns

String 

  • A string representing the registry.

matchRegistryFromRegistryName

matchRegistryFromRegistryName(registryName) returns String

Parse the registryName from a registry resource.

Parameter

registryName

String

A fully-qualified path representing a registry resources.

Returns

String 

  • A string representing the registry.

modifyCloudToDeviceConfig

modifyCloudToDeviceConfig(request, options, callback) returns Promise

Modifies the configuration for the device, which is eventually sent from the Cloud IoT Core servers. Returns the modified configuration version and its metadata.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

The name of the device. For example, projects/p0/locations/us-central1/registries/registry0/devices/device0 or projects/p0/locations/us-central1/registries/registry0/devices/{num_id}.

binaryData

string

The configuration data for the device.

versionToUpdate

Optional

number

The version number to update. If this value is zero, it will not check the version number of the server and will always update the current version; otherwise, this update will fail if the version number found on the server does not match this version number. This is used to support multiple simultaneous updates without losing data.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing DeviceConfig.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing DeviceConfig. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedName = client.devicePath('[PROJECT]', '[LOCATION]', '[REGISTRY]', '[DEVICE]');
const binaryData = '';
const request = {
  name: formattedName,
  binaryData: binaryData,
};
client.modifyCloudToDeviceConfig(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

registryPath

registryPath(project, location, registry) returns String

Return a fully-qualified registry resource name string.

Parameter

project

String

location

String

registry

String

Returns

String 

sendCommandToDevice

sendCommandToDevice(request, options, callback) returns Promise

Sends a command to the specified device. In order for a device to be able to receive commands, it must: 1) be connected to Cloud IoT Core using the MQTT protocol, and 2) be subscribed to the group of MQTT topics specified by /devices/{device-id}/commands/#. This subscription will receive commands at the top-level topic /devices/{device-id}/commands as well as commands for subfolders, like /devices/{device-id}/commands/subfolder. Note that subscribing to specific subfolders is not supported. If the command could not be delivered to the device, this method will return an error; in particular, if the device is not subscribed, this method will return FAILED_PRECONDITION. Otherwise, this method will return OK. If the subscription is QoS 1, at least once delivery will be guaranteed; for QoS 0, no acknowledgment will be expected from the device.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

name

string

The name of the device. For example, projects/p0/locations/us-central1/registries/registry0/devices/device0 or projects/p0/locations/us-central1/registries/registry0/devices/{num_id}.

binaryData

string

The command data to send to the device.

subfolder

Optional

string

Optional subfolder for the command. If empty, the command will be delivered to the /devices/{device-id}/commands topic, otherwise it will be delivered to the /devices/{device-id}/commands/{subfolder} topic. Multi-level subfolders are allowed. This field must not have more than 256 characters, and must not contain any MQTT wildcards ("+" or "#") or null characters.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing SendCommandToDeviceResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing SendCommandToDeviceResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedName = client.devicePath('[PROJECT]', '[LOCATION]', '[REGISTRY]', '[DEVICE]');
const binaryData = '';
const request = {
  name: formattedName,
  binaryData: binaryData,
};
client.sendCommandToDevice(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

setIamPolicy

setIamPolicy(request, options, callback) returns Promise

Sets the access control policy on the specified resource. Replaces any existing policy.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

resource

string

REQUIRED: The resource for which the policy is being specified. resource is usually specified as a path. For example, a Project resource is specified as projects/{project}.

policy

Object

REQUIRED: The complete policy to be applied to the resource. The size of the policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud Platform services (such as Projects) might reject them.

This object should have the same structure as Policy

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Policy.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Policy. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedResource = client.registryPath('[PROJECT]', '[LOCATION]', '[REGISTRY]');
const policy = {};
const request = {
  resource: formattedResource,
  policy: policy,
};
client.setIamPolicy(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

testIamPermissions

testIamPermissions(request, options, callback) returns Promise

Returns permissions that a caller has on the specified resource. If the resource does not exist, this will return an empty set of permissions, not a NOT_FOUND error.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

resource

string

REQUIRED: The resource for which the policy detail is being requested. resource is usually specified as a path. For example, a Project resource is specified as projects/{project}.

permissions

Array of string

The set of permissions to check for the resource. Permissions with wildcards (such as '' or 'storage.') are not allowed. For more information see IAM Overview.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing TestIamPermissionsResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing TestIamPermissionsResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedResource = client.registryPath('[PROJECT]', '[LOCATION]', '[REGISTRY]');
const permissions = [];
const request = {
  resource: formattedResource,
  permissions: permissions,
};
client.testIamPermissions(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

unbindDeviceFromGateway

unbindDeviceFromGateway(request, options, callback) returns Promise

Deletes the association between the device and the gateway.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

parent

string

The name of the registry. For example, projects/example-project/locations/us-central1/registries/my-registry.

gatewayId

string

The value of gateway_id can be either the device numeric ID or the user-defined device identifier.

deviceId

string

The device to disassociate from the specified gateway. The value of device_id can be either the device numeric ID or the user-defined device identifier.

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing UnbindDeviceFromGatewayResponse.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing UnbindDeviceFromGatewayResponse. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const formattedParent = client.registryPath('[PROJECT]', '[LOCATION]', '[REGISTRY]');
const gatewayId = '';
const deviceId = '';
const request = {
  parent: formattedParent,
  gatewayId: gatewayId,
  deviceId: deviceId,
};
client.unbindDeviceFromGateway(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

updateDevice

updateDevice(request, options, callback) returns Promise

Updates a device.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

device

Object

The new values for the device. The id and num_id fields must be empty, and the field name must specify the name path. For example, projects/p0/locations/us-central1/registries/registry0/devices/device0or projects/p0/locations/us-central1/registries/registry0/devices/{num_id}.

This object should have the same structure as Device

updateMask

Object

Only updates the device fields indicated by this mask. The field mask must not be empty, and it must not contain fields that are immutable or only set by the server. Mutable top-level fields: credentials, blocked, and metadata

This object should have the same structure as FieldMask

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing Device.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing Device. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const device = {};
const updateMask = {};
const request = {
  device: device,
  updateMask: updateMask,
};
client.updateDevice(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });

updateDeviceRegistry

updateDeviceRegistry(request, options, callback) returns Promise

Updates a device registry configuration.

Parameter

request

Object

The request object that will be sent.

Values in request have the following properties:

Parameter

deviceRegistry

Object

The new values for the device registry. The id field must be empty, and the name field must indicate the path of the resource. For example, projects/example-project/locations/us-central1/registries/my-registry.

This object should have the same structure as DeviceRegistry

updateMask

Object

Only updates the device_registry fields indicated by this mask. The field mask must not be empty, and it must not contain fields that are immutable or only set by the server. Mutable top-level fields: event_notification_config, http_config, mqtt_config, and state_notification_config.

This object should have the same structure as FieldMask

options

Optional

Object

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback

Optional

function(nullable Error, nullable Object)

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing DeviceRegistry.

Returns

Promise 

  • The promise which resolves to an array. The first element of the array is an object representing DeviceRegistry. The promise has a method named "cancel" which cancels the ongoing API call.

Example

const iot = require('@google-cloud/iot');

const client = new iot.v1.DeviceManagerClient({
  // optional auth parameters.
});

const deviceRegistry = {};
const updateMask = {};
const request = {
  deviceRegistry: deviceRegistry,
  updateMask: updateMask,
};
client.updateDeviceRegistry(request)
  .then(responses => {
    const response = responses[0];
    // doThingsWith(response)
  })
  .catch(err => {
    console.error(err);
  });