NVS Storage not retrieving strings, but ints work fine
Posted: Thu Aug 03, 2017 6:49 pm
So I have code that saves json text so the esp32 can store collected data.
The problem is that although I can save it properly ( the print reads the exact string it should ) it can not load it, and gives me a blank space
Here is the saving code:
Here is the loading code:
The timer loads perfectly fine, it's just as soon as the string is attempted to be read that it breaks. Also, the size_required actually gives you the proper size of the string. Somehow it still gives a blank text
The problem is that although I can save it properly ( the print reads the exact string it should ) it can not load it, and gives me a blank space
Here is the saving code:
Code: Select all
printf("wOS: Saving collected data into NVS...\n");
const char* data = GetDataCollected();
printf("%s\n", data ); //Prints the correct value
err = nvs_set_str(storage_device, "DataCollected", data );
printf((err != ESP_OK) ? "wOS: Failed to save Collected Data\n" : "wOS: Successfully saved Collected Data!\n");
Code: Select all
size_t required_size;
err = nvs_get_str(storage_device, "DataCollected", NULL, &required_size );
switch (err) {
case ESP_OK:
printf("wOS: Successfully grabbed size, loading in value..\n");
char* SavedData = malloc(required_size);
err = nvs_get_str( storage_device, "DataCollected", &SavedData, &required_size );
printf( "Downloaded Data: %s\n", SavedData );
ApplyLoadedData( &SavedData );
int timr = 0;
nvs_get_i32( storage_device, "CurrentTime", &timr );
printf( "Timer: %d", timr );
SetTimeKeeper( timr );
printf("wOS: Successfully loaded data!\n");
break;
case ESP_ERR_NVS_NOT_FOUND:
printf("wOS: There is no saved data on file.\n");
break;
default :
printf("wOS: Error (%d) reading!\n", err);
} size_t required_size;
err = nvs_get_str(storage_device, "DataCollected", NULL, &required_size );
switch (err) {
case ESP_OK:
printf("wOS: Successfully grabbed size, loading in value..\n");
char* SavedData = malloc(required_size);
err = nvs_get_str( storage_device, "DataCollected", &SavedData, &required_size );
printf( "Downloaded Data: %s\n", SavedData ); //Prints completely blank
ApplyLoadedData( &SavedData );
int timr = 0;
nvs_get_i32( storage_device, "CurrentTime", &timr );
printf( "Timer: %d", timr );
SetTimeKeeper( timr );
printf("wOS: Successfully loaded data!\n");
break;
case ESP_ERR_NVS_NOT_FOUND:
printf("wOS: There is no saved data on file.\n");
break;
default :
printf("wOS: Error (%d) reading!\n", err);
}