Azure IoT Edge自定义模块未连接到IoT中心容器

时间:2018-06-22 10:54:13

标签: python azure-iot-hub azure-iot-edge

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

我想根据Microsoft教程here将Windows PC作为“边缘设备”连接到Azure IoT中心。当我只运行Microsoft仓库中作为映像提供的“ temperatureSensor”模块时,一切工作都很好。模块运行后,连接到集线器容器,该集线器容器将数据发送到天蓝色的集线器。

下一步是编写自定义模块。在Microsoft网站上也有一个针对该教程的教程,该教程提供了可用于任何目的的C#和Python模板。我尝试了两个示例(C#和Python),但只有C#版本可以正常工作,没有任何其他问题。但是由于我不太精通C#,只有Python,所以我也需要同时运行它。

但是下载图像并启动容器后不久,Python版本就会失败。 edgeAgent和edgeHub以及Mock-“ temperatureSensor”模块的运行都像以前一样没有问题。但是自定义python模块似乎无法连接到集线器容器。泊坞窗日志如下:

edgeAgent:

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:

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#版本完全兼容(在其他情况下)。或者这可能是防火墙问题。我真的不这么认为,因为过滤器日志指示MQTT问题。据我了解,MQTT仅适用于内部边缘设备流量,不适用于传出流量(docker和设备外部)。因此,防火墙应该不成问题(?) 实际的问题显然是等待集线器确认连接的超时。因此,集线器无法获取连接请求或不进行答复,或者答复丢失了。

感谢所有帮助。

3 个答案:

答案 0 :(得分:0)

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

  • 您可以在Linux容器上运行
  • 您可以在Linux机器或VM上运行
  • 不久将添加更多语言支持-您可以在azure-iot-sdk-nodeazure-iot-sdk-java的模块预览分支中查看我们的进度

答案 1 :(得分:0)

Linux Edge设备上使用 Linux容器时,我遇到了同样的问题。我的所有模块都是用 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

如果有人有更好的主意,我也想通过适当的方式解决它...?

答案 2 :(得分:0)

自从这篇文章发表以来,我也有机会与一位微软人士就一项公约进行了交谈。当我们尝试复制问题时,事实证明整个过程在前一天已更改。 iodedgectl现在是Windows服务(据我之前所说,它只是一个常规过程[有意义吗?])

无论如何:此刻整个IoT边缘似乎都已得到了彻底修改。因此,根据我的经验,很多事情都会改变,我乐观地认为,下次我尝试教程时,一切都会很好。我正在关闭此线程。