esp-rs / esp-idf-svc

Type-Safe Rust Wrappers for various ESP-IDF services (WiFi, Network, Httpd, Logging, etc.)
https://docs.esp-rs.org/esp-idf-svc/
Apache License 2.0
333 stars 183 forks source link

Write to a file on SPIFFS esp32 file system. #522

Closed byfarm closed 5 days ago

byfarm commented 5 days ago

Hello,

I was looking around the documentation and I am having trouble finding how to use the SPIFFS file system on the esp32. Looking at espressif's documentation here, it looks to be possible to read and write to a file. However, as I am poling around the rust project's website I can find a few functions that look like they could do this functionality, but no documentation on how to implement it.

The project I am writing is so that a client can send a message to a server running on an esp32, and the server to store the information. The client can then request to receive the messages it wrote to the server. So far I can send messages to the server, but the server cannot store the information. I was thinking that the server could write the message to a file, and then it can access the information when it needs to.

I am a rust newbie so any help would be appreciated. Thank you!

ivmarkov commented 5 days ago

1 - Use this example as a starting point: https://github.com/esp-rs/esp-idf-svc/blob/master/examples/sd_mmc.rs ; note that it uses FatFS; I would not recommend using Spiffs anyway 2 - Use esp-idf-svc and the other esp-idf-* crates from master rather than the released ones (as this feature is rather new) by using the patch.crates-io syntax that you can read about in the Cargo book; and enable the experimental feature on the svc crate to see these APIs 3 - Best to ask questions in the esp-rs Matrix chat rather than opening bugs asking for help here, as addressing those is very time consuming :)

BTW: If you plan to use the internal flash storage of the esp32 rather than an external SD cartd, the API would be slightly different, and you need to deal with ESP IDF partitions, updating the partition table and so on.