diff --git a/advanced/button-interrupt/.cargo/config.toml b/advanced/button-interrupt/.cargo/config.toml index 773aceff..82e2a45c 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" } +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 diff --git a/advanced/button-interrupt/Cargo.toml b/advanced/button-interrupt/Cargo.toml index e4c5bd7c..889d87ad 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/rust-toolchain.toml b/advanced/button-interrupt/rust-toolchain.toml index a4b1ace3..6518c18d 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 773aceff..82e2a45c 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" } +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 diff --git a/advanced/i2c-driver/Cargo.toml b/advanced/i2c-driver/Cargo.toml index e863bb58..dff3f056 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 a4b1ace3..6518c18d 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 773aceff..82e2a45c 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" } +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 diff --git a/advanced/i2c-sensor-reading/Cargo.toml b/advanced/i2c-sensor-reading/Cargo.toml index e396e4fe..f719e5ba 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 a4b1ace3..6518c18d 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/03_5_3_mqtt.md b/book/src/03_5_3_mqtt.md index 6d00e460..e0d600b2 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) ## Handling Incoming Messages -The `message_event` parameter in the handler closure is of type `Result`. -Since we're only interested in processing successfully received messages, we can make use of deep pattern matching into the closure: +The `message_event` parameter in the handler closure is of type `EspMqttEvent`, which has a `payload()` method to access the `EventPayload` +Since we're only interested in processing successfully received messages: ```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}} ``` In the processing function, you will handle `Complete` messages. @@ -59,21 +51,7 @@ In the processing function, you will handle `Complete` messages. 💡 Use Rust Analyzer to generate the missing match arms or match any other type of response by logging an `info!()`. ```rust -match message.details() { - // All messages in this exercise will be of type `Complete` - // The other variants of the `Details` enum are for larger message payloads - Complete => { - - // Cow<&[u8]> can be coerced into a slice &[u8] or a Vec - // You can coerce it into a slice to be sent to try_from() - let message_data: &[u8] = &message.data(); - if let Ok(ColorData::BoardLed(color)) = ColorData::try_from(message_data) { - // Set the LED to the newly received color - - } - } - // Use Rust Analyzer to generate the missing match arms or match an incomplete message with a log message. -} +{{#include ../../intro/mqtt/exercise/examples/solution_publ_rcv.rs:process_message}} ``` 💡 Use a logger to see what you are receiving, for example, `info!("{}", color);` or `dbg!(color)`. @@ -98,7 +76,6 @@ let raw = RawCommandData { path: command, data: message.data(), }; - ``` Check the `host-client`: @@ -109,36 +86,6 @@ Check the `host-client`: let command = Command::BoardLed(color) ``` -✅ in the `process_message()` function, you will need to parse the topic. - -```rust -match message.details() { - Complete => { - // All messages in this exercise will be of type `Complete` - // the other variants of the `Details` enum - // are for larger message payloads - - // Cow behaves a lot like other Rust strings (&str, String) - let topic: Cow = message.topic(token); - - // Determine if we're interested in this topic and - // Dispatch based on its content - let is_command_topic: bool = /* ... */; - if is_command_topic { - let raw = RawCommandData { /* ... */ }; - if let Ok(Command::BoardLed(color)) = Command::try_from(raw) { - // Set the LED to the newly received color - } - - }, - _ => {} - } -} -``` - -💡 Since you will be iterating over a MQTT topic, you will need to `split()` on a string returns an iterator. You can access a specific item from an iterator using [`nth()`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.nth). -💡 The solution implementing hierarchy can be run with `cargo run --example solution2`, while the solution without can be run with `cargo run` or `cargo run --example solution1` - ### Other Tasks ✅ Leverage [`serde_json`](https://docs.serde.rs/serde_json/) to encode/decode your message data as JSON. diff --git a/common/lib/get-uuid/Cargo.toml b/common/lib/get-uuid/Cargo.toml index 3f7ec605..69e08c8f 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 2008751d..24816fa8 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 773aceff..82e2a45c 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" } +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 diff --git a/common/lib/rgb-led/Cargo.toml b/common/lib/rgb-led/Cargo.toml index 837e004a..fb49a441 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 a4b1ace3..6518c18d 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 773aceff..82e2a45c 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" } +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 diff --git a/common/lib/wifi/Cargo.toml b/common/lib/wifi/Cargo.toml index eef032f5..8aa5c86c 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 a4b1ace3..6518c18d 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 7cffdf9e..8debbf35 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 59a1d6f1..f6304ef7 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" } +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 diff --git a/intro/hardware-check/Cargo.toml b/intro/hardware-check/Cargo.toml index 92f84249..1bb6d958 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 a4b1ace3..6518c18d 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 773aceff..82e2a45c 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" } +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 diff --git a/intro/http-client/Cargo.toml b/intro/http-client/Cargo.toml index e265b2ab..cff92ff5 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 a4b1ace3..6518c18d 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 773aceff..82e2a45c 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" } +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 diff --git a/intro/http-server/Cargo.toml b/intro/http-server/Cargo.toml index 69f54520..c26440ac 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 5640f314..d0487ee0 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 a4b1ace3..6518c18d 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 773aceff..16b2b703 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" } +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 diff --git a/intro/mqtt/exercise/Cargo.toml b/intro/mqtt/exercise/Cargo.toml index 4cf4277b..d59b9624 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 be34dd27..afda55c8 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 cdd00ea2..c8f01da4 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 a4b1ace3..6518c18d 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 b2cb597e..5aba2dd2 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 60012190..0fd8efea 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"