Scripts analyzing past range data


Hello again,

The device we are using writes data to Exosite in records and not single writes. This has the effect of no events being dispatched and Scripts .wait() not working.

A work around we devised is to wait for a period and analyze past data all at once. Can we do this in the Script API? How do we retrieve a range of data ?



Hi @katesclau,

Thanks for posting, and sorry for not getting back to you earlier. Using some tricks with the .last function in the Alias table, you can parse through a dataport’s history. By setting the .last to an arbitrary point in time(that has passed), you can ‘wait’ from then to the present.

In practice this process looks like this:

local period = 60 -- how far you want to look back in seconds
local start_time = now-period
local end_time = now

local function evaluateHistory(p_start,p_end)
    local done = false

    mydataport.last = p_start

    while done == false do
        local ts = mydataport.wait(p_end)
        -- you can use mydataport[ts] to interact with data that is in the 'past'.


This is the general method of getting this done. But my understanding is that you are looking to recreate event functionality, so I made an example script that you can use. This Lua script sends an alert via email if a given dataport’s value is above 100.

For more details about Lua scripting please visit:

Feel free to post back if you have questions!