Azure IoT Edge自定义模块无法连接到IoT-Hub-Contain

2024-09-30 08:36:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我的问题可能与this post相同,但我不理解那些花哨的大城市堆积如山的政治,所以我不想打扰任何人,只想问我自己的问题。在

根据Microsoft教程here,我想将我的Windows PC作为“边缘设备”连接到我的Azure IoT集线器。当我只运行“temperatureSensor”模块时,一切都工作得非常好,这个模块在Microsoft存储库中是一个映像。模块运行后,连接到集线器容器,该容器将数据发送到azure集线器。在

下一步是编写定制模块。在Microsofts网站上也有一个关于这个的教程,它给出了一个C#和Python的模板,可以对其进行任何修改。我尝试了两个示例(C和Python),但只有C版本可以正常工作,没有任何其他问题。但由于我对C#不是很精通,只有Python,所以我也需要让它运行起来。在

但是Python版本在下载图像并启动容器后不久就会失败。edgeAgent和edgeHub以及模拟的“温度传感器”模块运行时没有出现问题。但是定制python模块似乎无法连接到集线器容器。docker日志如下:

边沿:

2018-06-22 10:28:26.062 +00:00 [INF] - Plan execution started for deployment 8
2018-06-22 10:28:26.062 +00:00 [INF] - Executing command: "Command Group: (
  [docker stop -t 10 filterModule]
  [docker start filterModule]
  [Update health stats for module filterModule]
)"
2018-06-22 10:28:26.062 +00:00 [INF] - Executing command: "docker stop -t 10 filterModule"
2018-06-22 10:28:26.063 +00:00 [INF] - Executing command: "docker start filterModule"
2018-06-22 10:28:26.567 +00:00 [INF] - Executing command: "Update health stats for module filterModule"
2018-06-22 10:28:26.567 +00:00 [INF] - Plan execution ended for deployment 8
2018-06-22 10:28:26.872 +00:00 [INF] - Updated reported properties
2018-06-22 10:28:56.975 +00:00 [INF] - HealthRestartPlanner is clearing restart stats for module 'edgeHub' as it has been running healthy for 00:10:00.
2018-06-22 10:28:56.975 +00:00 [INF] - Plan execution started for deployment 8
2018-06-22 10:28:56.975 +00:00 [INF] - Executing command: "Reset health stats for module edgeHub"
2018-06-22 10:28:56.977 +00:00 [INF] - Plan execution ended for deployment 8
2018-06-22 10:28:57.263 +00:00 [INF] - Updated reported properties
2018-06-22 10:29:02.268 +00:00 [INF] - HealthRestartPlanner is clearing restart stats for module 'tempSensor' as it has been running healthy for 00:10:00.
2018-06-22 10:29:02.268 +00:00 [INF] - Plan execution started for deployment 8
2018-06-22 10:29:02.268 +00:00 [INF] - Executing command: "Reset health stats for module tempSensor"
2018-06-22 10:29:02.268 +00:00 [INF] - Plan execution ended for deployment 8
2018-06-22 10:29:02.571 +00:00 [INF] - Updated reported properties

edgeHub公司:

^{pr2}$

过滤器:

Python 2.7.12 (default, Dec  4 2017, 14:50:18)
[GCC 5.4.0 20160609]

IoT Hub Client for Python
Adding TrustedCerts from: /mnt/edgemodule/edge-device-ca.cert.pem
set_option TrustedCerts successful
Starting the IoT Hub Python sample using protocol MQTT...
The sample is now waiting for messages and will indefinitely.  Press Ctrl-C to exit.
Error: Time:Fri Jun 22 10:28:57 2018 File:/usr/sdk/src/c/iothub_client/src/iothubtransport_mqtt_common.c Func:InitializeConnection Line:2003 mqtt_client timed out waiting for CONNACK

这是无限重复的。似乎集线器确实注意到了过滤器,但是身份验证成功了,但是访问无论如何都被拒绝了。这可能是pythonsdk中的一个bug吗,因为正如我所说的,它可以很好地与C#版本一起工作(在其他相同的场景中)。或者可能是防火墙问题。我不这么认为,因为过滤器日志指示MQTT问题。据我所知,MQTT只适用于内部边缘设备流量,不适用于传出流量(外部docker和设备)。所以防火墙不应该是个问题(?) 实际的问题显然是等待集线器确认连接的超时。因此,要么集线器没有收到连接请求,要么没有回复,要么回复以某种方式丢失。在

提前感谢大家的帮助。在


Tags: 模块dockerforstatsdeployment集线器容器command
3条回答

我假设您正在尝试在您的Windows边缘设备上运行Windows容器。目前不支持Windows容器上的Python(和C)自定义模块。这与我们存储和检索密钥的方式有关。虽然我们目前还没有任何预计到达时间,但这一功能肯定已经在路线图上了。解决这个问题的方法很少:

  • 可以在Linux容器上运行
  • 您可以在Linux机器或vm上运行
  • 更多的语言支持将很快添加-您可以查看我们在azure-iot-sdk-node和{a2}的模块预览分支上的进展

我在Linux边缘设备上使用Linux容器时也遇到了同样的问题。我所有的模块都是用Python编写的,除了一个azurestreamanalytics。在

为了解决这个问题,我不得不卸载azure iot edge runtime ctl。。。 不是一个“正确”的解决方法,但它奏效了! 这是我的剧本:

sudo pip3 uninstall azure-iot-edge-runtime-ctl
sudo pip3 install azure-iot-edge-runtime-ctl
sudo iotedgectl setup  connection-string "<your connection key>"  auto-cert-gen-force-no-password
sudo iotedgectl login  address <your container registry address>  username <your container registry username>  password <your container registry password>
sudo iotedgectl start

如果有人有更好的主意,我也有兴趣用适当的方法来解决它?在

自从这篇文章之后,我也有机会在一个会议上和微软的人交谈。当我们试图复制这个问题时,结果发现整个过程在前一天被改变了。IoEdgeCTL现在是一个Windows服务(据我所知,它“只是”一个常规进程[这有意义吗?])在

总之:整个物联网的边缘目前似乎被彻底检修过。所以根据我的经验,很多事情都会改变,我很乐观,下次我尝试教程时一切都会很好。我要结束这条线了。在

相关问题 更多 >

    热门问题