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 via csv
#1
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
Reply


Messages In This Thread
trend export via csv - by PassivPluss - 19.10.2016, 19:12
RE: trend export via csv - by PassivPluss - 19.10.2016, 20:03
RE: trend export via csv - by benanderson_475 - 10.12.2019, 19:39
RE: trend export via csv - by Gadjoken - 19.09.2022, 07:43
RE: trend export via csv - by Trond Hoyem - 16.01.2023, 14:03
RE: trend export via csv - by admin - 16.01.2023, 14:12
RE: trend export via csv - by Trond Hoyem - 16.01.2023, 14:18
RE: trend export via csv - by admin - 16.01.2023, 14:20
RE: trend export via csv - by Trond Hoyem - 16.01.2023, 14:31

Forum Jump: