108
1.
value = knxdatatype.decode(event.datahex, dt.bool)
2.
data =string.format('%s value is %s', os.date('%c'), tostring(value))
3.
-- write to the end of log file preserving all previous data
4.
file =io.open('/mnt/usb/log.txt', 'a+')
5.
file:write(data .. '\r\n')
6.
file:close()
Output:
Mon Jan 3 05:25:13 2011 value is false
Mon Jan 3 05:25:14 2011 value is true
Mon Jan 3 05:25:32 2011 value is false
Mon Jan 3 05:25:33 2011 value is true
Example: Read data from file (config in format key=value)
1.
for line inio.lines('/mnt/usb/config.txt')do
2.
-- split line by '=' sing
3.
items = line:split('=')
4.
-- two items, line seems to be valid
5.
if #items == 2 then
6.
key = items[1]:trim()
7.
value = items[2]:trim()
8.
alert('[config] %s = %s', key, value)
9.
end
10.
end
6.2.21. Script control functions
script.enable('scriptname')
Enable the script with the name scriptname.
script.disable('scriptname')
Disable the script with the name scriptname.
status = script.status('scriptname')
Returns true/false if script is found, nil otherwise
6.2.22. JSON library
Note: json is not loaded by default, use require('json') before calling any functions from this
library.
json.encode (value)