当前位置:首页>Linux>嵌入式 Linux 接入 Matter

嵌入式 Linux 接入 Matter

  • 2026-09-05 14:05:12
嵌入式 Linux 接入 Matter

最近在做嵌入式 Linux 平台的 Matter 接入,今天就嵌入式 Linux 平台 Matter 编译做一个总结和分享。

1. 参考资料

https://project-chip.github.io/connectedhomeip-doc/guides/BUILDING.html

2. 编译环境安装(操作系统:Ubuntu 22.04)

sudo apt-get install git gcc g++ pkg-config cmake curl libssl-dev libdbus-1-dev \ libglib2.0-dev libavahi-client-dev ninja-build python3-venv python3-dev \   python3-pip unzip libgirepository1.0-dev libcairo2-dev libreadline-dev \ libevent-dev default-jre

注意⚠️:如果是 Ubuntu 22.04,则需要升级 Python 版本为 v11

sudo apt-get install python3.11 python3.11-dev python3.11-venvsudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.10 1sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2python3 --version

如果出现如下错误

正在读取软件包列表... 完成 正在分析软件包的依赖关系树... 完成 正在读取状态信息... 完成 注意,根据正则表达式 'python3.11' 选中了 'python3.11-gdbm' 注意,根据正则表达式 'python3.11' 选中了 根据正则表达式 'python3.11' 选中 'python3-tk' 而非 'python3.11-tk' E: 无法定位软件包 python3.11-dev E: 无法按照 glob ‘python3.11-dev’ 找到任何软件包 E: 无法按照正则表达式 python3.11-dev 找到任何软件包 E: 无法定位软件包 python3.11-venv E: 无法按照 glob ‘python3.11-venv’ 找到任何软件包 E: 无法按照正则表达式 python3.11-venv 找到任何软件包

请执行下面代码,加下PPA 源后再安装

sudo apt updatesudo apt install software-properties-commonsudo add-apt-repository ppa:deadsnakes/ppasudo apt updatesudo apt install python3.11 python3.11-dev python3.11-venv

3. 安装Ninja 和 gn

sudo apt-get update# 安装 Ninjasudo apt-get install ninja-build# 安装 GNsudo apt-get install gn

4. 克隆代码

// ① 克隆顶层(深度为 1)git clone --depth=1 git@github.com:project-chip/connectedhomeip.git// ② 检出 linux 平台代码python3 ./scripts/checkout_submodules.py --shallow --platform  linux// ③ 更新代码git pullgit submodule update --init

5. 设置环境变量和交叉编译工具链

// 执行完成会自动调用执行./scripts/activate.sh(后面每次编译执行一次 activate.sh就行)source ./script/bootstrap.sh// my-activate.sh 存放内容为自己交叉编译工具联环境变量,内容如下source ./scripts/my-activate.sh
#根据你的环境填写,比如我是 Rockchip 的 SOC 值为MY_SYSROOT=/home/tiger/rockchip/buildroot/output/latest/host/arm-buildroot-linux-gnueabihf/sysroot#交叉编译工具链的 bin 目录根据自己的环境填写TOOLCHAIN_PATH=/home/tiger/rockchip/prebuilts/gcc/linux-x86/arm/gcc-arm-10.3-2021.07-x86_64-arm-none-linux-gnueabihf/binexport PATH=$TOOLCHAIN_PATH:$PATHexport C_INCLUDE_PATH=$MY_SYSROOT/include:$C_INCLUDE_PATHexport C_INCLUDE_PATH=$MY_SYSROOT/include/glib-2.0:$C_INCLUDE_PATHexport C_INCLUDE_PATH=$MY_SYSROOT/lib/glib-2.0/include:$C_INCLUDE_PATHexport C_INCLUDE_PATH=$MY_SYSROOT/include/gio-unix-2.0:$C_INCLUDE_PATHexport CPLUS_INCLUDE_PATH=$MY_SYSROOT/include:$C_INCLUDE_PATHexport CPLUS_INCLUDE_PATH=$MY_SYSROOT/include/glib-2.0:$C_INCLUDE_PATHexport CPLUS_INCLUDE_PATH=$MY_SYSROOT/lib/glib-2.0/include:$C_INCLUDE_PATHexport CPLUS_INCLUDE_PATH=$MY_SYSROOT/include/gio-unix-2.0:$C_INCLUDE_PATHexport PKG_CONFIG_SYSROOT_DIR=$MY_SYSROOTexport PKG_CONFIG_PATH=$MY_SYSROOT/lib/pkgconfig:$MY_SYSROOT/lib/glib-2.0/pkgconfig:$MY_SYSROOT/include/gio-unix-2.0/pkgconfigexport LD_LIBRARY_PATH=$MY_SYSROOT/lib:$LD_LIBRARY_PATH

6. 开始编译

// 1. 切换到 examples/air-quality-sensor-appcd  examples/air-quality-sensor-app//2. 生成编译配置gn gen --check --fail-on-unused-args out/debug --args=' target_os="linux"  target_cpu="arm"  is_clang=false  sysroot="跟my-activate.sh里的MY_SYSROOT值一样"  target_cc="arm-none-linux-gnueabihf-gcc"  target_cxx="arm-none-linux-gnueabihf-g++"   target_ar="arm-none-linux-gnueabihf-ar"   treat_warnings_as_errors=false   strip_symbols=true   chip_enable_additional_data_advertising = true  is_debug=true ' //3.开始编译ninja -C out/debug

7. 编译错误:

如果编译时报错找不到arm-none-linux-gnueabihf-gcc,请

修改:build/toolchain/linux/BUILD.gn 中 _toolprefix 为 arm-none-linux-gnueabihf-

8. 运行错误:

Need update BLE related part for bluez 5.78,请参考 https://github.com/project-chip/connectedhomeip/issues/37359 修改

--- a/src/platform/Linux/bluez/BluezEndpoint.cpp+++ b/src/platform/Linux/bluez/BluezEndpoint.cpp@@ -189,11 +189,11 @@ gboolean BluezEndpoint::BluezCharacteristicAcquireNotify(BluezGattCharacteristic     }     conn->SetupNotifyHandler(fds[0], isAdditionalAdvertising);-    bluez_gatt_characteristic1_set_notify_acquired(aChar, TRUE);+    //bluez_gatt_characteristic1_set_notify_acquired(aChar, TRUE);     conn->SetNotifyAcquired(true);     GUnixFDList * fdList = g_unix_fd_list_new_from_array(&fds[1], 1);-    bluez_gatt_characteristic1_complete_acquire_notify(aChar, aInvocation, fdList, g_variant_new_handle(0), conn->GetMTU());+    //bluez_gatt_characteristic1_complete_acquire_notify(aChar, aInvocation, fdList, g_variant_new_handle(0), conn->GetMTU());     g_object_unref(fdList);     BLEManagerImpl::HandleTXCharCCCDWrite(conn);

遇到下面错误,查看wpa_supplicant启动参数是否增加-u(-u 是 dbus),matter 通过 D-Bus 去找 wpa_supplicant,如果加了-u 后 wpa_supplicant没启动,则去看看 buildroot 中 wpa_supplicant 是否开启了 dbus 支持,并且重新编译 。

[4140.581] [1666:1666] [SVR] Manual pairing code: [34970112332][4140.581] [1666:1667] [DL] wpa_supplicant: Start WiFi management[4140.600] [1666:1667] [DL] wpa_supplicant: connected to wpa_supplicant proxy[4140.603] [1666:1667] [DL] wpa_supplicant: can't find interface wlan0: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name fi.w1.wpa_supplicant1 was not provided by any .service files[4140.603] [1666:1667] [DL] wpa_supplicant: try to create interface wlan0[4140.605] [1666:1667] [DL] wpa_supplicant: failed to create interface wlan0: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name fi.w1.wpa_supplicant1 was not provided by any .service files[4141.086] [1666:1666] [-] Wi-Fi Management taking too long to start - device configuration will be reset.
感谢阅读,下期分享 .zap 定制和OTA 开发测试。

最新文章

随机文章