32
CONTENTS
7.6.2.9
Persistent state management
User scripts can read and write state variables which persist across power cycles. This is done by modifying the
global
persistent
table. For example, the following
log_boot_count
function, if
, can report the current cold boot number (and the
ordinal
function is a convenience for printing strings
like "1st", "2nd", "3rd", etc.).
local special_suffixes,ordinal
function log_boot_count()
local boot_count=persistent.boot_count or 0
boot_count=boo1
persistent.boot_count=boot_count
LOG("This is my "..ordinal(boot_count).." power cycle")
end
special_suffixes={"st","nd","rd"}
function ordinal(number)
local d=number%100
return tostring(number)..((d<11 or d>19) and special_suffixes[d%10] or "th")
end
Here, the "boot_count" key is used to store the number of boots. Like with ordinary Lua tables, nonexistent keys
have nil values; to remove a key from
persistent
, write nil to it.
Only strings can be used as keys of
persistent
. Only numbers, strings and booleans can be stored (or nil can
be written to erase a value). Some of these limitations may be raised in future.
All keys of
persistent
can be enumerated if necessary using
pairs()
.
7.6.2.10
Meter access
The global
meter
table allows to read the following measured values :
•
meter.values
: a table storing properties of different values measured by meters.
Keys of
meter.values
are unique human-readable but possibly platform-specific identifiers (e.g.
power_
←
-
voltage
), and values are tables with the following form:
•
meter.values[key].name
: human-readable name of the measured value;
•
meter.values[key].quantity
: kind of the physical quantity of the value (e.g. "current", "voltage",
etc.);
•
meter.values[key].value
: number representing the current value measured by the meter in stan-
dard units;
•
meter.values[key].custom
: boolean indicating if the value is custom (user-defined);
•
meter.values[key].bus
: always nil for LPC9;
•
meter.values[key].internal
: boolean indicating if the value is internal (and should not appear in
the web UI);
•
meter.values[key].get_history
: function which can be called to obtain historical data points.
DLI LPC9 User’s Guide: 1.7.24.0
Summary of Contents for LPC9
Page 1: ...DLI LPC9 User s Guide 1 7 24 0 ...
Page 81: ......