/*
Using this page as a guide https://randomnerdtutorials.com/esp32-s ... eferences/
the following code prints the following to the serial monitor:
data saved
5
5
why does it not print?
hello
world
*/
#include <Preferences.h>
Preferences preferences;
const char* line1 = "hello";
const char* line2 = "world";
//String line1 = "hello"; // this produces same results
//String line2 = "world"; // this produces same results
void setup() {
Serial.begin(115200);
Serial.println();
preferences.begin("any_name_here", false);
preferences.putString("line1", line1);
preferences.putString("line2", line2);
Serial.println("data saved ");
Serial.println(preferences.putString("line1", line1));
Serial.println(preferences.putString("line2", line2));
preferences.end();
}
void loop() {
}
As always, any and all help appreciated
Need help with Preferences.h
-
- Posts: 828
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Need help with Preferences.h
putString returns the number of characters saved to the key. This can be compared to the expected string length to ensure success. Perhaps you were looking for getString?
-
- Posts: 14
- Joined: Sat Oct 14, 2017 2:05 pm
Re: Need help with Preferences.h
Thank you lbernstone
Yes, it is so obvious now.
I cut and pasted from the lines above and did not change putString to getString!
Thanks again.
Case closed
Yes, it is so obvious now.
I cut and pasted from the lines above and did not change putString to getString!
Thanks again.
Case closed
Who is online
Users browsing this forum: No registered users and 155 guests