Logic Machine Forum
Read values in scheduled script store in ftp - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Read values in scheduled script store in ftp (/showthread.php?tid=1622)

Pages: 1 2


RE: Read values in scheduled script store in ftp - Rauschentofft - 05.05.2021

Hi,

I cant get this script to work:

tagname = 'log'
logtime = os.time() - 60 * 60

query = [[
SELECT ol.*, o.name, o.datatype
FROM objectlog ol
JOIN objects o ON ol.address=o.id
JOIN objecttags t ON o.id=t.object
WHERE t.tag=? AND logtime>=?
ORDER BY id DESC
]]

buffer = { 'date;name;value' }

items = db:getall(query, tagname, logtime)
for _, item in ipairs(items) do
  id = tonumber(item.address) or 0
  logdate = os.date('%Y-%m-%d', math.floor(item.logtime))
  etype = item.eventtype

  if (etype == 'write' or etype == 'response') and item.datatype then
    value = grp.decodevalue(item.datahex, item.datatype)
    if type(value) == 'number' then
      value = tostring(value):gsub('%.', ',')
    end
  else
    value = ''
  end

  buffer[ #buffer + 1 ] = string.format('%s;%s;%s',
    logdate, item.name or '', tostring(value))
end

csv = table.concat(buffer, '\n')



I got nil.

I want to read meters convert to: buffer = { 'date;name;value' }

and send email once every sixth our.

Thanks for help.


RE: Read values in scheduled script store in ftp - Daniel - 05.05.2021

The script itself works, did you tag the objects? Did you enable logging to them? Did you change logged objects value to have anything to show?


RE: Read values in scheduled script store in ftp - admin - 06.05.2021

If you want to send periodical values you can use current object values instead of object logs. In this example all objects with the electricity tag are added to the CSV report.
Code:
buffer = { 'date;name;value' }

objects = grp.tag('electricity')
for _, object in ipairs(objects) do
  logdate = os.date('%Y-%m-%d', math.floor(object.updatetime))
  value = object.value
  if type(value) == 'number' then
    value = tostring(value):gsub('%.', ',')
  end
  buffer[ #buffer + 1 ] = string.format('%s;%s;%s',
    logdate, object.name or '', tostring(value))
end

csv = table.concat(buffer, '\n')
log(csv)



RE: Read values in scheduled script store in ftp - Rauschentofft - 06.05.2021

Hi again.

I got the script to work.

Now the problem i don´t know how to use it.

please help me.

Hi.

I have solved the problem.

Thanks for the help.