원격 명령 처리
IoT hub 의 direct method 를 사용한 원격 명령 처리 방법을 설명합니다.
function main() {
client = Client.fromConnectionString(deviceConnectionString, Protocol);
client.open(onConnect);
}
function onConnect(err) {
if(!!err) {
console.error('Could not connect: ' + err.message);
} else {
console.log('Connected');
// Direct method 인터페이스를 등록하고, 핸들러 펑션을 지정하고 있다.
client.onDeviceMethod('reboot', onReboot);
}
}
function onReboot(request, response) {
console.log('다이렉트 메소드 실행');
// complete the response
response.send(200, '실행 완료', function(err) {
if(!!err) {
console.error('error' + err.toString());
} else {
console.log('successfully.' );
}
});
}
main();Last updated