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.

Log 250 byte string to ftp file
#1
Hi.

I want to log 250 byte string to ftp file.

And i also want to know how to calculate the time differrence of two 250 byte string.

See picture.

Br
MR

Attached Files Thumbnail(s)
   
Reply
#2
There are many CSV/FTP examples on the forum. There's also example on our website: https://openrb.com/example-export-last-h...-from-lm2/
As for the difference calculation it should be done on numeric values not on the strings that are formatted using the numeric values. Then you can simply subtract one value from another.
Reply
#3
Okej, then i look it up.

If i understand it right about the difference.
Then i should compare the values before i convert it to string?

My script is done to log "on" value 1/1/1 and then add it to total value 1/1/2.
Total value shows "on" time in: year, month, week, days, h, m, s.

Br
MR
Reply
#4
Any calculations should be done on numeric values. If you have date/time string you will to convert it back to a number before doing any calculations.
Reply
#5
I don´t know how to convert it to numeric.

Could you help me with this?
Reply
#6
Please describe exactly what do you want to compare and post the code that you use. Most likely you already have a numeric value before it's converted to a formatted string that is written to 250 byte object.
Reply
#7
I use this script.

I have four timers an i want to compare two.

Total time 7/0/4 and 7/0/14.

Code:
----------Timer for group 7/0/1 ---------------

value = event.getvalue()

key_now_1 = 'ontime_now_1'
out_now_1 = '1/0/2'

key_last_1 = 'ontime_last_1'
out_last_1 = '1/0/3'

key_total_1 = 'ontime_total_1'
out_total_1 = '1/0/4'

time = storage.get(key_now_1)
now = os.time()

if value then
  if not time then
    storage.set(key_now_1, now)
    formattime(out_now_1, 0)
    storage.set(key_last_1, now)
    formattime(out_last_1, 0)
    end
    
else
  if time then
    time_total = storage.exec('incrby', key_total_1, now - time)
    formattime(out_total_1, time_total)
    
    storage.delete(key_now_1)
    storage.delete(key_last_1)
  end

  grp.update(out_now_1, '')
  
end

-----------------------------------------------------

----------Resident Script---------Timer for group 7/0/1 ---------------

key_now_1 = 'ontime_now_1'
out_now_1 = '1/0/2'

key_last_1 = 'ontime_last_1'
out_last_1 = '1/0/3'

key_total_1 = 'ontime_total_1'
out_total_1 = '1/0/4'

time_now = storage.get(key_now_1)
time_now_1 = storage.get(key_last_1)
if time_now then
  
  time_now = os.time() - time_now
  formattime(out_now_1, time_now)
  formattime(out_last_1, time_now)
  
  time_total = storage.get(key_total_1, 0)
  formattime(out_total_1, time_total + time_now)
end

--------------------------------------------------------------------

-----------------Common Function----------------------------
function formattime(output, seconds)
  local minutes = math.floor(seconds / 60)
  local hours = math.floor(minutes / 60)
  local days = math.floor(hours / 24)
  local res = {}

  seconds = seconds % 60
  minutes = minutes % 60
  hours = hours % 24

  if days > 0 then
    res[ #res + 1 ] = days .. 'd'
  end

  if hours > 0 then
    res[ #res + 1 ] = hours .. 'h'
  end

  if minutes > 0 then
    res[ #res + 1 ] = minutes .. 'm'
  end

  if seconds > 0 or #res == 0 then
    res[ #res + 1 ] = seconds .. 's'
  end

  res = table.concat(res, ' ')
  grp.update(output, res)
end
-------------------------------------------------------------------------
Reply
#8
Modify storage keys and output address as needed:
Code:
key_total_1 = 'ontime_total_1'
key_total_2 = 'ontime_total_2'

output = '1/2/3'

value_1 = storage.get(key_total_1, 0)
value_2 = storage.get(key_total_2, 0)

delta = math.abs(value_1 - value_2)

formattime(output, delta)
Reply
#9
Thanks alot for the help.

Br
MR
Reply


Forum Jump: