【问题标题】:Didn't manage to call Azure IoT Edge module direct method无法调用 Azure IoT Edge 模块直接方法
【发布时间】:2018-08-23 12:32:26
【问题描述】:

我正在运行 IoT 边缘模块并已注册方法回调。

SetMethodHandlerAsync 和 SetMethodDefaultHandlerAsync

但两者都没有被调用...

从 Azure 门户发起直接消息调用

调用设备方法失败:{"message":"Device {\"Message\":\"{\\"errorCode\\":404103,\\"trackingId\\":\\"126e3eef616c409385e73128aef94b21-G :17-TimeStamp:08/23/2018 12:29:35\\",\\"message\\":\\"等待设备连接超时。\\",\\"info\\": {\\"timeout\\":\\"00:00:10\\"},\\"timestampUtc\\":\\"2018-08-23T12:29:35.2214374Z\\"}\", \"ExceptionMessage\":\"\"} 未注册"}

来自 VsCode

调用直接方法失败:未找到

我是否错过了设置任何必需的配置?
是否有命名约定或要指定的路径?

【问题讨论】:

    标签: azure-iot-edge


    【解决方案1】:

    从 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
    

    如果所有模块运行成功,您将看到以下结果:

    【讨论】:

    • 是的,我不小心从设备级别调用了门户中的直接方法 - 无法正常工作....
    • @FrankPfattheicher 很高兴听到您发现问题。那么你从模块级别调用direct方法成功了吗?
    • 感谢您的解决方案。在我们的例子中,我认为从 MqttTransportSettings 更改为 AmqpTransportSettings 解决了这个问题。
    • 从设备级别调用直接方法不起作用,但模块级别。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多