This version of APP is build with a script-engine. This allows you extend the behaivor of the counter.
The script engine uses lua, a powerful script language designed to use embedded in applications. See the reference manual for more information on how to write lua scripts.
The Lua user interface is used to control, monitor and write your lua-scripts.
At the top of the page the current running scripts are listed. You can determine the status of a script by looking at the far left:
To change the state of a script use the controls on the right. Reload will completly rerun the script.
Use the info button to get detailed information about current running scripts.
Use the edit button to edit a script. When you are done, press save and then run/re-run the script.
The script output contain everything used in print. We reccomend you only use this for debug mode, your final script should not have any print statement in it.
Cognimatics extends lua with a library that is used to interact with the APP and to create custom behaivor. The Cognimatics namespace in lua is cog and cogdata. All interaction with the people counter is done using this namespace. The function added by cognimatics are:
cog.Callback is used to register functions within lua that are to be called when events happend in the APP. For example when a passage happens.
Raises an error when callbackname is invalid or maxiumum number of callbacks for a script is reached.
cog.Callback("day_reset", function (a,ts) print("data has been reset") end)
cog.ClearCallback is used to unregister a callback previously regisitered
Raises an error when callbackname is invalid or maxiumum number of callbacks for a script is reached.
cog.ClearCallback("day_reset")
cog.Timer is used to run your code on regular intervals. The script is only allow your code to be run a certain amount of time. Therefor if you want to run lua code periodically you need to use the timer function.
Raises an error when callback is invalid or maxiumum number of timers for a script is reached.
function every_time () print("timer was called") end cog.Timer(every_time, 10000, "my-timer")
cog.ClearTimer is used to remove a previously set timer.
Raises an error when the timer is not active.
cog.ClearTimer("my-timer")
The script can make use of the Axis Trigger interface. Before any triggers are triggered the script must initialize the trigger environment. Each script must only call cog.TriggerInit maximum of once.
Raises an error when the TriggerInit has been called already.
cog.TriggerInit("cognimatics")
Trigger of a trigger in the axis interface. If you want to process the trigger result you must configure the desired behavior in the axis settings trigger page.
Raises an error when the you use to many triggers within one script or when TriggerInit has not been called.
cog.TriggerInit("cognimatics") cog.Trigger("Test")
Create a new parameter in the axis parameter system. All parameters are stored as strings. All param names must begin with "Lua." or contain no dots.
Raises an error when trying to create a parameter outside the "Lua." namespace.
cog.ParamNew("myparam", "hello")
Get the value of a parameter
Raises an error when the parameter does not exist.
print(cog.ParamGet("myparam"))
Set the value of an existing parameter in the parameter system
Raises an error when trying to set a parameter outside the "Lua." namespace.
cog.ParamSet("myparam", "hello Steve")
Get a list of availible parameters.
Raises an error on internal error.
tab = cog.ParamList() for i=0, #tab do print(i, tab[i], cog.ParamGet(tab[i])) end
Removes a created parameter.
Raises an error when the parameter does not exist or is not writable.
cog.ParamRemove("myparam")
To communicate with the outside world you can create your own webpage that the webserver will listen to.
Raises an error if the maximum number of pages for the script has been reached or when the name is not available.
function webpage(table) return string.format([[ <html> <head> <title>Current Passages</title> </head> <body> Right now there has passed %d persons under the camera, this page was called with info: %q </body> </html> ]], i, table["info"] or "") end cog.Webpage("my-special", webpage, {"info"}, "text/html")
Returns a table describing the availible types in the products.
Raises an error raises an error when there are no availible types.
types = cogdata.Types() for i,v in pairs(types) do print(i,v) end
Returns the data for a specific time.
Raises an error raises an error when there is no availible data.
function today(type) now = os.time() - (os.time() % (24*60*60)) tot = 0, 0 for t=now,now + 24*60*60,900 do if cogdata.Exists(t) then tot = tot + cogdata.Get(t, type) end end return tot end print(today(3))
Returns all data for a specifc time.
Raises an error raises an error when there is no availible data.
print(cogdata.GetAll(os.time()-3600))
Check if data exists for a specific time.
None.
print(cogdata.Exists(os.time()-3600))