0

对于一个简单的测试,我在quickstart之后创建了一个 Linux 设备。

然后我尝试通过 Azure 门户 tempSensor 模块调用“重置”直接方法。我收到以下错误:

Failed to invoke device method: {"message":"Device {\"Message\":\"{\\\"errorCode\\\":404103,\\\"trackingId\\\":\\\"cc24992d14d44a498e65d1430907066c-G:2-TimeStamp:07/17/2018 16:52:44\\\",\\\"message\\\":\\\"Timed out waiting for device to connect.\\\",\\\"info\\\":{\\\"timeout\\\":\\\"00:00:10\\\"},\\\"timestampUtc\\\":\\\"2018-07-17T16:52:44.3400692Z\\\"}\",\"ExceptionMessage\":\"\"} not registered"}

设备已连接并将数据发送到 IoT 中心。

然后,我使用专有代码创建了第二个设备,并且也无法获得适用于模块的直接方法。

我不确定的一些事情可以提供答案:

  1. 是否需要从 $upstream 到接受直接方法的模块的路线?
  2. 门户网站调用模块的直接方法是否存在问题?
  3. 以下代码仍然是在模块上调用直接方法的有效方法吗?

    var serviceClient = ServiceClient.CreateFromConnectionString(connectionString); var writeMessageMethod = new CloudToDeviceMethod("command"); serviceClient.InvokeDeviceMethodAsync(deviceId, moduleId, writeMessageMethod).Wait();

4

1 回答 1

0

目前,

C# 预览版 SDK支持使用模块 ID 调用直接方法。为此,请使用 ServiceClient.InvokeDeviceMethodAsync() 方法并将 deviceId 和 moduleId 作为参数传入。

参考“ IoT Edge 模块的方法调用

所以从 Azure 门户似乎不支持。

是否需要从 $upstream 到接受直接方法的模块的路线?

没必要。

门户网站调用模块的直接方法是否存在问题?

您需要从模块中调用直接方法并使用上面提到的 C# 预览 SDK。所以从门户网站似乎还不支持。

以下代码仍然是在模块上调用直接方法的有效方法吗?

var serviceClient = ServiceClient.CreateFromConnectionString(connectionString); 
var writeMessageMethod = new CloudToDeviceMethod("command");     
serviceClient.InvokeDeviceMethodAsync(deviceId, moduleId, writeMessageMethod).Wait();

是的,代码是正确的。但请注意,如果您将直接方法命名为“command”,则需要调用“command”而不是“reset”。

参考“ Azure IoT Edge V2 - 直接方法调用示例(目前仅限 Linux) ”。

于 2018-07-18T06:49:06.070 回答