diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index a42adcf..b5d837f 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -7,8 +7,8 @@ ENV LANG=C.UTF-8
# Arguments
ARG CONTAINER_USER=esp
ARG CONTAINER_GROUP=esp
-ARG NIGHTLY_VERSION=nightly-2023-11-14
-ARG ESP_IDF_VERSION=v5.1.2
+ARG NIGHTLY_VERSION=nightly-2024-06-30
+ARG ESP_IDF_VERSION=v5.2.2
ARG ESP_BOARD=esp32c3
# Install dependencies
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
index de8beff..e861e6b 100755
--- a/.devcontainer/devcontainer.json
+++ b/.devcontainer/devcontainer.json
@@ -6,7 +6,7 @@
// "build": {
// "dockerfile": "Dockerfile",
// "args": {
- // "NIGHTLY_VERSION": "nightly-2023-11-14"
+ // "NIGHTLY_VERSION": "nightly-2024-06-30"
// }
// },
"customizations": {
diff --git a/README.md b/README.md
index 16ca95e..776a581 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
这里是 https://github.com/esp-rs/std-training 的简体中文翻译
-目前进度:已经翻译完成(部分更新的内容需要重新翻译),跟踪到 3ce0971
+目前进度:已经翻译完成(部分更新的内容需要重新翻译),跟踪到 015cd3d
---
diff --git a/advanced/button-interrupt/.cargo/config.toml b/advanced/button-interrupt/.cargo/config.toml
index 773acef..ca3f744 100644
--- a/advanced/button-interrupt/.cargo/config.toml
+++ b/advanced/button-interrupt/.cargo/config.toml
@@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]
[unstable]
build-std = ["panic_abort", "std"]
-build-std-features = ["panic_immediate_abort"]
[env]
-# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
-ESP_IDF_VERSION = { value = "tag:v5.1.2" }
+# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
+ESP_IDF_VERSION = { value = "tag:v5.2.2" }
# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
@@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
+# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
+CRATE_CC_NO_DEFAULTS = "1"
diff --git a/advanced/button-interrupt/Cargo.toml b/advanced/button-interrupt/Cargo.toml
index e4c5bd7..889d87a 100644
--- a/advanced/button-interrupt/Cargo.toml
+++ b/advanced/button-interrupt/Cargo.toml
@@ -9,6 +9,10 @@ authors = [
edition = "2021"
resolver = "2"
+[[bin]]
+name = "button-interrupt"
+harness = false # We can't use the default rust libtest harness for a crosscompile target
+
[profile.release]
opt-level = "s"
@@ -17,9 +21,9 @@ debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"
[dependencies]
-anyhow = "=1.0.75"
-esp-idf-svc = "=0.47.3"
+anyhow = "=1.0.86"
+esp-idf-svc = "=0.49.0"
rgb-led = { path = "../../common/lib/rgb-led" }
[build-dependencies]
-embuild = "=0.31.4"
+embuild = "=0.32.0"
diff --git a/advanced/button-interrupt/examples/solution_led.rs b/advanced/button-interrupt/examples/solution_led.rs
index 0212f85..2a81b56 100644
--- a/advanced/button-interrupt/examples/solution_led.rs
+++ b/advanced/button-interrupt/examples/solution_led.rs
@@ -35,6 +35,9 @@ fn main() -> Result<()> {
})?;
}
+ println!("Hello world!");
+
+
// ANCHOR: loop
loop {
// Enable interrupt and wait for new notificaton
diff --git a/advanced/button-interrupt/rust-toolchain.toml b/advanced/button-interrupt/rust-toolchain.toml
index a4b1ace..6518c18 100644
--- a/advanced/button-interrupt/rust-toolchain.toml
+++ b/advanced/button-interrupt/rust-toolchain.toml
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2023-11-14"
+channel = "nightly-2024-06-30"
components = ["rust-src"]
diff --git a/advanced/i2c-driver/.cargo/config.toml b/advanced/i2c-driver/.cargo/config.toml
index 773acef..ca3f744 100644
--- a/advanced/i2c-driver/.cargo/config.toml
+++ b/advanced/i2c-driver/.cargo/config.toml
@@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]
[unstable]
build-std = ["panic_abort", "std"]
-build-std-features = ["panic_immediate_abort"]
[env]
-# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
-ESP_IDF_VERSION = { value = "tag:v5.1.2" }
+# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
+ESP_IDF_VERSION = { value = "tag:v5.2.2" }
# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
@@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
+# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
+CRATE_CC_NO_DEFAULTS = "1"
diff --git a/advanced/i2c-driver/Cargo.toml b/advanced/i2c-driver/Cargo.toml
index e863bb5..dff3f05 100644
--- a/advanced/i2c-driver/Cargo.toml
+++ b/advanced/i2c-driver/Cargo.toml
@@ -8,6 +8,10 @@ authors = [
edition = "2021"
resolver = "2"
+[[bin]]
+name = "i2c-driver"
+harness = false # We can't use the default rust libtest harness for a crosscompile target
+
[profile.release]
opt-level = "s"
@@ -16,9 +20,9 @@ debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"
[dependencies]
-anyhow = "=1.0.75"
+anyhow = "=1.0.86"
embedded-hal = "=0.2.7"
-esp-idf-svc = "=0.47.3"
+esp-idf-svc = "=0.49.0"
[build-dependencies]
-embuild = "=0.31.4"
+embuild = "=0.32.0"
diff --git a/advanced/i2c-driver/rust-toolchain.toml b/advanced/i2c-driver/rust-toolchain.toml
index a4b1ace..6518c18 100644
--- a/advanced/i2c-driver/rust-toolchain.toml
+++ b/advanced/i2c-driver/rust-toolchain.toml
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2023-11-14"
+channel = "nightly-2024-06-30"
components = ["rust-src"]
diff --git a/advanced/i2c-sensor-reading/.cargo/config.toml b/advanced/i2c-sensor-reading/.cargo/config.toml
index 773acef..ca3f744 100644
--- a/advanced/i2c-sensor-reading/.cargo/config.toml
+++ b/advanced/i2c-sensor-reading/.cargo/config.toml
@@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]
[unstable]
build-std = ["panic_abort", "std"]
-build-std-features = ["panic_immediate_abort"]
[env]
-# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
-ESP_IDF_VERSION = { value = "tag:v5.1.2" }
+# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
+ESP_IDF_VERSION = { value = "tag:v5.2.2" }
# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
@@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
+# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
+CRATE_CC_NO_DEFAULTS = "1"
diff --git a/advanced/i2c-sensor-reading/Cargo.toml b/advanced/i2c-sensor-reading/Cargo.toml
index e396e4f..f719e5b 100644
--- a/advanced/i2c-sensor-reading/Cargo.toml
+++ b/advanced/i2c-sensor-reading/Cargo.toml
@@ -8,6 +8,10 @@ authors = [
edition = "2021"
resolver = "2"
+[[bin]]
+name = "i2c-sensor-reading"
+harness = false # We can't use the default rust libtest harness for a crosscompile target
+
[profile.release]
opt-level = "s"
@@ -16,13 +20,13 @@ debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"
[dependencies]
-anyhow = "=1.0.75"
+anyhow = "=1.0.86"
embedded-hal = "=0.2.7"
-esp-idf-svc = "=0.47.3"
+esp-idf-svc = "=0.49.0"
icm42670 = "=0.1.1"
lis3dh = "=0.4.2"
shared-bus = "=0.3.1"
shtcx = "=0.11.0"
[build-dependencies]
-embuild = "=0.31.4"
+embuild = "=0.32.0"
diff --git a/advanced/i2c-sensor-reading/rust-toolchain.toml b/advanced/i2c-sensor-reading/rust-toolchain.toml
index a4b1ace..6518c18 100644
--- a/advanced/i2c-sensor-reading/rust-toolchain.toml
+++ b/advanced/i2c-sensor-reading/rust-toolchain.toml
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2023-11-14"
+channel = "nightly-2024-06-30"
components = ["rust-src"]
diff --git a/book/src/02_2_software.md b/book/src/02_2_software.md
index 8cd0fe3..8fbf6ed 100644
--- a/book/src/02_2_software.md
+++ b/book/src/02_2_software.md
@@ -8,12 +8,12 @@
✅ 如果你的电脑上还没有安装 Rust,从 获取它
-此外,对于 ESP32-C3,目前需要 Rust 工具链的 [*nightly* 版本](https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust)。本教程中我们将使用 `nightly-2023-11-14` 版本。
+此外,对于 ESP32-C3,目前需要 Rust 工具链的 [*nightly* 版本](https://rust-lang.github.io/rustup/concepts/channels.html#working-with-nightly-rust)。本教程中我们将使用 `nightly-2024-06-30` 版本。
✅ 用以下命令安装 *nightly* Rust,并添加对目标架构的支持:
```console
-rustup toolchain install nightly-2023-11-14 --component rust-src
+rustup toolchain install nightly-2024-06-30 --component rust-src
```
🔎 Rust 能够交叉编译到任何支持的目标架构(参见 `rustup 目标列表`)。默认情况下,仅会安装本机的架构。
diff --git a/book/src/02_3_repository.md b/book/src/02_3_repository.md
index 1440e68..ee8403d 100644
--- a/book/src/02_3_repository.md
+++ b/book/src/02_3_repository.md
@@ -11,7 +11,7 @@ cd std-training
❗ Windows 用户可能会遇到[长路径名问题][windows-long-path]。
-[windows-long-path]: https://esp-rs.github.io/book/misc/troubleshooting.html#long-path-names
+[windows-long-path]: https://docs.esp-rs.org/book/troubleshooting/index.html#long-path-names
## 仓库内容
diff --git a/book/src/03_2_cargo_generate.md b/book/src/03_2_cargo_generate.md
index 92cf164..607eebd 100644
--- a/book/src/03_2_cargo_generate.md
+++ b/book/src/03_2_cargo_generate.md
@@ -54,7 +54,7 @@ ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" } # 添加这一行
```toml
[toolchain]
-channel = "nightly-2023-11-14" # 修改这一行
+channel = "nightly-2024-06-30" # 修改这一行
```
✅ 在 `hello-world` 目录中用下面的命令来运行项目:
diff --git a/book/src/03_5_3_mqtt.md b/book/src/03_5_3_mqtt.md
index 2f60e66..e5c2891 100644
--- a/book/src/03_5_3_mqtt.md
+++ b/book/src/03_5_3_mqtt.md
@@ -39,19 +39,11 @@ client.subscribe(subscribe_topic, QoS::AtLeastOnce)
## 处理收到的消息
-处理函数闭包里的 `message_event` 参数的类型是 `Result`。
-因为我们只对接收成功的消息感兴趣,我们可以在闭包里使用模式匹配:
+处理函数闭包里的 `message_event` 参数的类型是 `EspMqttEvent`,它有一个 `payload()` 方法,用于访问 `EventPayload`。
+由于我们只对接收成功的消息感兴趣:
```rust
-let mut client =
- EspMqttClient::new(
- broker_url,
- &mqtt_config,
- move |message_event| match message_event {
- Ok(Received(msg)) => process_message(msg, &mut led),
- _ => warn!("Received from MQTT: {:?}", message_event),
- },
- )?;
+{{#include ../../intro/mqtt/exercise/examples/solution_publ_rcv.rs:mqtt_client}}
```
在处理函数中,我们将会处理 `Complete` 消息。
@@ -59,21 +51,7 @@ let mut client =
💡 使用 Rust Analyzer 来生成缺失的 match 分支,或者匹配所有其他类型,输出一个 `info!()`。
```rust
-match message.details() {
- // 本练习中的消息都会是 `Complete` 类型的
- // `Details` 枚举的其他变体用于更大的消息 payload
- Complete => {
-
- // Cow<&[u8]> 可以被强制转换为 slice &[u8] 或 Vec
- // 你可以将它强制转换为 slice ,用 try_from() 发送
- let message_data: &[u8] = &message.data();
- if let Ok(ColorData::BoardLed(color)) = ColorData::try_from(message_data) {
- // 把 LED 配置为新收到的颜色
-
- }
- }
- // 使用 Rust Analyzer 来生成缺失的 match 分支,或者匹配非 complete 的消息来输出日志消息。
-}
+{{#include ../../intro/mqtt/exercise/examples/solution_publ_rcv.rs:process_message}}
```
💡 用 logger 来查看接收到的东西,例如:`info!("{}", color);` 或 `dbg!(color)`。
@@ -98,7 +76,6 @@ let raw = RawCommandData {
path: command,
data: message.data(),
};
-
```
检查 `host-client`:
@@ -109,36 +86,6 @@ let raw = RawCommandData {
let command = Command::BoardLed(color)
```
-✅ 在 `process_message()` 函数中,你需要解析主题。
-
-```rust
-match message.details() {
- Complete => {
- // 本练习中的消息都会是 `Complete` 类型的
- // `Details` 枚举的其他变体用于更大的消息 payload
- //
-
- // Cow 的行为很像其他 Rust 字符串 (&str, String)
- let topic: Cow = message.topic(token);
-
- // 确认我们是否对这个主题感兴趣
- // 并根据它的内容来分发
- let is_command_topic: bool = /* ... */;
- if is_command_topic {
- let raw = RawCommandData { /* ... */ };
- if let Ok(Command::BoardLed(color)) = Command::try_from(raw) {
- // 把 LED 配置为新收到的颜色
- }
-
- },
- _ => {}
- }
-}
-```
-
-💡 由于你需要遍历 MQTT 主题,你需要对字符串执行 `split()` 并得到一个迭代器。你可以用 [`nth()`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.nth) 来直接访问迭代器中的特定项。
-💡 可以用 `cargo run --example solution2` 运行实现了层次结构的解答。可以用 `cargo run` 或 `cargo run --example solution1` 运行未实现层次结构的解答。
-
### 其他任务
✅ 利用 [`serde_json`](https://docs.serde.rs/serde_json/) 将消息数据编码/解码为 JSON。
diff --git a/common/lib/get-uuid/Cargo.toml b/common/lib/get-uuid/Cargo.toml
index 3f7ec60..69e08c8 100644
--- a/common/lib/get-uuid/Cargo.toml
+++ b/common/lib/get-uuid/Cargo.toml
@@ -8,8 +8,8 @@ authors = [
edition = "2021"
[dependencies]
-anyhow = "=1.0.75"
+anyhow = "=1.0.86"
[build-dependencies]
-anyhow = "=1.0.75"
-uuid = { version = "=1.6.1", features = ["v4"] }
+anyhow = "=1.0.86"
+uuid = { version = "=1.9.1", features = ["v4"] }
diff --git a/common/lib/mqtt-messages/Cargo.toml b/common/lib/mqtt-messages/Cargo.toml
index 2008751..24816fa 100644
--- a/common/lib/mqtt-messages/Cargo.toml
+++ b/common/lib/mqtt-messages/Cargo.toml
@@ -8,4 +8,4 @@ authors = [
edition = "2021"
[dependencies]
-rgb = "=0.8.37"
+rgb = "=0.8.40"
diff --git a/common/lib/rgb-led/.cargo/config.toml b/common/lib/rgb-led/.cargo/config.toml
index 773acef..ca3f744 100644
--- a/common/lib/rgb-led/.cargo/config.toml
+++ b/common/lib/rgb-led/.cargo/config.toml
@@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]
[unstable]
build-std = ["panic_abort", "std"]
-build-std-features = ["panic_immediate_abort"]
[env]
-# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
-ESP_IDF_VERSION = { value = "tag:v5.1.2" }
+# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
+ESP_IDF_VERSION = { value = "tag:v5.2.2" }
# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
@@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
+# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
+CRATE_CC_NO_DEFAULTS = "1"
diff --git a/common/lib/rgb-led/Cargo.toml b/common/lib/rgb-led/Cargo.toml
index 837e004..fb49a44 100644
--- a/common/lib/rgb-led/Cargo.toml
+++ b/common/lib/rgb-led/Cargo.toml
@@ -5,10 +5,10 @@ edition = "2021"
authors = ["Sergio Gasquez "]
[dependencies]
-anyhow = "=1.0.75"
-esp-idf-svc = "=0.47.3"
-log = "=0.4.20"
+anyhow = "=1.0.86"
+esp-idf-svc = "=0.49.0"
+log = "=0.4.22"
rgb = "0.8.29"
[build-dependencies]
-embuild = "=0.31.4"
+embuild = "=0.32.0"
diff --git a/common/lib/rgb-led/rust-toolchain.toml b/common/lib/rgb-led/rust-toolchain.toml
index a4b1ace..6518c18 100644
--- a/common/lib/rgb-led/rust-toolchain.toml
+++ b/common/lib/rgb-led/rust-toolchain.toml
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2023-11-14"
+channel = "nightly-2024-06-30"
components = ["rust-src"]
diff --git a/common/lib/wifi/.cargo/config.toml b/common/lib/wifi/.cargo/config.toml
index 773acef..ca3f744 100644
--- a/common/lib/wifi/.cargo/config.toml
+++ b/common/lib/wifi/.cargo/config.toml
@@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]
[unstable]
build-std = ["panic_abort", "std"]
-build-std-features = ["panic_immediate_abort"]
[env]
-# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
-ESP_IDF_VERSION = { value = "tag:v5.1.2" }
+# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
+ESP_IDF_VERSION = { value = "tag:v5.2.2" }
# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
@@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
+# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
+CRATE_CC_NO_DEFAULTS = "1"
diff --git a/common/lib/wifi/Cargo.toml b/common/lib/wifi/Cargo.toml
index eef032f..8aa5c86 100644
--- a/common/lib/wifi/Cargo.toml
+++ b/common/lib/wifi/Cargo.toml
@@ -5,12 +5,12 @@ edition = "2021"
authors = ["Sergio Gasquez "]
[dependencies]
-anyhow = "=1.0.75"
-esp-idf-svc = "=0.47.3"
-log = "=0.4.20"
+anyhow = "=1.0.86"
+esp-idf-svc = "=0.49.0"
+log = "=0.4.22"
[build-dependencies]
-embuild = "=0.31.4"
+embuild = "=0.32.0"
[dev-dependencies]
toml-cfg = "=0.1.3"
diff --git a/common/lib/wifi/rust-toolchain.toml b/common/lib/wifi/rust-toolchain.toml
index a4b1ace..6518c18 100644
--- a/common/lib/wifi/rust-toolchain.toml
+++ b/common/lib/wifi/rust-toolchain.toml
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2023-11-14"
+channel = "nightly-2024-06-30"
components = ["rust-src"]
diff --git a/common/lib/wifi/src/lib.rs b/common/lib/wifi/src/lib.rs
index 7cffdf9..8debbf3 100644
--- a/common/lib/wifi/src/lib.rs
+++ b/common/lib/wifi/src/lib.rs
@@ -51,8 +51,12 @@ pub fn wifi(
};
wifi.set_configuration(&Configuration::Client(ClientConfiguration {
- ssid: ssid.into(),
- password: pass.into(),
+ ssid: ssid
+ .try_into()
+ .expect("Could not parse the given SSID into WiFi config"),
+ password: pass
+ .try_into()
+ .expect("Could not parse the given password into WiFi config"),
channel,
auth_method,
..Default::default()
diff --git a/intro/hardware-check/.cargo/config.toml b/intro/hardware-check/.cargo/config.toml
index 59a1d6f..708d257 100644
--- a/intro/hardware-check/.cargo/config.toml
+++ b/intro/hardware-check/.cargo/config.toml
@@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]
[unstable]
build-std = ["std", "panic_abort"]
-build-std-features = ["panic_immediate_abort"]
[env]
-# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
-ESP_IDF_VERSION = { value = "tag:v5.1.2" }
+# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
+ESP_IDF_VERSION = { value = "tag:v5.2.2" }
# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
@@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
+# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
+CRATE_CC_NO_DEFAULTS = "1"
diff --git a/intro/hardware-check/Cargo.toml b/intro/hardware-check/Cargo.toml
index 92f8424..1bb6d95 100644
--- a/intro/hardware-check/Cargo.toml
+++ b/intro/hardware-check/Cargo.toml
@@ -8,6 +8,10 @@ authors = [
edition = "2021"
resolver = "2"
+[[bin]]
+name = "hardware-check"
+harness = false # We can't use the default rust libtest harness for a crosscompile target
+
[profile.release]
opt-level = "s"
@@ -16,13 +20,13 @@ debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"
[dependencies]
-anyhow = "=1.0.75"
-esp-idf-svc = "=0.47.3"
-log = "=0.4.20"
+anyhow = "=1.0.86"
+esp-idf-svc = "=0.49.0"
+log = "=0.4.22"
rgb-led = { path = "../../common/lib/rgb-led" }
toml-cfg = "=0.1.3"
wifi = { path = "../../common/lib/wifi" }
[build-dependencies]
-embuild = "=0.31.4"
+embuild = "=0.32.0"
toml-cfg = "=0.1.3"
diff --git a/intro/hardware-check/rust-toolchain.toml b/intro/hardware-check/rust-toolchain.toml
index a4b1ace..6518c18 100644
--- a/intro/hardware-check/rust-toolchain.toml
+++ b/intro/hardware-check/rust-toolchain.toml
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2023-11-14"
+channel = "nightly-2024-06-30"
components = ["rust-src"]
diff --git a/intro/http-client/.cargo/config.toml b/intro/http-client/.cargo/config.toml
index 773acef..ca3f744 100644
--- a/intro/http-client/.cargo/config.toml
+++ b/intro/http-client/.cargo/config.toml
@@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]
[unstable]
build-std = ["panic_abort", "std"]
-build-std-features = ["panic_immediate_abort"]
[env]
-# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
-ESP_IDF_VERSION = { value = "tag:v5.1.2" }
+# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
+ESP_IDF_VERSION = { value = "tag:v5.2.2" }
# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
@@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
+# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
+CRATE_CC_NO_DEFAULTS = "1"
diff --git a/intro/http-client/Cargo.toml b/intro/http-client/Cargo.toml
index e265b2a..cff92ff 100644
--- a/intro/http-client/Cargo.toml
+++ b/intro/http-client/Cargo.toml
@@ -8,6 +8,10 @@ authors = [
edition = "2021"
resolver = "2"
+[[bin]]
+name = "http-client"
+harness = false # We can't use the default rust libtest harness for a crosscompile target
+
[profile.release]
opt-level = "s"
@@ -16,12 +20,12 @@ debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"
[dependencies]
-anyhow = "=1.0.75"
-embedded-svc = "=0.26.4"
-esp-idf-svc = "=0.47.3"
+anyhow = "=1.0.86"
+embedded-svc = "=0.28.0"
+esp-idf-svc = "=0.49.0"
toml-cfg = "=0.1.3"
wifi = { path = "../../common/lib/wifi" }
[build-dependencies]
-embuild = "=0.31.4"
+embuild = "=0.32.0"
toml-cfg = "=0.1.3"
diff --git a/intro/http-client/rust-toolchain.toml b/intro/http-client/rust-toolchain.toml
index a4b1ace..6518c18 100644
--- a/intro/http-client/rust-toolchain.toml
+++ b/intro/http-client/rust-toolchain.toml
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2023-11-14"
+channel = "nightly-2024-06-30"
components = ["rust-src"]
diff --git a/intro/http-server/.cargo/config.toml b/intro/http-server/.cargo/config.toml
index 773acef..ca3f744 100644
--- a/intro/http-server/.cargo/config.toml
+++ b/intro/http-server/.cargo/config.toml
@@ -10,11 +10,10 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]
[unstable]
build-std = ["panic_abort", "std"]
-build-std-features = ["panic_immediate_abort"]
[env]
-# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
-ESP_IDF_VERSION = { value = "tag:v5.1.2" }
+# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
+ESP_IDF_VERSION = { value = "tag:v5.2.2" }
# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
@@ -26,3 +25,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
+# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
+CRATE_CC_NO_DEFAULTS = "1"
diff --git a/intro/http-server/Cargo.toml b/intro/http-server/Cargo.toml
index 69f5452..c26440a 100644
--- a/intro/http-server/Cargo.toml
+++ b/intro/http-server/Cargo.toml
@@ -8,6 +8,10 @@ authors = [
edition = "2021"
resolver = "2"
+[[bin]]
+name = "http-server"
+harness = false # We can't use the default rust libtest harness for a crosscompile target
+
[profile.release]
opt-level = "s"
@@ -16,13 +20,13 @@ debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"
[dependencies]
-anyhow = "=1.0.75"
-embedded-svc = "=0.26.4"
-esp-idf-svc = "=0.47.3"
-shtcx = "=0.11.0"
+anyhow = "=1.0.86"
+embedded-svc = "=0.28.0"
+esp-idf-svc = "=0.49.0"
+shtcx = "=1.0.0"
toml-cfg = "=0.1.3"
wifi = { path = "../../common/lib/wifi" }
[build-dependencies]
-embuild = "=0.31.4"
+embuild = "=0.32.0"
toml-cfg = "=0.1.3"
diff --git a/intro/http-server/examples/http_server.rs b/intro/http-server/examples/http_server.rs
index 5640f31..d0487ee 100644
--- a/intro/http-server/examples/http_server.rs
+++ b/intro/http-server/examples/http_server.rs
@@ -5,6 +5,7 @@ use esp_idf_svc::{
eventloop::EspSystemEventLoop,
hal::{
i2c::{I2cConfig, I2cDriver},
+ io::EspIOError,
prelude::*,
},
http::server::{Configuration, EspHttpServer},
@@ -59,27 +60,35 @@ fn main() -> Result<()> {
// Set the HTTP server
let mut server = EspHttpServer::new(&Configuration::default())?;
// http:/// handler
- server.fn_handler("/", Method::Get, |request| {
- let html = index_html();
- let mut response = request.into_ok_response()?;
- response.write_all(html.as_bytes())?;
- Ok(())
- })?;
+ server.fn_handler(
+ "/",
+ Method::Get,
+ |request| -> core::result::Result<(), EspIOError> {
+ let html = index_html();
+ let mut response = request.into_ok_response()?;
+ response.write_all(html.as_bytes())?;
+ Ok(())
+ },
+ )?;
// http:///temperature handler
- server.fn_handler("/temperature", Method::Get, move |request| {
- let temp_val = temp_sensor
- .lock()
- .unwrap()
- .get_measurement_result()
- .unwrap()
- .temperature
- .as_degrees_celsius();
- let html = temperature(temp_val);
- let mut response = request.into_ok_response()?;
- response.write_all(html.as_bytes())?;
- Ok(())
- })?;
+ server.fn_handler(
+ "/temperature",
+ Method::Get,
+ move |request| -> core::result::Result<(), EspIOError> {
+ let temp_val = temp_sensor
+ .lock()
+ .unwrap()
+ .get_measurement_result()
+ .unwrap()
+ .temperature
+ .as_degrees_celsius();
+ let html = temperature(temp_val);
+ let mut response = request.into_ok_response()?;
+ response.write_all(html.as_bytes())?;
+ Ok(())
+ },
+ )?;
println!("Server awaiting connection");
diff --git a/intro/http-server/rust-toolchain.toml b/intro/http-server/rust-toolchain.toml
index a4b1ace..6518c18 100644
--- a/intro/http-server/rust-toolchain.toml
+++ b/intro/http-server/rust-toolchain.toml
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2023-11-14"
+channel = "nightly-2024-06-30"
components = ["rust-src"]
diff --git a/intro/mqtt/exercise/.cargo/config.toml b/intro/mqtt/exercise/.cargo/config.toml
index 773acef..1ca93d6 100644
--- a/intro/mqtt/exercise/.cargo/config.toml
+++ b/intro/mqtt/exercise/.cargo/config.toml
@@ -10,11 +10,11 @@ rustflags = ["--cfg", "espidf_time64", "-C", "default-linker-libraries"]
[unstable]
build-std = ["panic_abort", "std"]
-build-std-features = ["panic_immediate_abort"]
+
[env]
-# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.1.2)
-ESP_IDF_VERSION = { value = "tag:v5.1.2" }
+# Enables the esp-idf-sys "native" build feature (`cargo build --features native`) to build against ESP-IDF (v5.2.2)
+ESP_IDF_VERSION = { value = "tag:v5.2.2" }
# These configurations will pick up your custom "sdkconfig.release", "sdkconfig.debug" or "sdkconfig.defaults[.*]" files
# that you might put in the root of the project
@@ -26,3 +26,5 @@ ESP_IDF_SDKCONFIG_DEFAULTS = { value = "./sdkconfig.defaults", relative = true }
# ESP-IDF will be installed in ~/.espressif so it can be reused across the different examples.
# See also https://github.com/esp-rs/esp-idf-sys#esp_idf_tools_install_dir-esp_idf_tools_install_dir
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
+# Workaround for https://github.com/esp-rs/esp-idf-template/issues/174
+CRATE_CC_NO_DEFAULTS = "1"
diff --git a/intro/mqtt/exercise/Cargo.toml b/intro/mqtt/exercise/Cargo.toml
index 4cf4277..d59b962 100644
--- a/intro/mqtt/exercise/Cargo.toml
+++ b/intro/mqtt/exercise/Cargo.toml
@@ -8,6 +8,10 @@ authors = [
edition = "2021"
resolver = "2"
+[[bin]]
+name = "mqtt"
+harness = false # We can't use the default rust libtest harness for a crosscompile target
+
[profile.release]
opt-level = "s"
@@ -16,17 +20,17 @@ debug = true # Symbols are nice and they don't increase the size on Flash
opt-level = "z"
[dependencies]
-anyhow = "=1.0.75"
-embedded-svc = "=0.26.4"
-esp-idf-svc = "=0.47.3"
+anyhow = "=1.0.86"
+embedded-svc = "=0.28.0"
+esp-idf-svc = "=0.49.0"
get-uuid = { path = "../../../common/lib/get-uuid" }
-log = "=0.4.20"
+log = "=0.4.22"
mqtt-messages = { path = "../../../common/lib/mqtt-messages" }
rgb-led = { path = "../../../common/lib/rgb-led" }
-shtcx = "=0.11.0"
+shtcx = "=1.0.0"
toml-cfg = "=0.1.3"
wifi = { path = "../../../common/lib/wifi" }
[build-dependencies]
-embuild = "=0.31.4"
+embuild = "=0.32.0"
toml-cfg = "=0.1.3"
diff --git a/intro/mqtt/exercise/examples/solution_publ.rs b/intro/mqtt/exercise/examples/solution_publ.rs
index be34dd2..afda55c 100644
--- a/intro/mqtt/exercise/examples/solution_publ.rs
+++ b/intro/mqtt/exercise/examples/solution_publ.rs
@@ -1,5 +1,7 @@
use anyhow::Result;
-use embedded_svc::mqtt::client::QoS;
+use embedded_svc::mqtt::client::{
+ Details::Complete, EventPayload::Error, EventPayload::Received, QoS,
+};
use esp_idf_svc::{
eventloop::EspSystemEventLoop,
hal::{
@@ -7,7 +9,7 @@ use esp_idf_svc::{
i2c::{I2cConfig, I2cDriver},
prelude::*,
},
- mqtt::client::{EspMqttClient, MqttClientConfiguration},
+ mqtt::client::{Details, EspMqttClient, MqttClientConfiguration},
};
use log::info;
use mqtt_messages::hello_topic;
@@ -80,14 +82,14 @@ fn main() -> Result<()> {
// Your Code:
// 1. Create a client with default configuration and empty handler
- let mut client = EspMqttClient::new(&broker_url, &mqtt_config, move |_message_event| {
+ let mut client = EspMqttClient::new_cb(&broker_url, &mqtt_config, move |_message_event| {
// ... your handler code here - leave this empty for now
// we'll add functionality later in this chapter
})?;
// 2. publish an empty hello message
let payload: &[u8] = &[];
- client.publish(&hello_topic(UUID), QoS::AtLeastOnce, true, payload)?;
+ client.enqueue(&hello_topic(UUID), QoS::AtLeastOnce, true, payload)?;
loop {
sleep(Duration::from_secs(1));
@@ -96,7 +98,7 @@ fn main() -> Result<()> {
.unwrap()
.as_degrees_celsius();
// 3. publish CPU temperature
- client.publish(
+ client.enqueue(
&mqtt_messages::temperature_data_topic(UUID),
QoS::AtLeastOnce,
false,
diff --git a/intro/mqtt/exercise/examples/solution_publ_rcv.rs b/intro/mqtt/exercise/examples/solution_publ_rcv.rs
index cdd00ea..c8f01da 100644
--- a/intro/mqtt/exercise/examples/solution_publ_rcv.rs
+++ b/intro/mqtt/exercise/examples/solution_publ_rcv.rs
@@ -1,5 +1,7 @@
use anyhow::Result;
-use embedded_svc::mqtt::client::{Details::Complete, Event::Received, QoS};
+use embedded_svc::mqtt::client::{
+ Details::Complete, EventPayload::Error, EventPayload::Received, QoS,
+};
use esp_idf_svc::{
eventloop::EspSystemEventLoop,
hal::{
@@ -7,7 +9,7 @@ use esp_idf_svc::{
i2c::{I2cConfig, I2cDriver},
prelude::*,
},
- mqtt::client::{EspMqttClient, EspMqttMessage, MqttClientConfiguration},
+ mqtt::client::{Details, EspMqttClient, MqttClientConfiguration},
};
use log::{error, info, warn};
use mqtt_messages::{hello_topic, ColorData};
@@ -77,15 +79,18 @@ fn main() -> Result<()> {
};
// 1. Create a client with default configuration and empty handler
+ // ANCHOR: mqtt_client
let mut client =
- EspMqttClient::new(
+ EspMqttClient::new_cb(
&broker_url,
&mqtt_config,
- move |message_event| match message_event {
- Ok(Received(msg)) => process_message(msg, &mut led),
- _ => warn!("Received from MQTT: {:?}", message_event),
+ move |message_event| match message_event.payload() {
+ Received { data, details, .. } => process_message(data, details, &mut led),
+ Error(e) => warn!("Received error from MQTT: {:?}", e),
+ _ => info!("Received from MQTT: {:?}", message_event.payload()),
},
)?;
+ // ANCHOR_END: mqtt_client
// 2. publish an empty hello message
let payload: &[u8] = &[];
@@ -109,11 +114,12 @@ fn main() -> Result<()> {
}
}
-fn process_message(message: &EspMqttMessage, led: &mut WS2812RMT) {
- match message.details() {
+// ANCHOR: process_message
+fn process_message(data: &[u8], details: Details, led: &mut WS2812RMT) {
+ match details {
Complete => {
- info!("{:?}", message);
- let message_data: &[u8] = message.data();
+ info!("{:?}", data);
+ let message_data: &[u8] = data;
if let Ok(ColorData::BoardLed(color)) = ColorData::try_from(message_data) {
info!("{}", color);
if let Err(e) = led.set_pixel(color) {
@@ -121,6 +127,7 @@ fn process_message(message: &EspMqttMessage, led: &mut WS2812RMT) {
};
}
}
- _ => error!("Could not set board LED"),
+ _ => {}
}
}
+// ANCHOR_END: process_message
diff --git a/intro/mqtt/exercise/rust-toolchain.toml b/intro/mqtt/exercise/rust-toolchain.toml
index a4b1ace..6518c18 100644
--- a/intro/mqtt/exercise/rust-toolchain.toml
+++ b/intro/mqtt/exercise/rust-toolchain.toml
@@ -1,3 +1,3 @@
[toolchain]
-channel = "nightly-2023-11-14"
+channel = "nightly-2024-06-30"
components = ["rust-src"]
diff --git a/intro/mqtt/exercise/src/main.rs b/intro/mqtt/exercise/src/main.rs
index b2cb597..5aba2dd 100644
--- a/intro/mqtt/exercise/src/main.rs
+++ b/intro/mqtt/exercise/src/main.rs
@@ -1,5 +1,7 @@
use anyhow::Result;
-use embedded_svc::mqtt::client::{Details::Complete, Event::Received, QoS};
+use embedded_svc::mqtt::client::{
+ Details::Complete, EventPayload::Error, EventPayload::Received, QoS,
+};
use esp_idf_svc::{
eventloop::EspSystemEventLoop,
hal::{
@@ -7,7 +9,7 @@ use esp_idf_svc::{
i2c::{I2cConfig, I2cDriver},
prelude::*,
},
- mqtt::client::{EspMqttClient, EspMqttMessage, MqttClientConfiguration},
+ mqtt::client::{Details, EspMqttClient, MqttClientConfiguration},
};
use log::{error, info, warn};
use mqtt_messages::{hello_topic, ColorData};
@@ -80,7 +82,7 @@ fn main() -> Result<()> {
// Your Code:
// 1. Create a client with default configuration and empty handler
- // let mut client = EspMqttClient::new( ... )?;
+ // let mut client = EspMqttClient::new_cb( ... )?;
// 2. publish an empty hello message
diff --git a/intro/mqtt/host-client/Cargo.toml b/intro/mqtt/host-client/Cargo.toml
index 6001219..0fd8efe 100644
--- a/intro/mqtt/host-client/Cargo.toml
+++ b/intro/mqtt/host-client/Cargo.toml
@@ -11,5 +11,5 @@ edition = "2021"
get-uuid = { path = "../../../common/lib/get-uuid" }
mqtt-messages = { path = "../../../common/lib/mqtt-messages" }
rand = "=0.8.5"
-rumqttc = "=0.23.0"
+rumqttc = "=0.24.0"
toml-cfg = "=0.1.3"