Logic Machine Forum
http(s) server as REST api? - 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: http(s) server as REST api? (/showthread.php?tid=3141)



http(s) server as REST api? - Hert - 03.02.2021

Hello, this seems very obvious but I can't seem to find any information on this. I see the setting where I can enable the http and https service and I have enabled them.
Now I have some Shelly Sensors (in the same network as the LM) that I can configure to send a GET request to a URL when certain tresholds are exceeded.

I thought this together with the http service would allow me to set an object in the LM via URL. But I can't find anywhere how the HTTP server is supposed to work.

Is this even possible?


RE: http(s) server as REST api? - admin - 03.02.2021

See this: https://openrb.com/docs/remote-new.htm


RE: http(s) server as REST api? - Hert - 03.02.2021

(03.02.2021, 10:31)admin Wrote: See this: https://openrb.com/docs/remote-new.htm

thank you, this works!


RE: http(s) server as REST api? - Hert - 05.02.2021

Well, it seemed like it worked when I tested it from the browser. But apparently the browser used the cookie to authenticate.
The sensors are not able to access the http endpoint. Including the username:password doesn't work. Since the http port is not accessible out of my network, is there some way to turn authentication off for http?

If I use this url in an incognito tab in chrome:
http://username:password@192.168.0.10/scada-remote?m=json&r=grp&fn=write&alias=8/0/3&value=0
I also get an authentication popup.


RE: http(s) server as REST api? - admin - 06.02.2021

Password cannot be disabled. Are you using "remote" username for this?


RE: http(s) server as REST api? - Hert - 06.02.2021

That's a shame.
I figured out the sensors are doing something wrong and are locking the login due to 5 failed logon attempts (even though I set the user:password correctly in the url). I think I'll open an issue with the manufacturer and config them to go via IFTTT atm.


RE: http(s) server as REST api? - admin - 06.02.2021

There's a solution with .lp file that will work without login/password, I'll post an example later.


RE: http(s) server as REST api? - admin - 08.02.2021

Example for writing to group addresses without password.
You have to enable FTP server in System Config, connect via FTP by using apps username and upload write.lp file into public directory.
write.lp file contents:
Code:
<?
require('apps')
addr = getvar('addr') or ''
value = getvar('value') or ''
value = json.pdecode(value)
if type(value) ~= nil then
  grp.write(addr, value)
end

Example URLs:
http://LM_IP/public/write.lp?addr=1/1/1&value=1 - write 1/ON to 1/1/1
http://LM_IP/public/write.lp?addr=32/1/1&value=123 - write 123 to 32/1/1


RE: http(s) server as REST api? - idhe - 28.04.2021

(08.02.2021, 07:20)admin Wrote: Example for writing to group addresses without password.
You have to enable FTP server in System Config, connect via FTP by using apps username and upload write.lp file into public directory.
write.lp file contents:
Code:
<?
require('apps')
addr = getvar('addr') or ''
value = getvar('value') or ''
value = json.pdecode(value)
if type(value) ~= nil then
  grp.write(addr, value)
end

Example URLs:
http://LM_IP/public/write.lp?addr=1/1/1&value=1 - write 1/ON to 1/1/1
http://LM_IP/public/write.lp?addr=32/1/1&value=123 - write 123 to 32/1/1

Hi,
Is it possible to do the same for read and return the result ?


RE: http(s) server as REST api? - admin - 29.04.2021

http://LM_IP/public/read.lp?addr=1/1/1
Code:
<?
require('apps')
addr = getvar('addr') or ''
value = grp.getvalue(addr)
if type(value) == 'table' then
  value = json.encode(value)
end
print(value)