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.

http(s) server as REST api?
#1
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?
Reply
#2
See this: https://openrb.com/docs/remote-new.htm
Reply
#3
(03.02.2021, 10:31)admin Wrote: See this: https://openrb.com/docs/remote-new.htm

thank you, this works!
Reply
#4
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/sc.../3&value=0
I also get an authentication popup.
Reply
#5
Password cannot be disabled. Are you using "remote" username for this?
Reply
#6
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.
Reply
#7
There's a solution with .lp file that will work without login/password, I'll post an example later.
Reply
#8
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
Reply
#9
(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 ?
Reply
#10
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)
Reply
#11
(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

I'm trying to use this "workaround" within a shelly script, but the http.get request from the shelly device fails:

"shelly_http_client.:611 0x3ffeb688: Finished; bytes 340, code 301, redir 1/3, auth 0, status ABORTED: Abandoned"

An idea why the webserver from my W4K answers with code 301?
Reply
#12
Are you sure you are using public directory and not user? Try replacing both / in the group address with %2F

In LM we have integration with Shelly over MQTT: https://kb.logicmachine.net/integration/shelly/
Reply
#13
Yes, I was. Due to Postman - it was a redirect from http://IP_W4K to httpS://IP_W4K Unfortunatelly this doesn't solve my problem. With Postman I get a "200" and with Shelly I get a "body parse error". 
How can I install the MQTT broker von my W4K? I didn't found it.
Reply
#14
At least the communication with Shell is solved. Semms like the SSL certificate was the problem. I solved this by enabeling HTTP communication at the w4k und use a http instead of a httpS request.
Reply


Forum Jump: