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.

Download file .lp of logic machine automatic
#1
Good Morning to all


It could then have an .lp file in the / user / directory of the logic machine to download it to my computer every time an object is updated in my logic machine
my role wrote it in "recidente functions"
is the next:


Code:
objects_lp = [[<?
require('json')
require('apps')
objects = grp.all()
objects = json.encode(objects)
print(objects)

?>]]

io.writefile("/www/user/objects.csv", objects_lp)

that object generates it in the following url
http://192.168.1.242/user/objects.lp


so you can see the .lp file with all the objects

Attached Files Thumbnail(s)
   
Reply
#2
You will quickly kill the internal SD card if your script is contantly writing to the main file system.
Reply
#3
hi 
even if it's every 5 minutes?
Reply
#4
(11.09.2017, 14:07)Carlos Padilla Wrote: hi 
even if it's every 5 minutes?

The best is when you will return the content of .csv file in return function in .lp file, tlen all will be in RAM. Instead .csv you must then download the .lp file.
Reply
#5
Hello
I want to download the .json, change the code from .csv to .json



Quote:
Code:
require('json')

objects=grp.all()
objects= json.encode(objects)




io.writefile("/www/user/page.lp", objects)

shows me a .json as in the following image


this file I want to download from time to time

Attached Files Thumbnail(s)
   
Reply
#6
You can get the same thing by using remote services without any scripts:
http://openrb.com/docs/remote-new.htm

Request example:
http://remote:remote@LM_IP/scada-remote?m=json&r=objects

If you want live monitoring then you should use websockets:
https://forum.logicmachine.net/showthread.php?tid=525
Reply
#7
Hi,

What you also can do is write the file to your website's ftp, now you post the file to your local FTP (user folder on Apps FTP) and that's not helping your SD cards life cycle.

I also included a sample on how to created the .csv file on your external ftp location (:

Code:
require('socket.ftp')

-- ftp file
ftpfile = string.format('ftp://username:password@123.45.67.89/wwwroot/yourwebsitefolder/lmobjectdata.csv')
 
-- csv buffer
buffer = { '"name","address","updatetime"' } -- add more fields if you like

for _, row in ipairs(grp.all()) do
 csv = string.format('%q,%q,%q', row.name, row.address, row.updatetime) -- add more fields if you like
 table.insert(buffer, csv)
end

-- upload to ftp only when there's data in buffer
if #buffer > 1 then
 result, err = socket.ftp.put(ftpfile, table.concat(buffer, '\r\n'))
end

-- error while uploading
if err then
 alert('FTP upload error: %s', tostring(err))
end

You can run this from a scheduled or resident script.

BR,

Erwin
Reply
#8
Hi

Very thanks you

by the help Smile

thanks to 
Everybody
Reply


Forum Jump: