Logic Machine Forum
HTTP Request HS zu w4k - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: HTTP Request HS zu w4k (/showthread.php?tid=4766)



HTTP Request HS zu w4k - stephan - 13.05.2023

Hello everyone

I would like to retrieve or write the internal address from a home server via http.
Read http and write to virtual group address

read
https://192.168.2.113/endpoints/call?key=CO@100_0_1&method=get&user=XXXX&pw=XXXX

Write
https://192.168.2.113/endpoints/call?key=CO@100_0_1&method=set&value=7&user=XXXX&pw=XXXX


maybe someone can help me?


RE: HTTP Request HS zu w4k - admin - 15.05.2023

Use this. The result / error will be visible in the Logs tab.
Code:
http = require('socket.http')
url = 'https://192.168.2.113/endpoints/call?key=CO@100_0_1&method=get&user=XXXX&pw=XXXX'
res, err = http.request(url)
log(res, err)



RE: HTTP Request HS zu w4k - stephan - 15.05.2023

thanks works,
then I should actually get this value on the bus

http = require('socket.http')
url = 'https://192.168.2.113/endpoints/call?key=CO@100_0_1&method=get&user=xxx&pw=xxx'
res, err = http.request(url)
log(res, err)

value = data
grp.checkwrite('32/1/2', value)


RE: HTTP Request HS zu w4k - admin - 15.05.2023

Code:
grp.checkwrite('32/1/2', res)



RE: HTTP Request HS zu w4k - stephan - 15.05.2023

no sends 0


RE: HTTP Request HS zu w4k - admin - 15.05.2023

What do you get in Logs?


RE: HTTP Request HS zu w4k - stephan - 15.05.2023

test 15.05.2023 10:52:17
* arg: 1
  * string: {"request": {"method": "get", "key": "CO@100_0_1"}, "code": 0, "type": "call", "data": {"value": 22.0}}
* arg: 2
  * number: 200


RE: HTTP Request HS zu w4k - admin - 15.05.2023

Code:
http = require('socket.http')
json = require('json')

url = 'https://192.168.2.113/endpoints/call?key=CO@100_0_1&method=get&user=XXXX&pw=XXXX'
res, err = http.request(url)

res = json.pdecode(res)
grp.checkwrite('32/1/2', res.data.value)



RE: HTTP Request HS zu w4k - stephan - 15.05.2023

works, thanks. to send do I have to turn the sript around?


RE: HTTP Request HS zu w4k - admin - 15.05.2023

Use an event script for writing:
Code:
http = require('socket.http')
value = event.getvalue()

url = 'https://192.168.2.113/endpoints/call?key=CO@100_0_1&method=set&value=' .. value .. '&user=XXXX&pw=XXXX'
res, err = http.request(url)
log(res, err)

log() call is just for debugging, remove it if script is working correctly.


RE: HTTP Request HS zu w4k - stephan - 15.05.2023

Thanks for the support