esp-idf-svc icon indicating copy to clipboard operation
esp-idf-svc copied to clipboard

Commented Storage for EspNvsStorage implementation. No get/put functions on EspNvsStorage.

Open jBernavaPrah opened this issue 3 years ago • 3 comments
trafficstars

Hi, I'm new to esp-rs and I'm trying to play a little.

I saw, thanks to github examples, that the version esp-idf-svc = "0.36.1", has convenient api for the storage.

let nvs = Arc::new(EspDefaultNvs::new()?);
let mut storage = EspNvsStorage::new_default(nvs.clone(), "config", true)?;

if !storage.contains("configured")? {
    storage.put(WIFI_SSID_KEY, &env!("WIFI_SSID"))?;
    storage.put(WIFI_PASS_KEY, &env!("WIFI_PASS"))?;
    storage.put("configured", &"true")?;
    info!("stored creds");
}

let ssid: String = storage.get(WIFI_SSID_KEY)?.unwrap();
let password: String = storage.get(WIFI_PASS_KEY)?.unwrap();

But the latest version esp-idf-svc = "0.42.1", the one that I'm using now, the implementation of the Storage for EspNvsStorage has been commented with a TODO.

// TODO
// impl Storage for EspNvsStorage {
//     fn get<'a, T>(&'a self, name: &str) -> Result<Option<T>, Self::Error>
//     where
//         T: serde::Deserialize<'a> {
//         todo!()
//     }

//     fn set<T>(&mut self, name: &str, value: &T) -> Result<bool, Self::Error>
//     where
//         T: serde::Serialize {
//         todo!()
//     }
// }

Is this because there is a different way to use those functions? In this case, an example will be super useful.

jBernavaPrah avatar Aug 06 '22 15:08 jBernavaPrah

The get/put API will return (sort of) with the next major release of embedded-svc. You can preview it currently in branch next. It will however NOT be 100% backward compatible with what used to be there.

What used to be there was hard-wired to json serialization which is (a) verbose (b) the way the API looked like it could not be implemented without allocations. The new embedded-svc defines the traits in a way where it is guaranteed they can be implemented in no_std and without allocations, as the current STD and allocating implementation based in esp-idf will hopefully not be the only one in future.

You can keep this issue open until the next branch is released.

ivmarkov avatar Aug 06 '22 18:08 ivmarkov

Thanks for the response!

I’m not seeing the implementation of the Storage on the next branch, as you mentioned. :(

When do you think will be available the major update?

jBernavaPrah avatar Aug 07 '22 10:08 jBernavaPrah

Thanks for the response!

I’m not seeing the implementation of the Storage on the next branch, as you mentioned. :(

It is in the next branch of embedded-svc.

When do you think will be available the major update?

In a few weeks.

ivmarkov avatar Aug 07 '22 14:08 ivmarkov

Any updates regarding this? I too am new to esp-rs and find myself using this feature in a future project. I am open to contributing towards the get/put API, or something similar to enable access to the permanent flash memory on the esp.

DS3a avatar Nov 26 '22 07:11 DS3a

This is released since a week. Check CHANGELOG.md in embedded-svc root and in esp-idf-svc root.

ivmarkov avatar Nov 26 '22 09:11 ivmarkov