我正在使用 Azure IoT 中心并将一个自定义模块部署到边缘设备。 5 个模块中有 4 个看起来不错。其中一个在设置模块区域部署成功后消失。
这个模块只不过是一个带有 UI 的 C++ 可执行文件,我们将其部署为 IoT 边缘设备中的容器
问题: 基于 UI 的客户模块已部署,但在成功运行后从设置模块中消失。
设置:Ubuntu 22.04。
运行时:Docker 和 Azure IoT Edge 运行时
已安装: x11 和 x Server 作为我们基于容器的 exe 运行,有 UI 可以显示
重现步骤:
我正在执行以下步骤来重现该问题。
在 IoT 中心 >> 单击“设置模块”>> 单击“添加 IoT 边缘模块”
指定模块名称和容器镜像URL
环境设置:添加DISPLAY,值为:0
创建选项
{
"HostConfig": {
"Binds": [
"/dev/mem:/dev/mem",
"/dev/gpiomem:/dev/gpiomem"
],
"Mounts": [
{
"Source": "/dev",
"Target": "/dev",
"Type": "bind"
},
{
"Source": "/tmp",
"Target": "/tmp",
"Type": "bind"
},
{
"Source": "/tmp/.X11-unix",
"Target": "/tmp/.X11-unix",
"Type": "bind"
}
],
"NetworkMode": "host",
"Privileged": true
},
"Env": [
"DISPLAY=:0"
],
"NetworkingConfig": {
"EndpointsConfig": {
"host": {}
}
},
}
3.现在这已成功部署到边缘设备。我可以看到边缘设备上正在运行的 UI。
在 IoT 中心的 Azure 门户上,我可以看到模块正在运行
现在,如果我转到“设置模块”,我希望它列在那里。 但这个模块不可见。
我正在部署其他模块,这些模块始终可见,但不是这个特定模块。
任何帮助将不胜感激。
我期待看到设置模块列表中的自定义模块与所有其他模块代理和集线器相同。
自定义模块已部署但在成功运行后从“设置模块”部分消失的主要原因是由于部署清单中的规范被设置为“否”。当映像配置不正确或模式、路由或绑定敏感主机路径存在问题时,就会出现此问题。
请参阅此 MSDOC使用 Visual Studio Code 开发 Azure IoT Edge 模块。 这里的关键变化是
Privileged
的结构如何包含自定义模块,类似于
deployment manifest
和 edgeAgent
模块。这可确保模块的配置在 edgeHub
和 properties
方面正确无误。下面是使用 mount points
模块的部署清单的 IoT Edge 自定义模块示例:
SimulatedTemperatureSensor
要部署
{
"content": {
"modulesContent": {
"$edgeAgent": {
"properties.desired": {
"schemaVersion": "1.1",
"runtime": {
"type": "docker",
"settings": {
"minDockerVersion": "v1.25",
"loggingOptions": "",
"registryCredentials": {}
}
},
"systemModules": {
"edgeAgent": {
"type": "docker",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-agent:1.5",
"createOptions": "{}"
}
},
"edgeHub": {
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-hub:1.5",
"createOptions": "{\"HostConfig\":{\"PortBindings\":{\"5671/tcp\":[{\"HostPort\":\"5671\"}],\"8883/tcp\":[{\"HostPort\":\"8883\"}],\"443/tcp\":[{\"HostPort\":\"443\"}]}}}"
}
}
},
"modules": {
"SimulatedTemperatureSensor": {
"version": "1.0",
"type": "docker",
"status": "running",
"restartPolicy": "always",
"settings": {
"image": "mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.5",
"createOptions": "{}"
}
}
}
}
},
"$edgeHub": {
"properties.desired": {
"schemaVersion": "1.1",
"routes": {
"upstream": "FROM /messages/* INTO $upstream"
},
"storeAndForwardConfiguration": {
"timeToLiveSecs": 7200
}
}
},
"SimulatedTemperatureSensor": {
"properties.desired": {
"SendData": true,
"SendInterval": 5
}
}
}
}
}
,请使用以下 Azure CLI 命令:
deployment manifest
部署az iot edge set-modules --device-id [device id] --hub-name [hub name] --content [file path]
。
请参阅此 MSDOC用户界面步骤:
登录 azure UI>> IoT 中心 >> 单击“设置模块”>> 单击“添加 IoT 边缘模块”。
我使用图像 URI
deployment manifest
为 IoT Edge 自定义模块添加了一个具有 IoT 模块名称
SimulatedTemperatureSensor
的示例模拟温度图像。此外,我添加了一条名为 mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:latest
的路由,该路由将来自模拟温度模块的所有消息发送到 IoT 中心,其值为 SimulatedTemperatureSensorToIoTHub
。