forked from Azure/azure-iot-sdk-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
device_method.js
25 lines (20 loc) · 846 Bytes
/
device_method.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
'use strict';
var Client = require('azure-iothub').Client;
var connectionString = '<Hub Connection String>';
var targetDevice = '<Device Id>';
var methodParams = {
methodName: '<Method Name>',
payload: '[Method Payload]',
responseTimeoutInSeconds: 15 // set response timeout as 15 seconds
};
var client = Client.fromConnectionString(connectionString);
client.invokeDeviceMethod(targetDevice, methodParams, function (err, result) {
if (err) {
console.error('Failed to invoke method \'' + methodParams.methodName + '\': ' + err.message);
} else {
console.log(methodParams.methodName + ' on ' + targetDevice + ':');
console.log(JSON.stringify(result, null, 2));
}
});