Retrieve specified string from currently open namespace. If record doesn't exist, the String pin will output "NA".
get-string
@/get-string
Retrieve specified string from currently open namespace. If record doesn't exist, the String pin will output "NA".
Prefs@/preferences
A preferences object.
Keystring
Key name. Limited to 15 chars.
Sizenumber
Maximum size of string (number of bytes). Must be a constant value. Any changes during program execution will be ignored.
UPDpulse
Update
Donepulse
Pulse on read.
Stringstring
String retrieved from storage (or "NA" if key doesn't exist).
To use the node in your project you should have the wayland/esp32-preferences library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.
C++ implementation
#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_UPD
node {
CStringView view;
char* cString;
size_t cap;
void evaluate(Context ctx) {
if (isSettingUp()) {
cap = getValue<input_Size>(ctx) + 1;
cString = new char[cap];
view = CStringView(cString);
}
if (isInputDirty<input_UPD>(ctx)) {
auto prefs = getValue<input_Prefs>(ctx);
auto xStringKey = getValue<input_Key>(ctx);
int N=length(xStringKey);
if (N>15 || N<1) {
raiseError(ctx);
return;
}
N +=1;
char cStringKey[N];
for(int i=0;i<N;i++)
cStringKey[i]=0;
dump(xStringKey, cStringKey);
String str = prefs -> getString(cStringKey, "NA");
int strLen = str.length() + 1;
str.toCharArray(cString, strLen);
emitValue<output_String>(ctx, XString(&view));
emitValue<output_Done>(ctx, 1);
}
}
}