Skip to content

Commit ddb8ecb

Browse files
fixup! added preferences class from esp arduino core
1 parent f6750c2 commit ddb8ecb

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

main/Preferences.cpp

+16-2
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,25 @@ String Preferences::getString(const char* key, const String defaultValue){
495495
}
496496

497497
size_t Preferences::getBytesLength(const char* key){
498-
size_t len = 0;
499498
if(!_started || !key){
500499
return 0;
501500
}
502-
esp_err_t err = nvs_get_blob(_handle, key, NULL, &len);
501+
esp_err_t err = ESP_OK;
502+
503+
int8_t mt1; uint8_t mt2; int16_t mt3; uint16_t mt4;
504+
int32_t mt5; uint32_t mt6; int64_t mt7; uint64_t mt8;
505+
size_t len = 0;
506+
if ((err = nvs_get_i8(_handle, key, &mt1)) == ESP_OK) { len = sizeof(mt1);
507+
} else if((err = nvs_get_u8(_handle, key, &mt2)) == ESP_OK) { len = sizeof(mt2);
508+
} else if((err = nvs_get_i16(_handle, key, &mt3)) == ESP_OK) { len = sizeof(mt3);
509+
} else if((err = nvs_get_u16(_handle, key, &mt4)) == ESP_OK) { len = sizeof(mt4);
510+
} else if((err = nvs_get_i32(_handle, key, &mt5)) == ESP_OK) { len = sizeof(mt5);
511+
} else if((err = nvs_get_u32(_handle, key, &mt6)) == ESP_OK) { len = sizeof(mt6);
512+
} else if((err = nvs_get_i64(_handle, key, &mt7)) == ESP_OK) { len = sizeof(mt7);
513+
} else if((err = nvs_get_u64(_handle, key, &mt8)) == ESP_OK) { len = sizeof(mt8);
514+
} else if((err = nvs_get_str(_handle, key, NULL, &len)) == ESP_OK) {
515+
} else if((err = nvs_get_blob(_handle, key, NULL, &len)) == ESP_OK) {}
516+
503517
if(err){
504518
ESP_LOGE(__FILE__, "nvs_get_blob len fail: %s %s", key, nvs_error(err));
505519
return 0;

0 commit comments

Comments
 (0)