Storing a strucutre insde NVS

kartikkman
Posts: 15
Joined: Wed Jul 19, 2017 11:27 am

Storing a strucutre insde NVS

Postby kartikkman » Sat Nov 10, 2018 11:48 am

I need to store a Structure inside the NVS of ESP32, is it possible with the current APIs available somehow ??

Actual Problem is: I need to store the Alarms inside the ESP-32, which will be of following structure :

typedef struct
{

int minutes;
int hours;
int date ;

}Alarm ;


I will be storing multiple alarms inside the NVS & then fetching them at the startup.

tommeyers
Posts: 51
Joined: Tue Apr 17, 2018 1:51 pm
Location: Santiago, Dominican Republic

Re: Storing a strucutre insde NVS

Postby tommeyers » Sat Nov 10, 2018 2:54 pm

Why do you *need* to store it as a struct? What happened when you tried that? What else have you tried?

I recommend you begin here: https://math.hawaii.edu/home/pdf/putnam ... olveIt.pdf

Seriously, Tom Meyers
IT Professional, Maker
Santiago, Dominican Republic

WiFive
Posts: 2048
Joined: Tue Dec 01, 2015 7:35 am

Re: Storing a strucutre insde NVS

Postby WiFive » Sat Nov 10, 2018 4:01 pm

Make your struct into a 64bit value which is supported by nvs. Hours and minutes don't need to be 32bit values.

kartikkman
Posts: 15
Joined: Wed Jul 19, 2017 11:27 am

Re: Storing a strucutre insde NVS

Postby kartikkman » Sat Nov 10, 2018 4:35 pm

Hi , Thanks for looking into my issue .

Are you suggesting me to convert the structure into byte & then saving that byte data into NVS?

At the Time of Retrieving, I cast that byte into the structure.

Like this : https://stackoverflow.com/questions/137 ... -to-struct

Who is online

Users browsing this forum: Google [Bot] and 13 guests