forked from Azure/azure-iot-sdk-node
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodule_method.js
27 lines (21 loc) · 877 Bytes
/
module_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
26
27
// 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 = "[IoT Hub Connection String]";
var deviceId = '[Device ID]';
var moduleId = '[Module ID]';
var methodParams = {
methodName: '<Method Name>',
payload: '[Method Payload]',
responseTimeoutInSeconds: 15 // set response timeout as 15 seconds
};
var client = Client.fromConnectionString(connectionString);
client.invokeDeviceMethod(deviceId, moduleId, methodParams, function (err, result) {
if (err) {
console.error('Failed to invoke method \'' + methodParams.methodName + '\': ' + err.message);
} else {
console.log(methodParams.methodName + ' on ' + deviceId + ':');
console.log(JSON.stringify(result, null, 2));
}
});