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.

Trend export
#5
Your script does not work because you are not putting any data in buffer and thus there's no data to upload.

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
Reply


Messages In This Thread
Trend export - by PassivPluss - 22.09.2015, 21:11
RE: Trend export - by admin - 23.09.2015, 06:44
RE: Trend export - by PassivPluss - 23.09.2015, 07:53
RE: Trend export - by PassivPluss - 01.10.2015, 19:33
RE: Trend export - by admin - 02.10.2015, 06:57
RE: Trend export - by PassivPluss - 16.10.2015, 07:35
RE: Trend export - by admin - 16.10.2015, 08:44
RE: Trend export - by PassivPluss - 16.10.2015, 10:20
RE: Trend export - by admin - 16.10.2015, 10:52
RE: Trend export - by PassivPluss - 29.10.2015, 22:51
RE: Trend export - by Erwin van der Zwart - 02.11.2015, 07:28
RE: Trend export - by PassivPluss - 02.11.2015, 19:24

Forum Jump: