Logic Machine Forum
Download file .lp of logic machine automatic - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Download file .lp of logic machine automatic (/showthread.php?tid=982)



Download file .lp of logic machine automatic - Carlos Padilla - 09.09.2017

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



RE: Download file .lp of logic machine automatic - admin - 11.09.2017

You will quickly kill the internal SD card if your script is contantly writing to the main file system.


RE: Download file .lp of logic machine automatic - Carlos Padilla - 11.09.2017

hi 
even if it's every 5 minutes?


RE: Download file .lp of logic machine automatic - buuuudzik - 11.09.2017

(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.


RE: Download file .lp of logic machine automatic - Carlos Padilla - 11.09.2017

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



RE: Download file .lp of logic machine automatic - admin - 11.09.2017

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


RE: Download file .lp of logic machine automatic - Erwin van der Zwart - 11.09.2017

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


RE: Download file .lp of logic machine automatic - Carlos Padilla - 11.09.2017

Hi

Very thanks you

by the help Smile

thanks to 
Everybody