@@ -53,10 +53,14 @@ bool Preferences::begin(const char * name, bool readOnly, const char* partition_
53
53
return true ;
54
54
}
55
55
56
- void Preferences::end (){
56
+ void Preferences::end (){ // modified to add an nvs_commit()
57
57
if (!_started){
58
58
return ;
59
59
}
60
+ esp_err_t err = nvs_commit (_handle); // to undo changes: delete the lines from here...
61
+ if (err){
62
+ log_e (" nvs_commit fail: %s %s" , key, nvs_error (err));
63
+ } // ... to here.
60
64
nvs_close (_handle);
61
65
_started = false ;
62
66
}
@@ -65,7 +69,7 @@ void Preferences::end(){
65
69
* Clear all keys in opened preferences
66
70
* */
67
71
68
- bool Preferences::clear (){
72
+ bool Preferences::clear (){ // modified to add an nvs_commit()
69
73
if (!_started || _readOnly){
70
74
return false ;
71
75
}
@@ -74,14 +78,20 @@ bool Preferences::clear(){
74
78
log_e (" nvs_erase_all fail: %s" , nvs_error (err));
75
79
return false ;
76
80
}
77
- return true ;
81
+ // return true; // to undo changes: uncomment this line and...
82
+ err = nvs_commit (_handle); // ... delete the lines from from here...
83
+ if (err){
84
+ log_e (" nvs_commit fail: %s" , nvs_error (err));
85
+ return false ;
86
+ }
87
+ return true ; // ... to here.
78
88
}
79
89
80
90
/*
81
91
* Remove a key
82
92
* */
83
93
84
- bool Preferences::remove (const char * key){
94
+ bool Preferences::remove (const char * key){ // modified to add an nvs_commit()
85
95
if (!_started || !key || _readOnly){
86
96
return false ;
87
97
}
@@ -90,7 +100,13 @@ bool Preferences::remove(const char * key){
90
100
log_e (" nvs_erase_key fail: %s %s" , key, nvs_error (err));
91
101
return false ;
92
102
}
93
- return true ;
103
+ // return true; // to undo changes: uncomment this line and...
104
+ err = nvs_commit (_handle); // ... delete the lines from from here...
105
+ if (err){
106
+ log_e (" nvs_commit fail: %s %s" , key, nvs_error (err));
107
+ return false ;
108
+ }
109
+ return true ; // ... to here.
94
110
}
95
111
96
112
/*
0 commit comments