...
Use the Devices list method and specify a gateway ID to list all devices bound to the gateway.
Listing all devices bound to the gateway code samples
Node.js
Code Block |
---|
// const cloudRegion = 'us-central1'; // const gatewayId = 'my-gateway'; // const projectId = 'adjective-noun-123'; // const registryId = 'my-registry'; import { DeviceManagerClient } from '@clearblade/iot'; const iotClient = new DeviceManagerClient({ // optional auth parameters. }); async function listDevices() { // Construct request const parentName = iotClient.registryPath(projectId, cloudRegion, registryId); const [response] = await iotClient.listDevices({ parent: parentName, gatewayListOptions: { associationsGatewayId: gatewayId } }); const devices = response; if (devices.length > 0) { console.log('Current devices bound to gateway: ', gatewayId); } else { console.log('No devices bound to this gateway.'); } for (let i = 0; i < devices.length; i++) { const device = devices[i]; console.log(`\tDevice: ${device.numId}: ${device.id}`); } } listDevices(); |
...