18.05.2018, 08:07
State has to be polled so you need a resident script. Adjust sleep time as needed, but do not use 0 as it will consume all CPU.
Uncomment and modify grp calls depending on how many inputs are used.
Uncomment and modify grp calls depending on how many inputs are used.
Code:
require('json')
require('socket.http')
res, err = socket.http.request('http://192.168.1.101/api/io/status')
if res then
data = json.pdecode(res)
if type(data) == 'table' then
ports = data.result.ports
log(ports)
-- grp.checkwrite('1/1/1', ports[ 1 ].state)
-- grp.checkwrite('1/1/1', ports[ 2 ].state)
else
alert('failed to decode data')
end
else
alert('http request failed ' .. tostring(err))
end
-- release unused resources
collectgarbage('collect')