英文:
IotEdge Invoke a method from a device to the hub
问题
这是我从设备上的中心调用方法的方式,它可以正常工作。
DeviceMethod methodClient = DeviceMethod.createFromConnectionString(iotHubConnectionString);
payload = ...
String methodName = "insertUser";
result = methodClient.invoke(deviceId, methodName, responseTimeout, connectTimeout, payload);
我如何从设备向中心调用方法?(设备 -> 中心)
由于 deviceId 是必填项,我应该放入什么值?
result = methodClient.invoke(deviceId, methodName, responseTimeout, connectTimeout, payload);
我正在使用这两个 Java 库
<dependencies>
<dependency>
<groupId>com.microsoft.azure.sdk.iot</groupId>
<artifactId>iot-device-client</artifactId>
<version>1.17.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure.sdk.iot</groupId>
<artifactId>iot-service-client</artifactId>
<version>1.17.5</version>
</dependency>
</dependencies>
英文:
This way I invoke the methods, from the hub on a device and it works fine.
DeviceMethod methodClient = DeviceMethod.createFromConnectionString(iotHubConnectionString);
payload = ...
String methodName = "insertUser";
result = methodClient.invoke(deviceId, methodName, responseTimeout, connectTimeout, payload);
How can I invoke a method from the device to the hub? (device -> hub)
As deviceId is mandatory, what values shall I put?
result = methodClient.invoke(deviceId, methodName, responseTimeout, connectTimeout, payload);
I am using these 2 Java libraries
<dependencies>
<dependency>
<groupId>com.microsoft.azure.sdk.iot</groupId>
<artifactId>iot-device-client</artifactId>
<version>1.17.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure.sdk.iot</groupId>
<artifactId>iot-service-client</artifactId>
<version>1.17.5</version>
</dependency>
</dependencies>
答案1
得分: 1
直接方法是在您希望从服务端对设备执行特定功能时使用的方法。
根据了解并从IoT Hub调用直接方法中的定义:
> IoT Hub使您能够在云端对设备调用直接方法。直接方法代表与设备之间的请求-响应交互,类似于HTTP调用,它们会立即成功或失败(在用户指定的超时后)。这种方法对于根据设备是否能够响应而决定即时操作的情景非常有用。
因此,不打算从设备本身调用直接方法。
英文:
Direct Methods are used when you want to invoke a specific function on your Device from the Service Side.
From the definition in Understand and invoke direct methods from IoT Hub
> IoT Hub gives you the ability to invoke direct methods on devices from the cloud. Direct methods represent a request-reply interaction with a device similar to an HTTP call in that they succeed or fail immediately (after a user-specified timeout). This approach is useful for scenarios where the course of immediate action is different depending on whether the device was able to respond.
Therefore it is not intended that you call a direct method from the device itself.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论