Hi @Florian Cartier Greetings! Welcome to Microsoft Q&A forum. Thank you for posting the question here.
Here is a code that I have tested and could successfully invoke the direct method on a device from Node.js code
'use strict';
const connectionString = '<Connection string>';
const serviceClient = iothub.Client.fromConnectionString(connectionString);
const methodName = 'reboot';
const payload = { input1: 'someInput', input2: 'anotherInput'};
serviceClient.invokeDeviceMethod('TestDevice4', { methodName, payload }, (err, result) => {
if (err) {
console.error('Failed to invoke method: ' + err.message);
} else {
console.log('Method response:');
console.log(JSON.stringify(result, null, 2));
}
});
I have used the Service
policy connection string of IoT Hub in this code and here is the output I get from the code as I execute it.
Hope this helps. Please let us know if you have any additional questions or need further assistance.
If the response helped, please do click Accept Answer and Yes for the answer provided. Doing so would help other community members with similar issue identify the solution. I highly appreciate your contribution to the community.