19.10.2016, 19:12
hi
Earlier you had a example of how to export trends via ftp server as csv but now this doesnt work due to latest firmware.
Is it possible to get an working update for this?
require('socket.ftp')
require('genohm-scada.trends')
time = os.time()
date = {
stime = time - 86400,
etime = time,
}
values = trends.fetch('Effektforbruk lys', 'hour', date)
buffer = {}
count = 0
average = 0
resolution = 60 -- in minutes
row = string.format('%q,%q', "Tid", "Watt")
table.insert(buffer, row)
for _, data in ipairs(values) do
count = count + 1
average = average + data[ 2 ]
if count == resolution then
date = os.date('%d.%b %H:%M', time -86400)
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, '\n\r')
res, err = socket.ftp.put({
host = 'example.no',
user = 'example@example.no',
password = 'knfvkdnkd',
argument = 'trend_dag_lys.csv',
source = ltn12.source.string(data)
})
end
Earlier you had a example of how to export trends via ftp server as csv but now this doesnt work due to latest firmware.
Is it possible to get an working update for this?
require('socket.ftp')
require('genohm-scada.trends')
time = os.time()
date = {
stime = time - 86400,
etime = time,
}
values = trends.fetch('Effektforbruk lys', 'hour', date)
buffer = {}
count = 0
average = 0
resolution = 60 -- in minutes
row = string.format('%q,%q', "Tid", "Watt")
table.insert(buffer, row)
for _, data in ipairs(values) do
count = count + 1
average = average + data[ 2 ]
if count == resolution then
date = os.date('%d.%b %H:%M', time -86400)
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, '\n\r')
res, err = socket.ftp.put({
host = 'example.no',
user = 'example@example.no',
password = 'knfvkdnkd',
argument = 'trend_dag_lys.csv',
source = ltn12.source.string(data)
})
end