Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update training to latest releases #257

Merged
merged 5 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions advanced/button-interrupt/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions advanced/button-interrupt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
2 changes: 1 addition & 1 deletion advanced/button-interrupt/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-14"
channel = "nightly-2024-06-30"
components = ["rust-src"]
3 changes: 1 addition & 2 deletions advanced/i2c-driver/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions advanced/i2c-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
2 changes: 1 addition & 1 deletion advanced/i2c-driver/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-14"
channel = "nightly-2024-06-30"
components = ["rust-src"]
3 changes: 1 addition & 2 deletions advanced/i2c-sensor-reading/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions advanced/i2c-sensor-reading/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
2 changes: 1 addition & 1 deletion advanced/i2c-sensor-reading/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-14"
channel = "nightly-2024-06-30"
components = ["rust-src"]
61 changes: 4 additions & 57 deletions book/src/03_5_3_mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,41 +39,19 @@ client.subscribe(subscribe_topic, QoS::AtLeastOnce)
## Handling Incoming Messages


The `message_event` parameter in the handler closure is of type `Result<Event<EspMqttMessage>`.
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.

💡 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<u8>
// 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)`.
Expand All @@ -98,7 +76,6 @@ let raw = RawCommandData {
path: command,
data: message.data(),
};

```

Check the `host-client`:
Expand All @@ -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<str> behaves a lot like other Rust strings (&str, String)
let topic: Cow<str> = 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.
Expand Down
6 changes: 3 additions & 3 deletions common/lib/get-uuid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
2 changes: 1 addition & 1 deletion common/lib/mqtt-messages/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ authors = [
edition = "2021"

[dependencies]
rgb = "=0.8.37"
rgb = "=0.8.40"
3 changes: 1 addition & 2 deletions common/lib/rgb-led/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions common/lib/rgb-led/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ edition = "2021"
authors = ["Sergio Gasquez <sergio.gasquez@gmail.com>"]

[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"
2 changes: 1 addition & 1 deletion common/lib/rgb-led/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-14"
channel = "nightly-2024-06-30"
components = ["rust-src"]
3 changes: 1 addition & 2 deletions common/lib/wifi/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions common/lib/wifi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ edition = "2021"
authors = ["Sergio Gasquez <sergio.gasquez@gmail.com>"]

[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"
2 changes: 1 addition & 1 deletion common/lib/wifi/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-14"
channel = "nightly-2024-06-30"
components = ["rust-src"]
8 changes: 6 additions & 2 deletions common/lib/wifi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions intro/hardware-check/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions intro/hardware-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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"
2 changes: 1 addition & 1 deletion intro/hardware-check/rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-11-14"
channel = "nightly-2024-06-30"
components = ["rust-src"]
3 changes: 1 addition & 2 deletions intro/http-client/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading