The data I am trying to save is as follows:
Code: Select all
#define NUMBER_SCHEDULES 50
typedef struct {
uint8_t solenoid; // 1 to 4
uint8_t dayWeek; // bit 0 - Sunday, bit 1 - Monday, etc.
uint8_t hour; // 0 to 23
uint8_t minute; // 0 to 59
uint8_t duration; // in minutes
} timer_schedule;
timer_schedule schedules[NUMBER_SCHEDULES];
Code: Select all
nvs_handle my_handle;
esp_err_t err = nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &my_handle);
if (err != ESP_OK) return err;
size_t scheduleSize = sizeof(schedules);
err = nvs_set_blob(my_handle, "schedule", &schedules, scheduleSize);
if (err != ESP_OK) return err;
err = nvs_commit(my_handle);
if (err != ESP_OK) return err;
nvs_close(my_handle);
Code: Select all
nvs_handle my_handle;
esp_err_t err = nvs_open(STORAGE_NAMESPACE, NVS_READWRITE, &my_handle);
if (err != ESP_OK) return err;
size_t required_size = 0;
err = nvs_get_blob(my_handle, "schedule", NULL, &required_size);
if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) return err;
if (required_size == 0) {
printf("Schedule not saved yet!\n");
} else {
size_t scheduleSize = sizeof(schedules);
err = nvs_get_blob(my_handle, "schedule", &schedules, &scheduleSize);
if (err != ESP_OK) return err;
}
// ******* print out 'schedules' array here and find garbage in it ********
nvs_close(my_handle);