This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Visualization on Failure
#16
(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.
Reply


Messages In This Thread
Visualization on Failure - by Mrinj - 06.12.2017, 07:53
RE: Visualization on Failure - by Mrinj - 06.12.2017, 09:00
RE: Visualization on Failure - by Mrinj - 06.12.2017, 09:44
RE: Visualization on Failure - by Mrinj - 07.12.2017, 07:59
RE: Visualization on Failure - by Mrinj - 09.12.2017, 09:35
RE: Visualization on Failure - by Mrinj - 10.12.2017, 11:29
RE: Visualization on Failure - by FatMax - 22.02.2018, 10:42
RE: Visualization on Failure - by FatMax - 22.02.2018, 14:58
RE: Visualization on Failure - by admin - 05.03.2024, 10:50
RE: Visualization on Failure - by manos@dynamitec - 05.03.2024, 12:37
RE: Visualization on Failure - by admin - 05.03.2024, 12:50
RE: Visualization on Failure - by admin - 06.03.2024, 11:27

Forum Jump: