azure-iot-edge - 无法调用 Azure IoT Edge 模块直接方法
问题描述
我正在运行物联网边缘模块并已注册方法回调。
SetMethodHandlerAsync 和 SetMethodDefaultHandlerAsync
但两者都没有被称为...
从 Azure 门户发起直接消息呼叫
调用设备方法失败:{"message":"Device {\"Message\":\"{\\"errorCode\\":404103,\\"trackingId\\":\\"126e3eef616c409385e73128aef94b21-G:17-时间戳:08/23/2018 12:29:35\\",\\"message\\":\\"等待设备连接超时。\\",\\"info\\":{\\ "timeout\\":\\"00:00:10\\"},\\"timestampUtc\\":\\"2018-08-23T12:29:35.2214374Z\\"}\",\"ExceptionMessage \“:\“\“} 未注册”}
来自 VsCode
调用直接方法失败:未找到
我错过了设置任何必需的配置吗?
是否有命名约定或要指定的路径?
解决方案
从 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);
});
}
当我使用以下命令停止模块时,出现“等待设备连接超时”错误:
Stop-Service iotedge -NoWait
来自门户的错误:
但是在您的错误消息中,有“未注册”信息。您的模块似乎未连接到边缘设备或从未成功运行。
因此,您需要做的第一件事是检查模块日志并查看是否有任何错误。使用以下命令(替换您的模块名称而不是“TestDirectMethodModule”):
docker logs TestDirectMethodModule -f
使用以下命令检查所有模块的运行状态:
iotedge list
如果所有模块成功运行,您将看到以下结果:
推荐阅读
- javascript - 如何在 Mongoose 中找到与数组字段的最后一个元素与给定查询值匹配的所有文档?
- php - 如何按属性 LARAVEL 对全局范围进行排序
- javascript - Vee-validate 验证禁用字段
- string - Boot.Locale 的“线性/连续文本块”是什么意思?
- dax - DAX 查询 countdistinct
- python - numpe.zeros 错误 0 正在被转换
- python - 使用 numpy 实现微分矩阵时出错
- html - Windows 上的水平正文溢出,但不是 macOS
- java - Java JDBC - 找不到合适的驱动程序
- docker - Flask + Nginx 反向代理拒绝在 docker 容器中连接