Skip to content

Upgrade esp_idf_svc to 0.48.1 #243

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

Closed
Closed
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
2 changes: 1 addition & 1 deletion advanced/button-interrupt/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ESP_IDF_VERSION = { value = "tag:v5.1.2" }
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" }
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
2 changes: 1 addition & 1 deletion advanced/button-interrupt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ opt-level = "z"

[dependencies]
anyhow = "=1.0.75"
esp-idf-svc = "=0.47.3"
esp-idf-svc = "=0.48.1"
rgb-led = { path = "../../common/lib/rgb-led" }

[build-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion advanced/i2c-driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ opt-level = "z"
[dependencies]
anyhow = "=1.0.75"
embedded-hal = "=0.2.7"
esp-idf-svc = "=0.47.3"
esp-idf-svc = "=0.48.1"

[build-dependencies]
embuild = "=0.31.4"
2 changes: 1 addition & 1 deletion advanced/i2c-sensor-reading/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ESP_IDF_VERSION = { value = "tag:v5.1.2" }
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" }
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
2 changes: 1 addition & 1 deletion advanced/i2c-sensor-reading/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ opt-level = "z"
[dependencies]
anyhow = "=1.0.75"
embedded-hal = "=0.2.7"
esp-idf-svc = "=0.47.3"
esp-idf-svc = "=0.48.1"
icm42670 = "=0.1.1"
lis3dh = "=0.4.2"
shared-bus = "=0.3.1"
Expand Down
46 changes: 23 additions & 23 deletions book/src/03_5_3_mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,36 @@ The `message_event` parameter in the handler closure is of type `Result<Event<Es
Since we're only interested in processing successfully received messages, we can make use of deep pattern matching into the closure:

```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),
},
)?;
EspMqttClient::new_cb(
&broker_url,
&mqtt_config,
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()),
},
)?;
```

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

fn process_message(data: &[u8], details: Details, led: &mut WS2812RMT) {
match details {
Complete => {
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) {
error!("Could not set board LED: {:?}", e)
};
}
}
_ => {}
}
// Use Rust Analyzer to generate the missing match arms or match an incomplete message with a log message.
}
```

Expand Down Expand Up @@ -112,14 +112,14 @@ let command = Command::BoardLed(color)
✅ in the `process_message()` function, you will need to parse the topic.

```rust
match message.details() {
match 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);
let topic: Cow<str> = topic(token);

// Determine if we're interested in this topic and
// Dispatch based on its content
Expand Down
2 changes: 1 addition & 1 deletion common/lib/rgb-led/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Sergio Gasquez <sergio.gasquez@gmail.com>"]

[dependencies]
anyhow = "=1.0.75"
esp-idf-svc = "=0.47.3"
esp-idf-svc = "=0.48.1"
log = "=0.4.20"
rgb = "0.8.29"

Expand Down
2 changes: 1 addition & 1 deletion common/lib/wifi/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ESP_IDF_VERSION = { value = "tag:v5.1.2" }
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" }
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
2 changes: 1 addition & 1 deletion common/lib/wifi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Sergio Gasquez <sergio.gasquez@gmail.com>"]

[dependencies]
anyhow = "=1.0.75"
esp-idf-svc = "=0.47.3"
esp-idf-svc = "=0.48.1"
log = "=0.4.20"

[build-dependencies]
Expand Down
4 changes: 2 additions & 2 deletions common/lib/wifi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub fn wifi(
};

wifi.set_configuration(&Configuration::Client(ClientConfiguration {
ssid: ssid.into(),
password: pass.into(),
ssid: ssid.try_into().expect("SSID does not fit into String<32> buffer"),
password: pass.try_into().expect("Password does not fit into String<64> buffer"),
channel,
auth_method,
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion intro/hardware-check/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ESP_IDF_VERSION = { value = "tag:v5.1.2" }
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" }
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
2 changes: 1 addition & 1 deletion intro/hardware-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ opt-level = "z"

[dependencies]
anyhow = "=1.0.75"
esp-idf-svc = "=0.47.3"
esp-idf-svc = "=0.48.1"
log = "=0.4.20"
rgb-led = { path = "../../common/lib/rgb-led" }
toml-cfg = "=0.1.3"
Expand Down
2 changes: 1 addition & 1 deletion intro/http-client/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ESP_IDF_VERSION = { value = "tag:v5.1.2" }
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" }
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
4 changes: 2 additions & 2 deletions intro/http-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ opt-level = "z"

[dependencies]
anyhow = "=1.0.75"
embedded-svc = "=0.26.4"
esp-idf-svc = "=0.47.3"
embedded-svc = "0.27.1"
esp-idf-svc = "=0.48.1"
toml-cfg = "=0.1.3"
wifi = { path = "../../common/lib/wifi" }

Expand Down
2 changes: 1 addition & 1 deletion intro/http-server/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ESP_IDF_VERSION = { value = "tag:v5.1.2" }
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" }
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
6 changes: 3 additions & 3 deletions intro/http-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ opt-level = "z"

[dependencies]
anyhow = "=1.0.75"
embedded-svc = "=0.26.4"
esp-idf-svc = "=0.47.3"
embedded-svc = "0.27.1"
esp-idf-svc = "=0.48.1"
shtcx = "=0.11.0"
toml-cfg = "=0.1.3"
wifi = { path = "../../common/lib/wifi" }

[build-dependencies]
embuild = "=0.31.4"
toml-cfg = "=0.1.3"
toml-cfg = "=0.1.3"
10 changes: 4 additions & 6 deletions intro/http-server/examples/http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ use anyhow::Result;
use core::str;
use embedded_svc::{http::Method, io::Write};
use esp_idf_svc::{
eventloop::EspSystemEventLoop,
hal::{
eventloop::EspSystemEventLoop, hal::{
i2c::{I2cConfig, I2cDriver},
prelude::*,
},
http::server::{Configuration, EspHttpServer},
}, http::server::{Configuration, EspHttpServer}, io::EspIOError, sys::EspError
};
use shtcx::{self, shtc3, PowerMode};
use std::{
Expand Down Expand Up @@ -59,15 +57,15 @@ fn main() -> Result<()> {
// Set the HTTP server
let mut server = EspHttpServer::new(&Configuration::default())?;
// http://<sta ip>/ handler
server.fn_handler("/", Method::Get, |request| {
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://<sta ip>/temperature handler
server.fn_handler("/temperature", Method::Get, move |request| {
server.fn_handler("/temperature", Method::Get, move |request| -> core::result::Result<(), EspIOError> {
let temp_val = temp_sensor
.lock()
.unwrap()
Expand Down
32 changes: 2 additions & 30 deletions intro/http-server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use anyhow::Result;
use core::str;
use embedded_svc::{http::Method, io::Write};
use esp_idf_svc::{
eventloop::EspSystemEventLoop,
hal::{
i2c::{I2cConfig, I2cDriver},
prelude::*,
},
http::server::{Configuration, EspHttpServer},
};
use shtcx::{self, shtc3, PowerMode};
use std::{
Expand Down Expand Up @@ -50,7 +48,7 @@ fn main() -> Result<()> {
let config = I2cConfig::new().baudrate(100.kHz().into());
let i2c = I2cDriver::new(i2c, sda, scl, &config)?;
let temp_sensor_main = Arc::new(Mutex::new(shtc3(i2c)));
let mut temp_sensor = temp_sensor_main.clone();
let temp_sensor = temp_sensor_main.clone();
temp_sensor
.lock()
.unwrap()
Expand All @@ -72,30 +70,4 @@ fn main() -> Result<()> {
loop {
sleep(Duration::from_millis(1000));
}
}

fn templated(content: impl AsRef<str>) -> String {
format!(
r#"
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>esp-rs web server</title>
</head>
<body>
{}
</body>
</html>
"#,
content.as_ref()
)
}

fn index_html() -> String {
templated("Hello from mcu!")
}

fn temperature(val: f32) -> String {
templated(format!("chip temperature: {:.2}°C", val))
}
}
2 changes: 1 addition & 1 deletion intro/mqtt/exercise/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ ESP_IDF_VERSION = { value = "tag:v5.1.2" }
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" }
ESP_IDF_TOOLS_INSTALL_DIR = { value = "global" }
4 changes: 2 additions & 2 deletions intro/mqtt/exercise/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ opt-level = "z"

[dependencies]
anyhow = "=1.0.75"
embedded-svc = "=0.26.4"
esp-idf-svc = "=0.47.3"
embedded-svc = "0.27.1"
esp-idf-svc = "=0.48.1"
get-uuid = { path = "../../../common/lib/get-uuid" }
log = "=0.4.20"
mqtt-messages = { path = "../../../common/lib/mqtt-messages" }
Expand Down
6 changes: 3 additions & 3 deletions intro/mqtt/exercise/cfg.toml.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[mqtt]
mqtt_user = "horse"
mqtt_pass = "CorrectHorseBatteryStaple"
mqtt_host = "yourpc.local"
mqtt_user = "horsea"
mqtt_pass = "CorrectaHorseBatteryStaple"
mqtt_host = "yourpca.local"
wifi_ssid = "FBI Surveillance Van"
wifi_psk = "hunter2"

Expand Down
2 changes: 1 addition & 1 deletion intro/mqtt/exercise/examples/solution_publ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ 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
})?;
Expand Down
25 changes: 14 additions & 11 deletions intro/mqtt/exercise/examples/solution_publ_rcv.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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::{
delay,
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};
Expand Down Expand Up @@ -78,12 +80,13 @@ fn main() -> Result<()> {

// 1. Create a client with default configuration and empty handler
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()),
},
)?;

Expand All @@ -109,18 +112,18 @@ fn main() -> Result<()> {
}
}

fn process_message(message: &EspMqttMessage, led: &mut WS2812RMT) {
match message.details() {
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) {
error!("Could not set board LED: {:?}", e)
};
}
}
_ => error!("Could not set board LED"),
_ => {}
}
}
Loading