02.10.2015, 06:57
Your script does not work because you are not putting any data in buffer and thus there's no data to upload.
Try this:
Try this:
Code:
require('socket.ftp')
require('genohm-scada.trends')
time = os.time()
date = {
stime = time - 3600,
etime = time,
}
values = trends.fetch('watt lys', 'hour', date)
buffer = {}
count = 0
average = 0
resolution = 30 -- in minutes
for _, data in ipairs(values) do
count = count + 1
average = average + data[ 2 ]
if count == resolution then
date = os.date('%Y.%m.%d %H:%M', time)
value = average / resolution
row = string.format('%q,%q', date, value)
table.insert(buffer, row)
time = time + 60 * resolution
count = 0
average = 0
end
end
if #buffer > 0 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