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.

Read values in scheduled script store in ftp
#14
Use this to generate CSV for a certain tag and a certain time:
Code:
12345678910111213141516171819202122232425262728293031
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","address","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 %H:%M:%S', math.floor(item.logtime))   etype = item.eventtype   if (etype == 'write' or etype == 'response') and item.datatype then     value = grp.decodevalue(item.datahex, item.datatype)   else     value = ''   end   buffer[ #buffer + 1 ] = string.format('%q,%q,%q,%q',     logdate, item.name or '', buslib.decodega(id), tostring(value)) end csv = table.concat(buffer, '\n')
Reply


Messages In This Thread
RE: Read values in scheduled script store in ftp - by admin - 14.01.2021, 08:16

Forum Jump: