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.

Application Store documentation and sample app
#1
LogicMachine apps reference: https://kb.logicmachine.net/misc/apps/

Upload sample folder to data directory by using FTP  with username apps (you have to enabled FTP and set password in System config first). After that you will have sample application visible on the main screen.

Apps are written in JavaScript/HTML/CSS on client side and Lua on server side.

Attached Files
.zip   sample.zip (Size: 4.81 KB / Downloads: 664)
Reply
#2
(28.09.2015, 12:50)edgars Wrote: Please find attached short documentation on Apps and sample application. Upload sample folder to data directory by using FTP  with username apps (you have to enabled FTP and set password in System config first). After that you will have sample application visible on the main screen.

Full tutorials will be provided later on. All Apps are free for now and are published by sending application files to us.

Apps are written in JavaScript/HTML/CSS on client side and Lua on server side.
Help me,
I have a smartwatch moto 360.
How to connect and control smart home on this watch?

Thank so much,
Reply
#3
There should be a separate application created for Moto 360 integration.
Reply
#4
(21.10.2015, 13:04)edgars Wrote: There should be a separate application created for Moto 360 integration.

Can you give me one a few applications can do it ?

thank so much,
Reply
#5
When we can expect full documentation of apps on SE's HomeLYnk? Edgars's solution is ok, but dont explain all problems.
Reply
#6
(03.05.2016, 19:30)Pawel Wrote: When we can expect full documentation of apps on SE's HomeLYnk? Edgars's solution is ok, but dont explain all problems.
Hi Pawel,

From FW 1.5 we have access to the app engine, but we have no frontend like explained in Edgars docs.

However you can build apps and store them on ftp and call them by direct url or embedded in a iframe.

The option to download apps from the appstore is not available in homeLYnk yet.

I don't think (not sure) we will publish documentation or application notes for current engine, and you
have you wait for full version of the appstore.

What problems do you mean? I created a few apps already and i think its working great, I realy like
the server cliënt link and access to LUA, storage, DB, sockets, user libs from cliënt and already created 
some http API's in .lp to call server side LUA results direct from cliënt with javascript.

Now anything you can think off can be created..

Please tell me your struggles (:

BR,

Erwin van der Zwart
Reply
#7
For example showing apps on homepage. I thought that I did something wrong. SE's application notes are very helpful when you try something new. Smile

I also don
Reply
#8
OK, i have "storage tab" app. I have to add via ftp this folder to "data" folder, and then i can see app on "http://IP/apps/data/storage/". But there's no data, and a lot of errors in browser.

in code, a found in lua part "require('apps')" but You don't write anywhere to add some library. 

Also I have empty bootstrap.css, fontawesome.css and style.css files. I assume that i done something wrong, am i right? Smile
Reply
#9
Hi Pawel,


All the additional plugins / libs / css like bootstrap.css, fontawesome.css and style.css are not default available (yet) on homeLYnk. 
This is part of the full version that is still in development.

You could add them manualy but you need to place them where they are expected by the app. (or change the locations in the app to your new location)

I think that your issues are related to this, and your are trying to use fuctions that are not embedded yet...

BR,

Erwin
Reply
#10
so this is why i pleased for full documentation, because for now apps are grate for You, because you now limits and all functions. Smile

Can you give us some simple app, that works on HL, and consist of combination of lua script and html?
Reply
#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
#12
thanks for nice explanation.

I have question about using lua in html page. To use KNX specific HomeLYnk LUA function, is there necessary to import "genohm-scada" library? What with 'storage' function? Is there necessary to import some library to save variables in storage? I need to communicate my app with lua scripts.
Reply
#13
You can do require('apps'), it will include all required libraries
Reply
#14
(05.05.2016, 12:25)admin Wrote: You can do require('apps'), it will include all required libraries

also with Schneider's HomeLYnk?
Reply
#15
Hi Pawel,

I created a small HTTP API (as .lp) for you to save and get data from storage from javascript:

1) Create a LUA script and run once to create the storage.lp file that will act as HTTP API:

dst = '/www/user/storage.lp'

io.writefile(dst, [[<? 
require('apps')
require('socket.url')
action = socket.url.unescape( getvar('action') or 'none' )
storagename = socket.url.unescape( getvar('storagename') or 'none')
  format = socket.url.unescape( getvar('format') or 'string' )
storagevalue = socket.url.unescape( getvar('value') or '{}')
if action == 'storageset' then
  if storagename ~= 'none' then
  if format == 'json' then
  storagevalue = json.decode(storagevalue)
end
  storage.set(storagename, storagevalue)
  print('value saved to storage as ' .. format)
end
elseif action == 'storageget' then
  if storagename ~= 'none' then
storagevalue = storage.get(storagename)
storagevalue = json.encode(storagevalue)
  print(storagevalue)
end
end
?>]])

script.disable(_SCRIPTNAME)

2) Put this in your custom javascript:

$(function() {

  
  // Save json data to storage with name 'mystoragename1'
  var jsondata = {"name":"Erwin van der Zwart","company":"Schneider Electric","country":"The Netherlands"}
  jsondata = JSON.stringify(jsondata);
  $.get( "/user/storage.lp?action=storageset&storagename=mystoragename1&format=json&value=" + jsondata, function( data ) {
    res = data.trim();
    console.log(res);
  });
  
  // Get json data from storage with name 'mystoragename1'
  $.get( "/user/storage.lp?action=storageget&storagename=mystoragename1", function( data ) {
    res = data.trim();
    res = JSON.parse(res);
    console.log(res);
  });
  
  // Save string data to storage with name 'mystoragename2'
  var stringdata = "Erwin van der Zwart Schneider Electric The Netherlands"
  $.get( "/user/storage.lp?action=storageset&storagename=mystoragename2&format=string&value=" + stringdata, function( data ) {
    res = data.trim();
    console.log(res);
  });
  
  // Get string data from storage with name 'mystoragename2'
  $.get( "/user/storage.lp?action=storageget&storagename=mystoragename2", function( data ) {
    res = data.trim();
    console.log(res);
  });

});

By changing the action / storagename / format / value in the URL you can set and get any value from storage with this script.

BR,

Erwin
Reply
#16
Is there a guide somewhere om how to package apps so they can be installed via a file in GUI?
Reply
#17
@FatMax, check PM
Reply
#18
Hello
I am also interested in the instructions for packaging applications.

a greeting
Reply
#19
Check PM
Reply
#20
thanks
Reply


Forum Jump: