Azure iot edge 没有';t设法调用Azure IoT边缘模块直接方法
我正在运行IoT边缘模块,并已注册方法回调 SetMethodHandlerAsync和SetMethodDefaultHandlerAsync 但两者都不被称为 从Azure门户发起直接消息调用 调用设备方法失败:{“消息”:“设备{\”消息:\\:\“{\”错误代码\\”:404103,\\“trackingId\\”:\\“126e3eef616c409385e73128aef94b21-G:17时间戳:08/23/2018 12:29:35\”,\\“消息\\”:\“等待设备连接超时。\\”,\\“信息\\”:{\\“:\\ \”:{\\”:\“超时\\”:\“00:00:10\,\,\\“UTC时间戳:\”,\\“UTC:2018-08-2322:2329\”,\\”14z\”例外消息\“:\“\”}未注册“} 来自VsCode 调用直接方法失败:找不到 我是否错过了设置任何必需的配置?Azure iot edge 没有';t设法调用Azure IoT边缘模块直接方法,azure-iot-edge,Azure Iot Edge,我正在运行IoT边缘模块,并已注册方法回调 SetMethodHandlerAsync和SetMethodDefaultHandlerAsync 但两者都不被称为 从Azure门户发起直接消息调用 调用设备方法失败:{“消息”:“设备{\”消息:\\:\“{\”错误代码\\”:404103,\\“trackingId\\”:\\“126e3eef616c409385e73128aef94b21-G:17时间戳:08/23/2018 12:29:35\”,\\“消息\\”:\“等待设备连接超时。\
是否有要指定的命名约定或路径?从VS代码似乎调用了设备而不是模块的方法,因为它不需要输入模块id 从Azure门户,它为我工作 注册方法和实现方法回调:
static async Task Init()
{
AmqpTransportSettings amqpSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only);
ITransportSettings[] settings = { amqpSetting };
// Open a connection to the Edge runtime
ModuleClient ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings);
await ioTHubModuleClient.OpenAsync();
Console.WriteLine("IoT Hub module client initialized.");
await ioTHubModuleClient.SetMethodHandlerAsync("Write", WriteConsole, null);
Console.WriteLine("IoT Hub module Set Method Handler:WriteConsole.");
// Register callback to be called when a message is received by the module
await ioTHubModuleClient.SetInputMessageHandlerAsync("input1", PipeMessage, ioTHubModuleClient);
}
private static Task<MethodResponse> WriteConsole(MethodRequest methodRequest, object userContext)
{
return Task.Run( () => {
Console.WriteLine($"Write direct method called!");
return new MethodResponse(200);
});
}
来自门户的错误:
但在错误消息中,有“未注册”信息。您的模块似乎未连接到边缘设备或从未成功运行
因此,您需要做的第一件事是检查模块日志,看看是否有任何错误。使用以下命令(替换模块名而不是“TestDirectMethodModule”):
使用以下命令检查所有模块的运行状态:
Stop-Service iotedge -NoWait
iotedge list
如果所有模块都成功运行,您将看到以下结果:
来自VS的代码似乎对设备而不是模块调用了方法,因为它不需要输入模块id 从Azure门户,它为我工作 注册方法和实现方法回调:
static async Task Init()
{
AmqpTransportSettings amqpSetting = new AmqpTransportSettings(TransportType.Amqp_Tcp_Only);
ITransportSettings[] settings = { amqpSetting };
// Open a connection to the Edge runtime
ModuleClient ioTHubModuleClient = await ModuleClient.CreateFromEnvironmentAsync(settings);
await ioTHubModuleClient.OpenAsync();
Console.WriteLine("IoT Hub module client initialized.");
await ioTHubModuleClient.SetMethodHandlerAsync("Write", WriteConsole, null);
Console.WriteLine("IoT Hub module Set Method Handler:WriteConsole.");
// Register callback to be called when a message is received by the module
await ioTHubModuleClient.SetInputMessageHandlerAsync("input1", PipeMessage, ioTHubModuleClient);
}
private static Task<MethodResponse> WriteConsole(MethodRequest methodRequest, object userContext)
{
return Task.Run( () => {
Console.WriteLine($"Write direct method called!");
return new MethodResponse(200);
});
}
来自门户的错误:
但在错误消息中,有“未注册”信息。您的模块似乎未连接到边缘设备或从未成功运行
因此,您需要做的第一件事是检查模块日志,看看是否有任何错误。使用以下命令(替换模块名而不是“TestDirectMethodModule”):
使用以下命令检查所有模块的运行状态:
Stop-Service iotedge -NoWait
iotedge list
如果所有模块都成功运行,您将看到以下结果:
是的,我无意中从设备级别调用了门户中的直接方法-无法工作…@FrankPfattheicher很高兴听到您发现了问题。那么,您是否成功地从模块级别调用了直接方法?谢谢您的解决方案。在我们的例子中,我认为从MqttTransportSettings更改为AMQPTTransportSettings解决了这个问题。从设备级别调用direct方法不起作用,而是在模块级别。是的,我意外地从设备级别调用了门户中的direct方法-无法工作…@FrankPfattheicher很高兴听到您发现了这个问题。那么,您是否成功地从模块级别调用了直接方法?谢谢您的解决方案。在我们的例子中,我认为从MqttTransportSettings更改为AMQPTTransportSettings解决了这个问题。从设备级别调用direct方法不起作用,而是在模块级别。