0

我的问题可能与这篇文章相同,但我不了解那些花哨的大城市 stackoverflow 政治,所以我不想打扰任何人,只是问我自己的问题。

我想根据此处的 Microsoft 教程将我的 Windows PC 作为“边缘设备”连接到我的 Azure IoT Hub 。当我只运行作为 Microsoft 存储库中的图像的“温度传感器”模块时,一切正常。模块运行,连接到集线器容器,将数据发送到天蓝色集线器。

下一步是编写自定义模块。Microsoft 网站上还有一个教程,它提供了 C# 和 Python 的模板,可以针对任何目的进行修改。我尝试了两个示例(C# 和 Python),但只有 C#-Version 没有任何进一步的问题。但由于我不是很精通 C#,只精通 Python,所以我也需要运行那个。

但是 Python 版本在下载图像并启动容器后不久就失败了。edgeAgent 和 edgeHub 以及模拟“温度传感器”模块像以前一样运行没有问题。但是自定义 python 模块似乎无法连接到集线器容器。码头工人日志如下:

边缘代理:

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

边缘枢纽:

2018-06-22 10:26:14.438 +00:00 [INF] - Attempting to connect to IoT Hub for client xxxdevice/filterModule via AMQP over WebSocket...
2018-06-22 10:26:14.439 +00:00 [INF] - New token requested by client xxxdevice/filterModule, but using existing token as it is usable.
2018-06-22 10:26:14.789 +00:00 [INF] - Connected to IoT Hub for client xxxdevice/filterModule via AMQP over WebSocket, with client operation timeout 60000.
2018-06-22 10:26:14.793 +00:00 [INF] - Closed cloud proxy for device xxxdevice/filterModule
2018-06-22 10:26:14.793 +00:00 [INF] - No session state found in store for xxxdevice/filterModule
2018-06-22 10:26:14.793 +00:00 [INF] - New cloud connection created for device xxxdevice/filterModule
2018-06-22 10:26:14.793 +00:00 [INF] - Successfully authenticated device xxxdevice/filterModule
2018-06-22 10:26:14.793 +00:00 [INF] - Successfully generated identity for clientId xxxdevice/filterModule and username xxx-iothub.azure-devices.net/xxxdevice/filterModule/api-version=2016-11-14&DeviceClientType=iothubclient%2f1.1.31%20(native%3b%20Linux%3b%20x86_64)
2018-06-22 10:26:14.793 +00:00 [INF] - ClientAuthenticated, xxxdevice/filterModule, 084e3167
2018-06-22 10:28:26.580 +00:00 [INF] - Attempting to connect to IoT Hub for client xxxdevice/filterModule via AMQP...
2018-06-22 10:29:26.583 +00:00 [INF] - Attempting to connect to IoT Hub for client xxxdevice/filterModule via AMQP over WebSocket...
2018-06-22 10:29:26.584 +00:00 [INF] - New token requested by client xxxdevice/filterModule, but using existing token as it is usable.
2018-06-22 10:29:26.918 +00:00 [INF] - Connected to IoT Hub for client xxxdevice/filterModule via AMQP over WebSocket, with client operation timeout 60000.
2018-06-22 10:29:26.919 +00:00 [INF] - Closed cloud proxy for device xxxdevice/filterModule
2018-06-22 10:29:26.923 +00:00 [INF] - No session state found in store for xxxdevice/filterModule
2018-06-22 10:29:26.923 +00:00 [INF] - New cloud connection created for device xxxdevice/filterModule
2018-06-22 10:29:26.924 +00:00 [INF] - Successfully authenticated device xxxdevice/filterModule
2018-06-22 10:29:26.924 +00:00 [INF] - Successfully generated identity for clientId xxxdevice/filterModule and username xxx-iothub.azure-devices.net/xxxdevice/filterModule/api-version=2016-11-14&DeviceClientType=iothubclient%2f1.1.31%20(native%3b%20Linux%3b%20x86_64)
2018-06-22 10:29:26.924 +00:00 [INF] - ClientAuthenticated, xxxdevice/filterModule, 126cb7eb
2018-06-22 10:31:33.659 +00:00 [ERR] - Module filterModule is not connected

筛选:

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

这是无限重复的。集线器似乎确实注意到了过滤器,但身份验证成功,但访问仍然被拒绝。这可能是 Python SDK 中的一个错误,因为正如我所说,它在 C#-Version 中工作得非常好(在其他相同的情况下)。还是有可能是防火墙问题。我真的不这么认为,因为过滤器日志表明存在 MQTT 问题。据我了解,MQTT 仅适用于内部边缘设备流量,而不适用于传出流量(docker 和设备外部)。所以防火墙应该不是问题(?)实际问题显然是等待集线器确认连接的超时。因此,集线器要么没有收到连接请求,要么没有回复,要么回复以某种方式丢失。

感谢您提前提供的所有帮助。

4

3 回答 3

0

我在Linux Edge Device上使用Linux Containers时遇到了同样的问题。我所有的模块都是用Python编写的,除了一个是Azure Stream Analytics

为了解决这个问题,我不得不卸载 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

如果有人有更好的主意,我也对解决它的正确方法感兴趣......?

于 2018-06-28T15:18:26.813 回答
0

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

无论如何:目前整个 iot-edge 似乎都进行了大修。因此,根据我的经验,很多事情都会发生变化,我很乐观,下次我尝试这些教程时,一切都会好起来的。我正在关闭这个线程。

于 2018-07-06T09:53:34.007 回答
0

我假设您正在尝试在 Windows Edge 设备上运行 Windows 容器。当前不支持 Windows 容器上的 Python(和 C)自定义模块。这与我们存储和检索密钥的方式有关。这个功能肯定在路线图上,尽管我们目前没有任何 ETA。有几种方法可以解决这个问题:

于 2018-06-25T05:47:46.110 回答