ESP Matter 环境搭建

前言

esp-matter 项⽬仓库及其附带的⼦仓库位于 github,国内⼀些地区从 github 克隆仓库⾮常慢,同时由 于 esp-matter 仓库及⼦仓库⾮常⼤,导致克隆时间⾮常⻓且易失败。另外,esp-matter 环境安装过程 中需要访问⼀些外⽹,导致部分资源不能获取。以上两点可通过特殊上⽹⼿段解决,但考虑到并⾮所有 开发者均有此条件,本⽂简要介绍了⼀种在国内快速搭建 esp-matter 开发环境的⽅法。

1. 步骤

1.1 准备

ubuntu 20.04/22.04,其他发⾏版未做验证,ubuntu 软件源请⾃⾏改为国内的。

1.2 设置 github 镜像

git clone https://gitee.com/EspressifSystems/esp-gitee-tools.git 

cd esp-gitee-tools 

./jihu-mirror.sh set # 可通过 ./jihu-mirror.sh unset 取消设置

1.3 安装 esp-idf 依赖包

以 esp-idf v4.4 为例,具体参考 esp-idf 编程⼿册中环境搭建部分章节。

sudo apt-get install git wget flex bison gperf python3 python3-pip python3-setuptools cmake ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0

1.4 设置 python 源到国内

pip config set global.index-url http://mirrors.aliyun.com/pypi/simple 

pip config set global.trusted-host mirrors.aliyun.com

1.5 拉取 esp-idf 并安装设置环境

git clone --recursive --single-branch --branch release/v4.4 https://github.com/espressif/esp-idf.git 

cd esp-idf 

export IDF_GITHUB_ASSETS="dl.espressif.com/github_assets" 

./install.sh 

. ./export.sh

1.6 拉取 esp-matter 并做相应修改

git clone https://github.com/espressif/esp-matter.git 
cd esp-matter 
git submodule update --init connectedhomeip/connectedhomeip/scripts/checkout_submodules.py --shallow --platform esp32

以上命令仅拉取与 esp32 相关的 connectedhomeip ⼦仓库,如想拉取完整⼯程,也可使⽤如下命令:

git clone --recursive https://github.com/espressif/esp-matter.git
  • 如已克隆 esp-matter,并做过安装尝试,删除 esp-matter/connectedhomeip/connectedhomeip/.environment⽬录

  • esp-matter/export.sh 中,注释掉 export PATH=${PATH}:${ESP_MATTER_PATH}/connectedhomeip/connectedhomeip/.environment/cip d/packages/pigweed/export PATH=${PATH}:${ESP_MATTER_PATH}/connectedhomeip/connectedhomeip/examples/chip- tool/out/ 两⾏,增加 export PATH=${PATH}:${ESP_MATTER_PATH}/connectedhomeip/connectedhomeip/out/host/

  • 补充 pigweed_environment.gni ⽂件

cd esp-matter 

touch connectedhomeip/connectedhomeip/build_overrides/pigweed_environment.gni

添加 pigweed_environment.gni ⽂件内容为:

# This file is automatically generated by Pigweed's environment setup. Do not 
# edit it manually or check it in. 
declare_args() { 
pw_env_setup_CIPD_ARM = "//.environment/cipd/packages/arm" 
dir_cipd_arm = "//.environment/cipd/packages/arm" 
pw_env_setup_CIPD_PIGWEED = "//.environment/cipd/packages/pigweed" 
dir_cipd_pigweed = "//.environment/cipd/packages/pigweed" 
pw_env_setup_CIPD_PYTHON = "//.environment/cipd/packages/python" 
dir_cipd_python = "//.environment/cipd/packages/python" 
pw_env_setup_VIRTUAL_ENV = "//.environment/pigweed-venv" 
pw_env_setup_PACKAGE_ROOT = "//.environment/packages" }

1.7 安装 connectedhomeip 依赖包

sudo apt-get install gn pkg-config libglib2.0-dev python3-venv libgirepository- 1.0-1 libdbus-1-dev

对于 ubuntu 20.04 ⽤⼾,源上没有 gn,可以⼿动下载 gn 进⾏安装

sudo apt-get install unzip 

wget https://dl.espressif.com/AE/gn-linux-amd64-2071.zip 

sudo unzip gn-linux-amd64-2071.zip -d /usr/bin/

sudo chmod 777 /usr/bin/gn

1.8 编译 connectedhomeip 相关⼯具 以上⼯具需要在 connectedhomeip 更新后重新编译,如未更新,不需要每次编译。

cd esp-matter/connectedhomeip/connectedhomeip 
gn gen out/host # 下⾯命令会编译所有⼯具,需要耗费⼀些时间,暂不推荐使⽤ 
ninja -C out/host # 也可⽤以下命令单独编译 esp-matter 所需⼯具,较快,推荐使⽤ 
ninja -C out/host chip-cert 
ninja -C out/host chip-tool 
ninja -C out/host spake2p

以上⼯具需要在 connectedhomeip 更新后重新编译,如未更新,不需要每次编译。

1.9 设置 esp-matter 环境

cd esp-matter # 注意:不需要 ./install.sh 

export ESP_MATTER_PATH=$(pwd)

. ./export.sh

1.10 编译 esp-matter ⽰例

cd esp-matter/examples/light 
idf.py set-target esp32c3 
idf.py build

你可能感兴趣的:(环境搭建,(Environment,Setup),git,matter)