DEV Community

Cover image for Edge IoT with Rust on ESP: MQTT Subscriber

Edge IoT with Rust on ESP: MQTT Subscriber

Omar Hiari on November 19, 2023

This blog post is the sixth of a multi-part series of posts where I explore various peripherals in the ESP32C3 using standard library embedded Rus...
Collapse
 
ananthnarayanan profile image
Ananth • Edited

The part where wifi configuration is set,
ssid & password are String32 & String 64 respectively.

"some string".into()
throws error saying,

expected String<32>, found &str

can be resolved by using,

"some string".try_into()

Collapse
 
apollolabsbin profile image
Omar Hiari

That's odd, the example code replicated on Wokwi here builds fine. Additionally, I think the suggested code would still blow an error as try_into() returns a Result that needs to be unwrapped.

Either way, I referred back to the source of the embedded-svc for the same version of the crate being used in the example, in the Default implementation of ClientConfiguration here, into() is being used as well for the heapless::String<32> and heapless::String<64> types returning the expected type without error.

Collapse
 
apollolabsbin profile image
Omar Hiari

Update: I replicated the issue but in a more recent version of the embedded-svc crate, try_into().unwrap() seems to solve the issue like suggested. Another option is to used the heapless::String from_str method.

Thanks for your input!

Collapse
 
iceshare profile image
Jonas Yde • Edited

Thanks for the great tutorial, helps a lot with getting into rust on esp32.

However i have an issue when trying to compile the application. I'm using a esp32-wroom-32 (xtensa), i've ajusted my target to this and can build/flash simple hello world applications just fine).

I get this error when running cargo run:


error[E0432]: unresolved import
core::sync::atomic::AtomicU64
--> C:\Users\jjy19\.cargo\registry\src\index.crates.io-6f17d22bba15001f\esp-idf-hal-0.41.2\src\interrupt.rs:1:26
|
1 | use core::sync::atomic::{AtomicU64, Ordering};
| ^^^^^^^^^
| |
| no
AtomicU64insync::atomic
| help: a similar name exists in the module:
AtomicU32

Image description

seems like it's trying to build 64 bit code to my 32 bit machine?

Collapse
 
apollolabsbin profile image
Omar Hiari

I get these sometimes. It was an issue with an older release. If you update to the latest crate versions the error should disappear.