7 Scripting
33
The
get_history()
function must be called like this:
get_history(desired_start_time,
desired_end_time, desired_step)
.
The
desired_start_time
is the timestamp of the start
of the desired interval (in seconds since the epoch, 1970-01-01T00:00:00Z). Similarly,
desired_end_time
is the desired end time.
desired_step
is the desired step between adjacent time points. Resulting data
may not match the requirements exactly, but will be generated so that it overlaps the desired time range and
has the closest time step. The function returns a table with 3 elements
{actual_start, actual_step,
data}
(note that it doesn't return 3 values, which is possible for Lua functions, but a single table containing
them).
actual_start
is the timestamp of the start of the output interval,
actual_step
is the step between
adjacent time points, and
data
is a table whose
i
th element is the (averaged) value of the meter around time
actua(i-1)
∗
actual_step
(mind that indices in Lua are 1-based) or
false
if no reading was
obtained within that time interval (e.g. if the device was offline).
Its use is best illustrated by an example. Suppose
temperature
is a value of the form:
local temperature=meter.values[...]
Then the following script could be used for obtaining bounds for the 5-minute-average temperature for the last 24
hours:
local now=os.time()
local history_data=temperature.get_history(now-86400,now,300)
local start,step,data=unpack(history_data)
-- or local start,step,data=history_data[1],history_data[2],history_data[3]
local mintime,mintemp,maxtime,maxtemp
for pos,temp in ipairs(data) do
if temp then
local time=start+(pos-1)*step
if mintemp==nil or mintemp>temp then
mintemp=temp
mintime=time
end
if maxtemp==nil or maxtemp<temp then
maxtemp=temp
maxtime=time
end
end
end
if mintime then
LOG(string.format("Min temperature was %gK at %s",mintemp,os.date("%H:%M:%S",mintime)))
LOG(string.format("Max temperature was %gK at %s",maxtemp,os.date("%H:%M:%S",maxtime)))
else
LOG("No temperature readings for the last 24 hours!")
end
Note that values of
meter.values[key].value
and
meter.values[key].get_history()
are in
standard SI units, e.g. degrees Kelvin for temperature.
7.6.2.11
AutoPing integration
The global
autoping
table allows to query and configure AutoPing.
•
autoping.enabled
: boolean variable which allows enabling (
true
) or disabling (
false
) AutoPing;
•
autoping.items[N].enabled
: read-only boolean value indicating if the Nth AutoPing item is enabled;
•
autoping.items[N].enable
: function to call to attempt to enable (with the argument
true
) or disable
(with the argument
false
) the Nth AutoPing;
•
autoping.items[N].addresses
: array of hostnames or IP addresses of the Nth AutoPing item's
elements;
•
autoping.items[N].outlets
: array of outlets controlled by the Nth AutoPing item;
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: ......