The nv object stores strings in 4 kB of battery-backed non-volatile memory.
It is ideal for operator setpoints, calibration values or user tables that
must survive script restarts and power cycles.
The standard pattern is to keep state in an object with sensible defaults,
serialise it with string() on save, and merge it key-by-key on load — that
way, new setpoints added to the code keep their defaults when an older saved
configuration is loaded. See the Non-Volatile Setpoint Storage example.
Multiple objects can share the memory by using the optional byte offset —
e.g. setpoints at offset 0 and a users table at offset 2048, splitting
the 4 kB in half.
Functions
nv.get() — Loads a string from non-volatile memory; undefined when no valid data is stored.
nv.set() — Stores a string in non-volatile memory.
Loads a string from non-volatile memory; undefined when no valid data is stored.
Reads the string stored at offset (default 0). Returns undefined if no
valid string is detected — this can happen if the memory backup battery goes
dead, so always handle the undefined case by falling back to defaults.
Arguments
Name
Type
Required
Default
Description
offset
number
optional
0
Byte offset within the 4 kB memory.
Returns
string | undefined
The stored string, or undefined when nothing valid is stored.
Example
nv.set("abcd");
nv.set("1234",2048);
let msg1 = nv.get();
let msg2 = nv.get(2048);
print(msg1); // msg1 = "abcd"
print(msg2); // msg2 = "1234"