Här kommer kodsnuttar för uppspelningsfunktionerna i SONOS, både som LUA och TCP
Börja med att skapa en virtuell enhet med IP till din SONOS-enhet och port 1400.
TCP:
Play
Code: Select all
POST /MediaRenderer/AVTransport/Control HTTP/1.1
Content-Length: 266
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Play></s:Body></s:Envelope>0x0D0x0A0x0D0x0A
Code: Select all
POST /MediaRenderer/AVTransport/Control HTTP/1.1
Content-Length: 267
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Pause"
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Pause xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Pause></s:Body></s:Envelope>0x0D0x0A0x0D0x0A
Code: Select all
POST /MediaRenderer/AVTransport/Control HTTP/1.1
Content-Length: 266
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Stop"
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Stop xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Stop></s:Body></s:Envelope>0x0D0x0A0x0D0x0A
Code: Select all
POST /MediaRenderer/AVTransport/Control HTTP/1.1
Content-Length: 270
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Previous"
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Previous xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Previous></s:Body></s:Envelope>0x0D0x0A0x0D0x0A
Code: Select all
POST /MediaRenderer/AVTransport/Control HTTP/1.1
Content-Length: 266
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Next"
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:Next xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><Speed>1</Speed></u:Next></s:Body></s:Envelope>0x0D0x0A0x0D0x0A
Code: Select all
POST /MediaRenderer/RenderingControl/Control HTTP/1.1
Content-Length: 314
SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetMute"
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"><InstanceID>0</InstanceID><Channel>Master</Channel><DesiredMute>1</DesiredMute></u:SetMute></s:Body></s:Envelope>0x0D0x0A0x0D0x0A
Code: Select all
POST /MediaRenderer/RenderingControl/Control HTTP/1.1
Content-Length: 314
SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetMute"
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"><InstanceID>0</InstanceID><Channel>Master</Channel><DesiredMute>0</DesiredMute></u:SetMute></s:Body></s:Envelope>0x0D0x0A0x0D0x0A
Code: Select all
POST /MediaRenderer/RenderingControl/Control HTTP/1.1
Content-Length: 324
SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume"
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:SetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"><InstanceID>0</InstanceID><Channel>Master</Channel><DesiredVolume>_sliderValue_</DesiredVolume></u:SetVolume></s:Body></s:Envelope>0x0D0x0A0x0D0x0A
(Glöm inte att ändra till rätt IP-adress i början på varje kommando nedan)
Play
Code: Select all
local IPaddress = '192.168.x.xx'
local action = "Play"
local server_url = IPaddress .. ':1400/MediaRenderer/AVTransport/Control'
local servicetype = 'urn:schemas-upnp-org:service:AVTransport:1'
local arguments = '<InstanceID>0</InstanceID>,<Speed>1</Speed>'
local req = '<?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="' .. servicetype .. '">' .. arguments ..
'</u:' .. action .. '>' ..
'</s:Body>' ..
'</s:Envelope>'
local file_req = io.open( "/tmp/req.lua", "w" )
file_req:write( req )
file_req:close()
a = os.execute ('curl -s -X POST -H "SOAPAction: ' .. servicetype .. '#' .. action .. '" -d @/tmp/req.lua ' .. server_url)
Code: Select all
local IPaddress = '192.168.x.xx'
local action = "Stop"
local server_url = IPaddress .. ':1400/MediaRenderer/AVTransport/Control'
local servicetype = 'urn:schemas-upnp-org:service:AVTransport:1'
local arguments = '<InstanceID>0</InstanceID>,<Speed>1</Speed>'
local req = '<?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="' .. servicetype .. '">' .. arguments ..
'</u:' .. action .. '>' ..
'</s:Body>' ..
'</s:Envelope>'
local file_req = io.open( "/tmp/req.lua", "w" )
file_req:write( req )
file_req:close()
a = os.execute ('curl -s -X POST -H "SOAPAction: ' .. servicetype .. '#' .. action .. '" -d @/tmp/req.lua ' .. server_url)
Code: Select all
local IPaddress = '192.168.x.xx'
local action = "Pause"
local server_url = IPaddress .. ':1400/MediaRenderer/AVTransport/Control'
local servicetype = 'urn:schemas-upnp-org:service:AVTransport:1'
local arguments = '<InstanceID>0</InstanceID>,<Speed>1</Speed>'
local req = '<?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="' .. servicetype .. '">' .. arguments ..
'</u:' .. action .. '>' ..
'</s:Body>' ..
'</s:Envelope>'
local file_req = io.open( "/tmp/req.lua", "w" )
file_req:write( req )
file_req:close()
a = os.execute ('curl -s -X POST -H "SOAPAction: ' .. servicetype .. '#' .. action .. '" -d @/tmp/req.lua ' .. server_url)
Code: Select all
local IPaddress = '192.168.x.xx'
local action = "Next"
local server_url = IPaddress .. ':1400/MediaRenderer/AVTransport/Control'
local servicetype = 'urn:schemas-upnp-org:service:AVTransport:1'
local arguments = '<InstanceID>0</InstanceID>,<Speed>1</Speed>'
local req = '<?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="' .. servicetype .. '">' .. arguments ..
'</u:' .. action .. '>' ..
'</s:Body>' ..
'</s:Envelope>'
local file_req = io.open( "/tmp/req.lua", "w" )
file_req:write( req )
file_req:close()
a = os.execute ('curl -s -X POST -H "SOAPAction: ' .. servicetype .. '#' .. action .. '" -d @/tmp/req.lua ' .. server_url)
Code: Select all
local IPaddress = '192.168.x.xx'
local action = "Previous"
local server_url = IPaddress .. ':1400/MediaRenderer/AVTransport/Control'
local servicetype = 'urn:schemas-upnp-org:service:AVTransport:1'
local arguments = '<InstanceID>0</InstanceID>,<Speed>1</Speed>'
local req = '<?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="' .. servicetype .. '">' .. arguments ..
'</u:' .. action .. '>' ..
'</s:Body>' ..
'</s:Envelope>'
local file_req = io.open( "/tmp/req.lua", "w" )
file_req:write( req )
file_req:close()
a = os.execute ('curl -s -X POST -H "SOAPAction: ' .. servicetype .. '#' .. action .. '" -d @/tmp/req.lua ' .. server_url)
Code: Select all
local IPaddress = '192.168.x.xx'
local DesiredMute = "1"
local action = "SetMute"
local server_url = IPaddress .. ':1400/MediaRenderer/RenderingControl/Control'
local servicetype = 'urn:schemas-upnp-org:service:RenderingControl:1'
local arguments = '<InstanceID>0</InstanceID>,<Channel>Master</Channel>,<DesiredMute>' .. DesiredMute .. '</DesiredMute>'
local req = '<?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="' .. servicetype .. '">' .. arguments ..
'</u:' .. action .. '>' ..
'</s:Body>' ..
'</s:Envelope>'
local file_req = io.open( "/tmp/req.lua", "w" )
file_req:write( req )
file_req:close()
os.execute ('curl -s -X POST -H "SOAPAction: ' .. servicetype .. '#' .. action .. '" -d @/tmp/req.lua ' .. server_url )
Code: Select all
local IPaddress = '192.168.x.xx'
local DesiredMute = "0"
local action = "SetMute"
local server_url = IPaddress .. ':1400/MediaRenderer/RenderingControl/Control'
local servicetype = 'urn:schemas-upnp-org:service:RenderingControl:1'
local arguments = '<InstanceID>0</InstanceID>,<Channel>Master</Channel>,<DesiredMute>' .. DesiredMute .. '</DesiredMute>'
local req = '<?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="' .. servicetype .. '">' .. arguments ..
'</u:' .. action .. '>' ..
'</s:Body>' ..
'</s:Envelope>'
local file_req = io.open( "/tmp/req.lua", "w" )
file_req:write( req )
file_req:close()
os.execute ('curl -s -X POST -H "SOAPAction: ' .. servicetype .. '#' .. action .. '" -d @/tmp/req.lua ' .. server_url )