πŸ“¦ Archived documentation: r1 (committed 2026-07-24) View current documentation β†’

nv

Battery-backed non-volatile memory (4 kB) for setpoints, user tables and other state that must survive restarts.

Available on: Flexs Q5C Flexs Q5M

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()

nv.get([offset]) β†’ string | undefined

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

NameTypeRequiredDefaultDescription
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"

nv.set()

nv.set(data, [offset])

Stores a string in non-volatile memory.

Writes data at offset (default 0). Serialise objects with string() first. Take care that regions written at different offsets don't overlap.

Arguments

NameTypeRequiredDefaultDescription
data string yes β€” The string to store β€” use string(obj) for objects.
offset number optional 0 Byte offset within the 4 kB memory.

Example

nv.set(string(sp));          // setpoints at offset 0
nv.set(string(users), 2048); // users table at offset 2048