Overview

This version of APP is build with a script-engine. This allows you extend the behaivor of the counter.

Lua

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.

Gui

The Lua user interface is used to control, monitor and write your lua-scripts.

Script Status

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.

Script Information

Use the info button to get detailed information about current running scripts.

Edit A Script

Use the edit button to edit a script. When you are done, press save and then run/re-run the script.

Script Output

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.

Api

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

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.

Input
Return
Errors

Raises an error when callbackname is invalid or maxiumum number of callbacks for a script is reached.

Example

cog.Callback("day_reset", function (a,ts) print("data has been reset") end)

cog.ClearCallback

cog.ClearCallback is used to unregister a callback previously regisitered

Input
Return
Errors

Raises an error when callbackname is invalid or maxiumum number of callbacks for a script is reached.

Example

cog.ClearCallback("day_reset")

cog.Timer

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.

Input
Return
Errors

Raises an error when callback is invalid or maxiumum number of timers for a script is reached.

Example

function every_time ()
print("timer was called")
end
cog.Timer(every_time, 10000, "my-timer")

cog.ClearTimer

cog.ClearTimer is used to remove a previously set timer.

Input
Return
Errors

Raises an error when the timer is not active.

Example

cog.ClearTimer("my-timer")

cog.TriggerInit

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.

Input
Return
Errors

Raises an error when the TriggerInit has been called already.

Example

cog.TriggerInit("cognimatics")

cog.Trigger

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.

Input
Return
Errors

Raises an error when the you use to many triggers within one script or when TriggerInit has not been called.

Example

cog.TriggerInit("cognimatics")
cog.Trigger("Test")

cog.ParamNew

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.

Input
Return
Errors

Raises an error when trying to create a parameter outside the "Lua." namespace.

Example

cog.ParamNew("myparam", "hello")

cog.ParamGet

Get the value of a parameter

Input
Return
Errors

Raises an error when the parameter does not exist.

Example

print(cog.ParamGet("myparam"))

cog.ParamSet

Set the value of an existing parameter in the parameter system

Input
Return
Errors

Raises an error when trying to set a parameter outside the "Lua." namespace.

Example

cog.ParamSet("myparam", "hello Steve")

cog.ParamList

Get a list of availible parameters.

Input
Return
Errors

Raises an error on internal error.

Example

tab = cog.ParamList()
for i=0, #tab do
  print(i, tab[i], cog.ParamGet(tab[i]))
end

cog.ParamRemove

Removes a created parameter.

Input
Return
Errors

Raises an error when the parameter does not exist or is not writable.

Example

cog.ParamRemove("myparam")

cog.Webpage

To communicate with the outside world you can create your own webpage that the webserver will listen to.

Input
Return
Errors

Raises an error if the maximum number of pages for the script has been reached or when the name is not available.

Example

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

cogdata.Types

Returns a table describing the availible types in the products.

Input
Return
Errors

Raises an error raises an error when there are no availible types.

Example

types = cogdata.Types()
for i,v in pairs(types) do print(i,v) end

cogdata.Get

Returns the data for a specific time.

Input
Return
Errors

Raises an error raises an error when there is no availible data.

Example

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

cogdata.GetAll

Returns all data for a specifc time.

Input
Return
Errors

Raises an error raises an error when there is no availible data.

Example

print(cogdata.GetAll(os.time()-3600))

cogdata.Exists

Check if data exists for a specific time.

Input
Return
Errors

None.

Example

print(cogdata.Exists(os.time()-3600))