|
| 1 | +// Copyright 2021 Google LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +'use strict'; |
| 16 | + |
| 17 | +function main(parent, gatewayId, deviceId) { |
| 18 | + // [START cloudiot_v1_generated_DeviceManager_BindDeviceToGateway_async] |
| 19 | + /** |
| 20 | + * TODO(developer): Uncomment these variables before running the sample. |
| 21 | + */ |
| 22 | + /** |
| 23 | + * Required. The name of the registry. For example, |
| 24 | + * `projects/example-project/locations/us-central1/registries/my-registry`. |
| 25 | + */ |
| 26 | + // const parent = 'abc123' |
| 27 | + /** |
| 28 | + * Required. The value of `gateway_id` can be either the device numeric ID or the |
| 29 | + * user-defined device identifier. |
| 30 | + */ |
| 31 | + // const gatewayId = 'abc123' |
| 32 | + /** |
| 33 | + * Required. The device to associate with the specified gateway. The value of |
| 34 | + * `device_id` can be either the device numeric ID or the user-defined device |
| 35 | + * identifier. |
| 36 | + */ |
| 37 | + // const deviceId = 'abc123' |
| 38 | + |
| 39 | + // Imports the Iot library |
| 40 | + const {DeviceManagerClient} = require('@google-cloud/iot').v1; |
| 41 | + |
| 42 | + // Instantiates a client |
| 43 | + const iotClient = new DeviceManagerClient(); |
| 44 | + |
| 45 | + async function bindDeviceToGateway() { |
| 46 | + // Construct request |
| 47 | + const request = { |
| 48 | + parent, |
| 49 | + gatewayId, |
| 50 | + deviceId, |
| 51 | + }; |
| 52 | + |
| 53 | + // Run request |
| 54 | + const response = await iotClient.bindDeviceToGateway(request); |
| 55 | + console.log(response); |
| 56 | + } |
| 57 | + |
| 58 | + bindDeviceToGateway(); |
| 59 | + // [END cloudiot_v1_generated_DeviceManager_BindDeviceToGateway_async] |
| 60 | +} |
| 61 | + |
| 62 | +process.on('unhandledRejection', err => { |
| 63 | + console.error(err.message); |
| 64 | + process.exitCode = 1; |
| 65 | +}); |
| 66 | +main(...process.argv.slice(2)); |
0 commit comments