05.03.2024, 12:37
(05.03.2024, 10:50)admin Wrote: 238.600 1 byte DALI diagnostics data type is supported out of the box. In scripts you will get the diagnostics value as a table with 3 fields: address (number), ballasterror (bool) and lamperror (bool)
You can use this solution for CSV export: https://kb.logicmachine.net/scripting/ex...-hour-csv/
Currently grp.decodevalue() does not support 238.600 conversion to a readable string value so an additional conversion function is needed:
Code:function dalidiagtostring(value)
local stat
if value.ballasterror then
stat = 'ECG error'
elseif value.lamperror then
stat = 'Lamp error'
else
stat = 'OK'
end
return string.format('Address %d %s', value.address, stat)
end
Hello admin,
Where should I include the function above in the following script?
Code:
require('socket.ftp')
-- ftp file
url = '/home/ftp/%s.csv'
date = os.date('%Y-%m-%d_%H-%M')
ftpfile = string.format(url, date)
-- get past 12 hours data (43200 seconds)
logtime = os.time() - 12 * 3600
-- csv buffer
buffer = {
'"date","type","destination","name","datatype",' ..
'"value","source","sender","login/meta"'
}
-- get object logs
query = [[
SELECT ol.*, o.name, o.datatype
FROM objectlog ol
LEFT JOIN objects o ON ol.address=o.id
WHERE logtime >= ?
ORDER BY id DESC
]]
function fmtdpt(dpt)
if dpt >= 1000 then
dpt = string.format('%0.3f', dpt / 1000)
end
return dpt
end
for _, row in ipairs(db:getall(query, logtime)) do
id = tonumber(row.address) or 0
ia = tonumber(row.src) or 0
logdate = os.date('%Y.%m.%d %H:%M:%S', math.floor(row.logtime))
etype = row.eventtype
textdpt = nil
if (etype == 'write' or etype == 'response') and row.datatype then
textdpt = fmtdpt(row.datatype)
value = grp.decodevalue(row.datahex, row.datatype)
else
value = ''
end
buffer[ #buffer + 1 ] = string.format('%q,%q,%q,%q,%q,%q,%q,%q,%q',
logdate,
etype,
buslib.decodega(id),
row.name or '',
tostring(textdpt or ''),
tostring(value),
ia > 0 and buslib.decodeia(ia) or 'local',
row.sender or '',
row.meta or ''
)
end
if #buffer > 1 then
data = table.concat(buffer, '\r\n')
io.writefile(ftpfile, data)
end
Since we log other objects also can we implement this but only for Tagged with 'Dali Error' objects?
P.S. Is there a known issue with email notifications subscription on threads? It seems that I cannot get emails for the last month or so.