Lua device can be configured using cron time expression. This way script execution can be scheduled or executed at certain times. To create such solution, device sheet of Excel configuration should look like this:
As seen in this configuration, execution type for Lua device is date and execution parameter is in cron time expression. In this case script will be executed every 30s starting from a mm:30 or a mm:00 mark. There are a lot of online cron expression parsers or generators to convert this expression to a more understandable form. https://crontab.cronhub.io/
To complete Excel configuration fill out the red fields with correct parameters. For "ip" field enter IP address of Wi-Fi connection that is connected to computer. This can be checked by entering command "ipconfig" on terminal window. For the "host" field enter IP address of WCC Lite device.
Signals sheet should look similar to this:
IEC104 SCADA will send command which will then go to Lua signal. Lua signal will send the response back to IEC104 SCADA and to Modbus TCP result signal.
Lua script in this case will be very simple. To show how Lua with cronjob can be used in real life, a calculation for kilowatts per hour has been added:
local kW = tonumber(get_value(signals.command))--function "get_value" will get value from iec104 command
--without any attributes this value is still in string form so funtion "tonumber" will convert it to number
--a new variable is creted which is now equal to command value
value = value or 0 --new variable is created. It has to be equal to itself or to 0 if the script is running
--for the forst time
value = (kW * 30/3600) + value --formula for calculating kilowatts. command value from iec104 is multiplied by time.
--Since the script is being executed every 30s, this time needs to be converted to hours. an old value is being
--added to new value, this way result value that is being published will grow every 30s
publish(signals.result, value)--publishes result to result signals for lua and modbus TCP.
--Since the script is being executed every 30s, those values will be refreshed every 30s as well
To test the functionality of this script upload Excel configuration to WCC Lite (it should upload without any errors):
Upload Lua script to script runner and press start. After this, Status should show Running and script process number will appear:
Open Vinci as IEC104 master, enter IP address of WCC Lite and start communication. Then open another Vinci window and connect Modbus TCP master – select Modbus TCP slave in Vinci and enter the same IP address as set in Excel configuration for Modbus device. With both communications running check Protocol connections on WCC Lite web interface, it should show connected. From IEC104 Vinci window go to System tab. Select command determined in the Excel configuration (50), IOA (1) and value (for example 3600).
Execute the command and check Imported signals:
On a 30s mark result signals will have calculated value:
After another 30s new value will be added to old value and result signals will be updated accordingly:
Cronjob with Lua can be used mainly to schedule tasks. It can also be used as a way to filter, monitor or control the data. As seen in this example, Lua script can help calculate certain parameters which will then can be sorted using cron time expression.
Configuration --> Download
Lua script --> Download