@@ -495,11 +495,25 @@ String Preferences::getString(const char* key, const String defaultValue){
495
495
}
496
496
497
497
size_t Preferences::getBytesLength (const char * key){
498
- size_t len = 0 ;
499
498
if (!_started || !key){
500
499
return 0 ;
501
500
}
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
+
503
517
if (err){
504
518
ESP_LOGE (__FILE__, " nvs_get_blob len fail: %s %s" , key, nvs_error (err));
505
519
return 0 ;
0 commit comments