集成Dunfell分支的IoT Edge到Yocto镜像 (Integrate Dunfell branch IoT Edge to Yocto Image)
前面提到搭建了WSL2来编译Yocto image, 那这里就大概说一下,在集成Dunfell branch的IoT Edge时候遇到的问题,以及如何解决这些问题来编译Yocto的镜像。
在Yocto上要集成IoT Edge的话,需要添加meta-iotedge层,参见 https://github.com/Azure/meta-iotedge
因为我们的开发设备用的是Dunfell branch, 所以这里的iotedge也用同样的branch。然而meta-iotedge给出的介绍并不多,除了要添加依赖的layer之外,还有一些配置要修改。另外针对于所要适配的设备,还需要添加额外的配置,例如网络,swap等。这里就不考虑设备的差异了,只关注于IoT Edge部分。
-
获取meta-iotedge以及其依赖的layers
PC $> git clone git://github.com/meta-rust/meta-rust.git
PC $> git clone git://git.yoctoproject.org/meta-virtualization -b dunfell
PC $> git clone git://github.com/openembedded/openembedded-core.git -b dunfell
PC $> git clone https://github.com/Azure/meta-iotedge.git -b dunfell -
在编译镜像的conf/bblayers.config中添加相应的layer, 例如:
PC $> vi conf/bblayers.conf
POKY_BBLAYERS_CONF_VERSION = "2"BBPATH = "${TOPDIR}"
BBFILES ?= ""BSPDIR := "${@os.path.abspath(os.path.dirname(d.getVar('FILE', True)) + '/../../..')}"
BBLAYERS ?= "
${BSPDIR}/poky/meta
${BSPDIR}/poky/meta-poky
${BSPDIR}/poky/meta-yocto-bsp \
${BSPDIR}/meta-openembedded/meta-oe
${BSPDIR}/meta-openembedded/meta-networking
${BSPDIR}/meta-openembedded/meta-webserver
${BSPDIR}/meta-openembedded/meta-python
${BSPDIR}/meta-openembedded/meta-initramfs
${BSPDIR}/meta-openembedded/meta-multimedia
${BSPDIR}/meta-openembedded/meta-filesystems
${BSPDIR}/meta-atmel
${BSPDIR}/meta-aws
${BSPDIR}/meta-rust
${BSPDIR}/meta-virtualization
${BSPDIR}/meta-iotedge
"
通过命令‘bitbake-layers show-layers’可以检查添加的layers是否正确
-
conf/local.conf文件中追加feature:virtualization
DISTRO_FEATURES_append += " virtualization" -
根据你自己的设备修改相应的配置文件,然后编译镜像。
在我们的设备上出现了如下错误:| 3 | #![deny(rust_2018_idioms, warnings)]
| | ^^^^^^^^^^^^^^^^
|
| error: deny(rust_2018_idioms) is ignored unless specified at crate level
那这里只需要在相应的iotedge版本的cli以及daemon中修改对应的.rs文件,删除:
#![deny(rust_2018_idioms, warnings)]
-
在Azure中配置IoT Edge 设备和module
a. 添加SimulatedTemperatureSensor, image url 为: mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.0.9.4-linux-arm32v7
b. Edge Hub Image - mcr.microsoft.com/azureiotedge-hub:1.0.9.4-linux-arm32v7
c. Edge Agent Image - mcr.microsoft.com/azureiotedge-agent:1.0.9.4-linux-arm32v7 -
在你设备上输入编译的镜像,配置IoT edge, 如上述azure iot edge设备的连接字符串, 主机名字, 监听的workload,management等
-
如果运行ok的话,可以看看SimulatedTemperatureSensor的日志,可以看到能否发送数据了
docker logs -f SimulatedTemperatureSensor
[2020-12-07 08:25:47 +00:00]: Starting Module
SimulatedTemperatureSensor Main() started.
Initializing simulated temperature sensor to send 500 messages, at an interval of 5 seconds.
To change this, set the environment variable MessageCount to the number of messages that should be sent (set it to -1 to send unlimited messages).
Information: Trying to initialize module client using transport type [Amqp_Tcp_Only].Information: Successfully initialized module client of transport type [Amqp_Tcp_Only].
12/07/2020 08:39:15> Sending message: 1, Body: [{"machine":{"temperature":21.026835825888828,"pressure":1.0030572459873348},"ambient": {"temperature":21.169012992023031,"humidity":25},"timeCreated":"2020-12-07T08:39:13.2554267Z"}]
12/07/2020 08:39:35> Sending message: 2, Body: [{"machine":{"temperature":22.131411956451558,"pressure":1.1288950330134686},"ambient":{"temperature":20.763105732511313,"humidity":25},"timeCreated":"2020-12-07T08:39:35.0850299Z"}]
12/07/2020 08:39:43> Sending message: 3, Body: [{"machine":{"temperature":23.176592528320192,"pressure":1.2479662374035663},"ambient":{"temperature":21.277855576378226,"humidity":26},"timeCreated":"2020-12-07T08:39:43.731997Z"}] -
查看一下iot edge 的module:
iotedge listNAME STATUS DESCRIPTION CONFIG
SimulatedTemperatureSensor running Up 11 minutes mcr.microsoft.com/azureiotedge-simulated-temperature-sensor:1.0.9.4-linux-arm32v7
edgeAgent running Up 13 minutes mcr.microsoft.com/azureiotedge-agent:1.0.9.4-linux-arm32v7
edgeHub running Up 11 minutes mcr.microsoft.com/azureiotedge-hub:1.0.9.4-linux-arm32v7