I tried to integrate this into your example but it only types the data in the logs of the LM.
How do I change this script to get it to work?
I need the LM to export the log with 30 min resolution to my web server once a day.
When fetching the log i also need the values to be accurate. How is this data produced? Like the 13.00 log result, it should be the average of 12.45-13.15. Is that correct?
How do I change this script to get it to work?
I need the LM to export the log with 30 min resolution to my web server once a day.
When fetching the log i also need the values to be accurate. How is this data produced? Like the 13.00 log result, it should be the average of 12.45-13.15. Is that correct?
Code:
require('socket.ftp')
logtime = os.time() - 60 * 60
objects = {}
query = 'SELECT address, datatype, name FROM objects WHERE disablelog=0'
for _, object in ipairs(db:getall(query)) do
objects[ tonumber(object.address) ] = {
datatype = tonumber(object.datatype),
name = tostring(object.name or ''),
}
end
buffer = {}
require('genohm-scada.trends')
time = os.time()
date = {
stime = time - 3600,
etime = time,
}
values = trends.fetch('watt lys', 'hour', date)
for _, data in ipairs(values) do
value = data[ 2 ]
date = os.date('%Y.%m.%d %H:%M', time)
log(date, value)
time = time + 60
end
if #buffer > 1 then
data = table.concat(buffer, '\r\n')
res, err = socket.ftp.put({
host = 'x',
user = 'x',
password = 'x',
command = 'appe',
argument = 'x',
source = ltn12.source.string(data)
})
end
if err then
alert('FTP upload error: %s', tostring(err))
end