docs.rs failed to build esp-idf-matter-0.1.0
Please check the
build logs for more information.
See
Builds for ideas on how to fix a failed build,
or
Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault,
open an issue.

Overview
Everything necessary to run rs-matter on the ESP-IDF:
- Bluedroid implementation of
rs-matter's GattPeripheral for BLE comissioning support.
rs-matter-stack support with Netif, Ble, Wireless (all of Wifi / Thread / Ethernet) and KvBlobStore implementations.
Since ESP-IDF does support the Rust Standard Library, UDP networking just works.
Example
(See also All examples)
#![allow(unexpected_cfgs)]
#![recursion_limit = "256"]
fn main() -> Result<(), anyhow::Error> {
#[cfg(any(esp32, esp32s3, esp32c3, esp32c6))]
{
example::main()
}
#[cfg(not(any(esp32, esp32s3, esp32c3, esp32c6)))]
panic!("This example is only supported on ESP32, ESP32-S2, ESP32-S3, ESP32-C3 and ESP32-C6 chips. Please select a different example or target.");
}
#[cfg(any(esp32, esp32s3, esp32c3, esp32c6))]
mod example {
use core::pin::pin;
use alloc::sync::Arc;
use esp_idf_matter::init_async_io;
use esp_idf_matter::matter::crypto::{default_crypto, Crypto};
use esp_idf_matter::matter::dm::clusters::app::on_off::test::TestOnOffDeviceLogic;
use esp_idf_matter::matter::dm::clusters::app::on_off::{self, OnOffHandler, OnOffHooks};
use esp_idf_matter::matter::dm::clusters::desc::{self, ClusterHandler as _, DescHandler};
use esp_idf_matter::matter::dm::devices::test::{
DAC_PRIVKEY, TEST_DEV_ATT, TEST_DEV_COMM, TEST_DEV_DET,
};
use esp_idf_matter::matter::dm::devices::DEV_TYPE_ON_OFF_LIGHT;
use esp_idf_matter::matter::dm::endpoints::ROOT_ENDPOINT_ID;
use esp_idf_matter::matter::dm::{Async, Dataver, EmptyHandler, Endpoint, Node};
use esp_idf_matter::matter::persist::DummyKvBlobStore;
use esp_idf_matter::matter::utils::init::InitMaybeUninit;
use esp_idf_matter::matter::{clusters, devices};
use esp_idf_matter::wireless::{EspMatterWifi, EspWifiMatterStack};
#[cfg(esp_idf_bt_bluedroid_enabled)]
use esp_idf_svc::bt::reduce_bt_memory;
use esp_idf_svc::eventloop::EspSystemEventLoop;
use esp_idf_svc::hal::peripherals::Peripherals;
use esp_idf_svc::hal::task::block_on;
use esp_idf_svc::hal::task::thread::ThreadSpawnConfiguration;
use esp_idf_svc::io::vfs::MountedEventfs;
use esp_idf_svc::nvs::EspDefaultNvsPartition;
use esp_idf_svc::timer::EspTaskTimerService;
use log::{error, info};
use static_cell::StaticCell;
extern crate alloc;
const STACK_SIZE: usize = 10 * 1024;
const BUMP_SIZE: usize = 18000;
pub fn main() -> Result<(), anyhow::Error> {
esp_idf_svc::log::init_from_env();
info!("Starting...");
ThreadSpawnConfiguration::set(&ThreadSpawnConfiguration {
name: Some(c"matter"),
..Default::default()
})?;
let thread = std::thread::Builder::new()
.stack_size(STACK_SIZE)
.spawn(run)
.unwrap();
thread.join().unwrap()
}
#[inline(never)]
#[cold]
fn run() -> Result<(), anyhow::Error> {
let result = block_on(pin!(matter()));
if let Err(e) = &result {
error!("Matter aborted execution with error: {e:?}");
}
{
info!("Matter finished execution successfully");
}
result
}
async fn matter() -> Result<(), anyhow::Error> {
let stack = MATTER_STACK.uninit().init_with(EspWifiMatterStack::init(
&TEST_DEV_DET,
TEST_DEV_COMM,
&TEST_DEV_ATT,
));
let sysloop = EspSystemEventLoop::take()?;
let timers = EspTaskTimerService::new()?;
let nvs = EspDefaultNvsPartition::take()?;
let peripherals = Peripherals::take()?;
let mounted_event_fs = Arc::new(MountedEventfs::mount(3)?);
init_async_io(mounted_event_fs.clone())?;
#[cfg(esp_idf_bt_bluedroid_enabled)]
reduce_bt_memory(unsafe { peripherals.modem.reborrow() })?;
let crypto = default_crypto(rand::rng(), DAC_PRIVKEY);
let mut weak_rand = crypto.weak_rand()?;
let on_off = OnOffHandler::new_standalone(
Dataver::new_rand(&mut weak_rand),
LIGHT_ENDPOINT_ID,
TestOnOffDeviceLogic::new(true),
);
let handler = EmptyHandler
.chain(
|e, _| e == ROOT_ENDPOINT_ID,
Async(EspWifiMatterStack::<0, ()>::root_handler(
&(),
&mut weak_rand,
)),
)
.chain(
|e, c| e == LIGHT_ENDPOINT_ID && c == TestOnOffDeviceLogic::CLUSTER.id,
on_off::HandlerAsyncAdaptor(&on_off),
)
.chain(
|e, c| e == LIGHT_ENDPOINT_ID && c == DescHandler::CLUSTER.id,
Async(desc::DescHandler::new(Dataver::new_rand(&mut weak_rand)).adapt()),
);
let mut store = DummyKvBlobStore;
stack.startup(&crypto, &mut store).await?;
let kv = stack.kv(store);
let matter = pin!(stack.run_coex(
EspMatterWifi::new_with_builtin_mdns(peripherals.modem, sysloop, timers, nvs, stack),
&crypto,
(NODE, handler),
&kv,
(),
));
matter.await?;
Ok(())
}
static MATTER_STACK: StaticCell<EspWifiMatterStack<BUMP_SIZE, ()>> = StaticCell::new();
const LIGHT_ENDPOINT_ID: u16 = 1;
const NODE: Node = Node {
endpoints: &[
EspWifiMatterStack::<0, ()>::root_endpoint(),
Endpoint::new(
LIGHT_ENDPOINT_ID,
devices!(DEV_TYPE_ON_OFF_LIGHT),
clusters!(DescHandler::CLUSTER, TestOnOffDeviceLogic::CLUSTER),
),
],
};
}
Future
- Device Attestation data support using secure flash storage
- Setting system time via Matter
- Matter OTA support based on the ESP-IDF OTA API
Build Prerequisites
Follow the Prerequisites section in the esp-idf-template crate.
All examples
The examples could be built and flashed conveniently with cargo-espflash. To run e.g. light_wifi on an e.g. ESP32-C3:
(Swap the Rust target and example name with the target corresponding for your ESP32 MCU and with the example you would like to build)
with cargo-espflash:
$ MCU=esp32c3 cargo espflash flash --target riscv32imc-esp-espidf --example light_wifi --features examples --monitor
| MCU |
"--target" |
| esp32c2 |
riscv32imc-esp-espidf |
| esp32c3 |
riscv32imc-esp-espidf |
| esp32c5 |
riscv32imac-esp-espidf |
| esp32c6 |
riscv32imac-esp-espidf |
| esp32h2 |
riscv32imac-esp-espidf |
| esp32p4 |
riscv32imafc-esp-espidf |
| esp32 |
xtensa-esp32-espidf |
| esp32s2 |
xtensa-esp32s2-espidf |
| esp32s3 |
xtensa-esp32s3-espidf |