10.03.2016, 14:32
Try these functions, they are untested so might not work at all. You have to parse any XML response manually
Code:
function request(host, url, urn, action, args)
local body, http, ltn12, sink, res, err
ltn12 = require('ltn12')
http = require('socket.http')
body = [[<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body><u:]] .. action .. [[ xmlns:u="urn:]] .. urn .. [[">]] .. args .. [[</u:]] .. action .. [[></s:Body>
</s:Envelope>]]
sink = {}
res, err = http.request({
url = 'http://' .. host .. ':55000/' .. url,
method = 'POST',
headers = {
['soapaction'] = '"urn:' .. urn .. '#' .. action .. '"',
['Content-Length'] = #body,
},
sink = ltn12.sink.table(sink),
source = ltn12.source.string(body),
})
if res then
return table.concat(sink)
else
return nil, err
end
end
function sendkey(host, code)
local args = '<X_KeyEvent>' .. code .. '</X_KeyEvent>'
return request(host, 'nrc/control_0', 'panasonic-com:service:p00NetworkControl:1', 'X_SendKey', args)
end
function getmute(host)
return request(host, 'dmr/control_0', 'schemas-upnp-org:service:RenderingControl:1', 'GetMute', '<InstanceID>0</InstanceID><Channel>Master</Channel>')
end
IP = '192.168.1.2'
log(getmute(IP))