Skip to content

Commit b6508c3

Browse files
committed
Preferences examples: add begin return value check
- This library works only if WiFi firmware version is greater than 0.3.0
1 parent 83f6d7b commit b6508c3

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

libraries/Preferences/examples/Prefs2Struct/Prefs2Struct.ino

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ typedef struct {
1717
void setup() {
1818
Serial.begin(115200);
1919

20-
prefs.begin("schedule"); // use "schedule" namespace
20+
if (!prefs.begin("schedule")) { // use "schedule" namespace
21+
Serial.println("Cannot initialize preferences");
22+
Serial.println("Make sure your WiFi firmware version is greater than 0.3.0");
23+
while(1) {};
24+
}
2125
uint8_t content[] = {9, 30, 235, 255, 20, 15, 0, 1}; // two entries
2226
prefs.putBytes("schedule", content, sizeof(content));
2327
size_t schLen = prefs.getBytesLength("schedule");

libraries/Preferences/examples/StartCounter/StartCounter.ino

+5-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ void setup() {
2121
// has to use a namespace name to prevent key name collisions. We will open storage in
2222
// RW-mode (second parameter has to be false).
2323
// Note: Namespace name is limited to 15 chars.
24-
int ret = preferences.begin("my-app", false);
25-
Serial.println(ret);
24+
if (!preferences.begin("my-app", false)) {
25+
Serial.println("Cannot initialize preferences");
26+
Serial.println("Make sure your WiFi firmware version is greater than 0.3.0");
27+
while(1) {};
28+
}
2629

2730
// Remove all preferences under the opened namespace
2831
//preferences.clear();

0 commit comments

Comments
 (0)