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 whether you accept or reject these cookies being set.

Application Store documentation and sample app
#11
Hi Pawel,

To be honest, i'm just a early adopter and have never any documentation. By the time the documentation is finished and released i'm already playing with the new stuff (;

I have just as much info as you do, i have all the information from Edgars sample document and by exploring the Apps that are available...

I created some easy commands to give you an idea how to use it:

*****************************************************************************
Run in LUA once to create a file with client IP resolve:

dst = '/www/user/ip.lp'
if not io.exists(dst) then
  io.writefile(dst, '<? print(ngx.var.remote_addr) ?>')
end

Or if you want to create new and/or overwrite excisting file

dst = '/www/user/ip.lp'
io.writefile(dst, '<? print(ngx.var.remote_addr) ?>')

and run from custom javascript to get it: inside JS

 $.get( "/user/ip.lp", function( data ) {
    res = data.trim();
    alert('Client IP is: ' + res);
    console.log(res);
  });

or you can test it direct from browser with:

http://192.168.0.10/user/ip.lp

*****************************************************************************
Run in LUA once to create a file with LUA system time table as JSON object:

dst = '/www/user/systemtime.lp'
if not io.exists(dst) then
  io.writefile(dst, [[<? 
  require('json')
  require('genohm-scada')
  mydata = os.date('*t')
  mydata = json.encode(mydata)
  print(mydata) 
  ?>]])
end

Or if you want to create new and/or overwrite excisting file

dst = '/www/user/systemtime.lp'
io.writefile(dst, [[<? 
require('json')
require('genohm-scada')
mydata = os.date('*t')
mydata = json.encode(mydata)
print(mydata) 
?>]])

and run from custom javascript to get it: inside JS

 $.get( "/user/systemtime.lp", function( data ) {
    res = data.trim();
    alert('Systemtime seconds is: ' + res[0].sec);
    console.log(res);
  });

or you can test it direct from browser with:

http://192.168.0.10/user/systemtime.lp

*****************************************************************************
Run in LUA once to create a file with get storage script:

dst = '/www/user/storage.lp'
if not io.exists(dst) then
  io.writefile(dst, [[<? 
  require('json')
  require('genohm-scada')
  mydata = storage.get('Sonos_Streams')
  mydata = json.encode(mydata)
  print(mydata) 
  ?>]])
end

Or if you want to create new and/or overwrite excisting file

dst = '/www/user/storage.lp'
io.writefile(dst, [[<? 
require('json')
require('genohm-scada')
mydata = storage.get('Sonos_Streams')
mydata = json.encode(mydata)
print(mydata) 
?>]])

and run from custom javascript to get it: inside JS

 $.get( "/user/storage.lp", function( data ) {
    res = data.trim();
    alert('Storage value is: ' + res);
    console.log(res);
  });

or you can test it direct from browser with:

http://192.168.0.10/user/storage.lp

*****************************************************************************
Run in LUA once to create a file with get storage script with variable storagename:

dst = '/www/user/dynamicstorage.lp'
if not io.exists(dst) then
  io.writefile(dst, [[<? 
  require('json')
  require('socket.url')
  arg1 = socket.url.unescape( getvar('storagename1') )
  arg2 = socket.url.unescape( getvar('storagename2') )
  mydata1= storage.get(arg1)
  mydata2 = storage.get(arg2)
  datatable = {}
  table.insert(datatable, {storage1 = mydata1, storage2 = mydata2})
  datatable = json.encode(datatable)
  print(datatable)
  ?>]])
end

Or if you want to create new and/or overwrite excisting file

dst = '/www/user/dynamicstorage.lp'
io.writefile(dst, [[<? 
require('json')
require('socket.url')
arg1 = socket.url.unescape( getvar('storagename1') )
arg2 = socket.url.unescape( getvar('storagename2') )
mydata1= storage.get(arg1)
mydata2 = storage.get(arg2)
datatable = {}
table.insert(datatable, {storage1 = mydata1, storage2 = mydata2})
datatable = json.encode(datatable)
print(datatable)
?>]])

and run from custom javascript to get it: inside JS

$.get( "/user/dynamicstorage.lp?storagename1=storage1&storagename2=storage2", function( data ) {
    res = data.trim();
    res = JSON.parse(res);
    console.log(res);
});

or you can test it direct from browser with:

http://192.168.0.10/user/dynamicstorage.lp

*****************************************************************************
Run in LUA once to create a file with get db data script:

dst = '/www/user/database.lp'
if not io.exists(dst) then
  io.writefile(dst, [[<? 
  require('json')
  require('genohm-scada')
  require('dbenv')
  db = dbenv:new()
  query = 'SELECT * FROM objects'
  mydata = db:getall(query)
  mydata = json.encode(mydata)
  print(mydata) 
  ?>]])
end

Or if you want to create new and/or overwrite excisting file

dst = '/www/user/database.lp'
io.writefile(dst, [[<? 
require('json')
require('genohm-scada')
require('dbenv')
db = dbenv:new()
query = 'SELECT * FROM objects'
mydata = db:getall(query)
mydata = json.encode(mydata)
print(mydata) 
?>]])

and run from custom javascript to get it: inside JS

$.get( "/user/database.lp", function( data ) {
    res = data.trim();
    res = JSON.parse(res);
    console.log(res);
});

or you can test it direct from browser with:

http://192.168.0.10/user/database.lp

You can also use require('user.yourlib') and use the funtion like we used to in LUA, this way if someone opens the .lp file he can't see te functions behind it, only the function call.

Deleting .lp can also be done with LUA:

os.remove("/www/user/ip.lp")
os.remove("/www/user/systemtime.lp")
os.remove("/www/user/storage.lp")
os.remove("/www/user/dynamicstorage.lp")
os.remove("/www/user/database.lp")

or directly from APPS FTP folder User 

BR,

Erwin
Reply


Messages In This Thread
RE: Application Store documentation and sample app - by Erwin van der Zwart - 04.05.2016, 17:19

Forum Jump: