Logic Machine Forum
Remote services retrieve objects with a tag - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: General (https://forum.logicmachine.net/forumdisplay.php?fid=2)
+--- Thread: Remote services retrieve objects with a tag (/showthread.php?tid=1951)



Remote services retrieve objects with a tag - rocfusion - 06.03.2019

Hi,

Is there a way to use remote services to retrieve a list of the objects checked with the export box that have a specific tag?  Currently it just returns all the objects with export checked.

So you would use something like,  http://192.168.1.10/scada-remote?m=json&r=objects&tags=mytag

Could this be added?

Thanks,


Roger


RE: Remote services retrieve objects with a tag - Erwin van der Zwart - 06.03.2019

Hi,

What you could do is create a .lp to do the request like this (run once to create the .lp in the user folder) and a request with http://192.168.0.10/user/request.lp?tag=yourtag and you will get a JSON response back with the objects that has the requested tag.

Code:
-- use this path for request: http://192.168.0.10/user/request.lp?tag=yourtag

dst = '/www/user/request.lp'
io.writefile(dst, [[
<?
  require('apps')
 require('socket.url')
 tagname = socket.url.unescape(getvar('tag') or 'nothing')
 if tagname ~= 'nothing' then
    response = grp.tag(tagname)
    response = json.encode(response)
    print(response)
   end
?>
]])
script.disable(_SCRIPTNAME)
BR,

Erwin


RE: Remote services retrieve objects with a tag - rocfusion - 07.03.2019

Hi Erwin,

Thank you.  That works,  I have revised your script so I just return the object name and its value which is all I need.  In case someone would find this useful the revised code is.

Code:
dst = '/www/user/request.lp'
io.writefile(dst, [[
<?
 require('apps')
 require('socket.url')
 tagname = socket.url.unescape(getvar('tag') or 'nothing')
 if tagname ~= 'nothing' then
   local fb={}
   response = grp.tag(tagname)
   for index,value in ipairs(response) do
     local tmp = { n=response[index].name, v=response[index].value }
     fb[index] = tmp
   end
   response = json.encode(fb)
   print(response)
  end
?>
]])
script.disable(_SCRIPTNAME)

Thx

Roger