工控網(wǎng)首頁
>

應用設計

>

NXP iMX8MP ARM 平臺 EMQX 部署測試

NXP iMX8MP ARM 平臺 EMQX 部署測試

1). 簡介

EMQX 是一款基于 Erlang/OTP 平臺開發(fā)的開源 MQTT 消息服務器,廣泛應用于物聯(lián)網(wǎng)IoT)領域,以實現(xiàn)設備到服務器以及服務器到設備的消息傳遞與控制文本就基于 NXP i.MX8M Plus ARM 處理器平臺,通過在 Yocto Linux BSP 中集成 Docker 環(huán)境來部署測試 EMQX。

 

本文所演示的平臺來自于 Toradex Verdin i.MX8MP 嵌入式平臺

 

 

2. 準備

a). Verdin i.MX8MP ARM核心版配合Dahlia 載板,并連接調(diào)試串口用于測試

 

 

3). Verdin i.MX8MP Yocto Linux 編譯部署

a). 首先參考這里說明創(chuàng)建 Yocto/Openembedded 編譯框架,當前最新版本是對應于 Toradex Yocto Linux BSP 7.x 版本的 scarthgap-7.x.y branch

 

b). 增加包含 Docker 支持的 meta-virtualization layer。

-------------------------------

### add meta-virtualization ###

$ cd/layers

$ git clone -b scarthgap git://git.yoctoproject.org/meta-virtualization

 

### add meta-clang layer for PySide6 ###

$ git clone -b kirkstone https://github.com/kraj/meta-clang.git

-------------------------------

 

c). 創(chuàng)建定制化 layer meta-customer-demos ,用于添加 Docker 需要的額外修改和配置,首先添加 layer 配置文件

---------------------------------------

$ mkdir -p ../oe_core/layers/meta-customer-demos/conf

$ cd .../oe_core/layers/meta-customer-demos/conf

### create layer.conf file ###

# We have a conf and classes directory, append to BBPATH

BBPATH .= ":${LAYERDIR}"

 

# We have recipes-* directories, add to BBFILES

BBFILES += "${LAYERDIR}/recipes-*/*/*.bb ${LAYERDIR}/recipes-*/*/*.bbappend"

 

BBFILE_COLLECTIONS += "customer-demos"

BBFILE_PATTERN_customer-demos = "^${LAYERDIR}/"

BBFILE_PRIORITY_customer-demos = "24"

 

# Let us add layer-specific bbappends which are only applied when that

# layer is included in our configuration

BBFILES += "${@' '.join('${LAYERDIR}/%s/recipes*/*/*.bbappend' % layer \

               for layer in BBFILE_COLLECTIONS.split())}"

# Add layer-specific bb files too

BBFILES += "${@' '.join('${LAYERDIR}/%s/recipes*/*/*.bb' % layer \

               for layer in BBFILE_COLLECTIONS.split())}"

 

LAYERDEPENDS_customer-demos = " \

    core \

    yocto \

    openembedded-layer gnome-layer multimedia-layer networking-layer \

"

LAYERSERIES_COMPAT_customer-demos = "hardknott honister kirkstone scarthgap"

---------------------------------------

 

d). 在定制化 layer meta-customer-demos 下面添加 Docker bbapend 文件,配置 Docker 可以啟動自動加載

---------------------------------------

$ cd .../oe_core/layers/meta-customer-demos/

mkdir -p recipes-containers/docker

$ cd recipes-containers/docker

### cteate docker-moby_git.bbappend file ###

FILES:${PN} += "${sysconfdir}/systemd/system/docker.service"

 

SYSTEMD_SERVICE:${PN} = "docker.service"

SYSTEMD_AUTO_ENABLE:${PN} = "enable"

---------------------------------------

 

e). Docker daemon 啟動需要額外比如 IPSec/Netfilter/NF_table 等網(wǎng)絡相關的 Kernel Modules,因此如下增加額外的 Linux Kernel 配置。

---------------------------------------

$ cd .../oe_core/layers/meta-customer-demos/

mkdir -p recipes-kernel/linux/

$ cd recipes-kernel/linux

### cteate linux-toradex%.bbappend file ###

SRCREV_meta-custom = "1e293f75e7e5569f0d86d752fbf4180dd3fac6eb"

SRCREV_meta-custom:use-head-next = "${AUTOREV}"

 

KMETABRANCH = "scarthgap-7.x.y"

KMETAVIRTUALITION = "kernel-meta-custom"

 

KMETAREPOSITORY="github.com/toradex/toradex-kernel-cache.git"

KMETAPROTOCOL="https"

 

SRC_URI += "git://${KMETAREPOSITORY};protocol=${KMETAPROTOCOL};type=kmeta;name=meta-custom;branch=${KMETABRANCH};destsuffix=${KMETAVIRTUALITION}"

 

## Compose additional .scc file including docker requirement and include it to our build.

KERNEL_FEATURES += "bsp/${MACHINE}-${LINUX_KERNEL_TYPE}-torizon.scc"

---------------------------------------

 

f). 最終完整 meta-customer-demos layer 文件結構如下

meta-customer-demos

├── conf

│   └── layer.conf

├── recipes-containers

│   └── docker

│       └── docker-moby_git.bbappend

└── recipes-kernel

    └── linux

        └── linux-toradex%.bbappend

 

 

g). 修改 bblayers.conf 和 local.conf 文件

-------------------------------

### modify bblayer.conf ###

--- a/build/conf/bblayers.conf  

+++ b/build/conf/bblayers.conf  

@@ -34,7 +34,7 @@

   ${TOPDIR}/../layers/meta-openembedded/meta-python \

   ${TOPDIR}/../layers/meta-freescale-distro \

   ${TOPDIR}/../layers/meta-toradex-demos \

+  ${TOPDIR}/../layers/meta-virtualization \

+  ${TOPDIR}/../layers/meta-customer-demos \

   \

   \

   ${TOPDIR}/../layers/meta-toradex-distro \

 

### add below to local.conf ###

# enable meta-virtualization

DISTRO_FEATURES:append = " virtualization"

 

# enable docker support

IMAGE_INSTALL:append = " docker docker-compose"

 

# add Freescale EULA

ACCEPT_FSL_EULA = "1"

-------------------------------

 

h). 編譯 Yocto Linux image

-------------------------------

### compile Reference-Multimedia image ###

$ MACHINE="verdin-imx8mp" bitbake tdx-reference-multimedia-image

-------------------------------

 

i). Yocto Linux image部署

參考這里通過Toradex Easy installer將上面編譯好的image更新部署到模塊

 

 

4). EMQX 部署測試

a). 關于 EMQX 的更多說明和介紹可以參考如下

https://docs.emqx.com/en/emqx/latest/getting-started/getting-started.html

 

b). 在 Verdin i.MX8MP 設備上面通過如下命令確認 Docker daemon 已經(jīng)成功運行

-------------------------------

root@verdin-imx8mp-06849028:~# systemctl is-enabled docker.service

enabled

root@verdin-imx8mp-06849028:~# systemctl status docker.service                                

* docker.service - Docker Application Container Engine

     Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled)

     Active: active (running) since Fri 2025-03-28 01:54:37 UTC; 5h 16min ago

TriggeredBy: * docker.socket

       Docs: https://docs.docker.com

   Main PID: 685 (dockerd)

      Tasks: 19

     Memory: 99.6M (peak: 146.5M)

        CPU: 14.376s

     CGroup: /system.slice/docker.service

             `-685 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

 

...

Mar 28 01:54:37 verdin-imx8mp-06849028 dockerd[685]: time="2025-03-28T01:54:37.583078000Z" level=info msg="Daemon has completed initialization"

Mar 28 01:54:37 verdin-imx8mp-06849028 dockerd[685]: time="2025-03-28T01:54:37.684308375Z" level=info msg="API listen on /run/docker.sock"

Mar 28 01:54:37 verdin-imx8mp-06849028 systemd[1]: Started Docker Application Container Engine.

-------------------------------

 

c). 參考這里通過如下命令安裝并運行 EMQX ARM64 Docker Image,本文采用 offline 方式,如果網(wǎng)絡條件允許也可以 online 方式安裝。

-------------------------------

### download

wget https://www.emqx.com/en/downloads/broker/5.8.6/emqx-5.8.6-docker-arm64.tar.gz

### install

$ docker load < emqx-5.8.6-docker-arm64.tar.gz

###

$ docker run -d --name emqx -p 1883:1883 -p 8083:8083 -p 8084:8084 -p 8883:8883 -p 18083:18083 emqx/emqx:5.8.6

-------------------------------

 

d). 此時在開發(fā)主機,通過瀏覽器通過如下網(wǎng)址可以查看已經(jīng)運行的 EMQX 控制臺頁面,默認登錄信息為 admin/public,可以后續(xù)自行更改密碼。

-------------------------------

http://:18083/

-------------------------------

 

NXP iMX8MP ARM 平臺 EMQX 部署測試7154.png 

NXP iMX8MP ARM 平臺 EMQX 部署測試7156.png 

 

e). 通過如下自帶的基于 Websocket 的 MQTT 客戶端進行測試

NXP iMX8MP ARM 平臺 EMQX 部署測試7198.png 

 

./ 進入客戶端后,首先連接 Verdin i.MX8MP 核心節(jié)點設備

NXP iMX8MP ARM 平臺 EMQX 部署測試7238.png 

 

./ 然后再訂閱默認的 testtopic 主題

NXP iMX8MP ARM 平臺 EMQX 部署測試7268.png 

 

./ 最后可以修改 payload 內(nèi)容后,點擊發(fā)布,可以看到核心節(jié)點可以正常接收數(shù)據(jù)

NXP iMX8MP ARM 平臺 EMQX 部署測試7315.png 

 

5). 總結

本文基于 NXP i.MX8MP 處理器簡單演示了通過 Docker 環(huán)境部署運行 EMQX MQTT 消息服務器。

審核編輯(
王靜
)

提交

查看更多評論
其他資訊

查看更多

NXP iMX8QM 通過 SCFW 隔離 AP_M4 核資源

上手測試 Hailo:在 Toradex 模塊上加速邊緣 AI

Yocto Linux 量產(chǎn) BSP 鏡像定制

ARM 處理器平臺 eMMC Flash 存儲磨損測試示例

NXP iMX8MP 處理器基于 Linux 關閉 Debug Console 輸出