[使用Visual Studio调试模块时如何与Azure IoT边缘模块和模块Twin交互

问题描述 投票:0回答:1

我已经设置了Azure IoT Edge模块,并且在通过Azure将其部署到IoT Edge Runtime时,它工作得很好。

但是,在本地调试模块时,我找不到与模块交互的方法。我需要做的是在其上调用直接方法并在模块twin运行时对其进行修改。

另外,我有一个问题:本地调试模块实际上连接到哪里?是否使用Visual Studio的“ IoT Edge工具”中配置的连接字符串打开与Azure IoT Edge设备的连接?至少看起来不是这样,因为它不会从Azure IoT中心读取Module Twin的设置。

[其他问题:在Visual Studio中的Edge解决方案上,当我右键单击Project Node时,可以将“ Build and Push the Module”“构建并推送到Azure Container Registry,并在模拟器中运行它。我认为在模拟器中运行它与调试它不一样吗?

非常感谢!

azure-iot-edge
1个回答
0
投票

在Visual Studio中调试模块时,模板以单模块模式启动iotedgehubdev(即模拟器)。

使用这种模式,您可以通过REST API将消息发送到模块

curl --header "Content-Type: application/json" --request POST --data '{"inputName": "<input_name>","data":"hello world"}' http://localhost:53000/api/v1/messages

它也会启动您的模块并将其命名为“ target”

iotedgehubdev modulecred -l -m "target"
   EdgeHubConnectionString=HostName=<hostname>;GatewayHostName=localhost;DeviceId=<your-edge-device-id>;ModuleId=target;SharedAccessKey=<key>
   EdgeModuleCACertificateFile=C:\ProgramData\iotedgehubdev\data\certs\edge-device-ca\cert\edge-device-ca.cert.pem

模块目标可在azure门户-iothub中访问。您可以使用该接口来调用方法并更改孪生模块enter image description here

最后,在模拟器中运行与调试不同。当您使用该命令时,VS在模式模拟器中运行iotedgehubdev,它将运行部署文件中的所有模块并应用路由,配置等。

您仍然可以调试模块,但是必须使用远程调试器,这是另一个主题。

© www.soinside.com 2019 - 2024. All rights reserved.