Note that there are some explanatory texts on larger screens.

plurals
  1. POError 405 when trying to control Sonos through PHP
    primarykey
    data
    text
    <p>This is my error:</p> <pre><code>exception 'Exception' with message 'Error sending command: HTTP/1.1 405 Method Not Allowed Allow: GET, HEAD Content-type: text/html Server: Linux UPnP/1.0 Sonos/24.0-69180 (BR100) Connection: close Error 405 Method Not Allowed ' in C:\wamp\www\PHPSonos.inc.php:240 Stack trace: #0 C:\wamp\www\PHPSonos.inc.php(148): PHPSonos-&gt;sendPacket('POST /MediaRend...') #1 C:\wamp\www\demo.php(9): PHPSonos-&gt;SetRadio('x-rincon-mp3rad...') #2 {main} nope. </code></pre> <p>I'm hosting this server through the latest version of WAMP on port 8080. Whenever I try to visit my main page, demo.php, it's supposed to send a SOAP/UPNP request to the sonos player. Unfortunately, it always comes up with error 405. I need help fixing this ASAP.</p> <p>This is my code: Main page:</p> <pre><code>&lt;?php include("PHPSonos.inc.php"); $sonos = new PHPSonos("192.168.1.5"); //Sonos ZP IPAdresse //Grundfunktionen try { //$sonos-&gt;Pause(); $sonos-&gt;SetRadio("x-rincon-mp3radio://players.creacast.com/creacast/klassik/playlist.pls"); $sonos-&gt;Play(); } catch(Exception $e) { echo $e; } //$sonos-&gt;Play(); //$sonos-&gt;Next(); //$sonos-&gt;Previous(); //$sonos-&gt;Rewind(); //$sonos-&gt;SetVolume(1); //0-100 in % //$sonos-&gt;SetPlayMode("NORMAL"); //REPEAT_ALL, SHUFFLE, NORMAL //$sonos-&gt;SetMute(false); //True = MUTE, False = KEIN MUTE //Klassik Radio abspielen //$sonos-&gt;SetRadio("x-rincon-mp3radio://players.creacast.com/creacast/klassik/playlist.pls"); //$sonos-&gt;Play(); //Neue MP3 abspielen //$sonos-&gt;ClearQueue(); //Playlist löschen //$sonos-&gt;AddToQueue("x-file-cifs://ipsserver/Public/test.mp3"); //Datei hinzufügen //$sonos-&gt;SetQueue("x-rincon-queue:RINCON_"."HIER DIE MAC DES PLAYERS ZB: FFEEDDCCBBAA"."01400#0"); //Playlist auswählen (Nötig, wenn Radio vorher ausgewählt war) //$sonos-&gt;Play(); ?&gt; &lt;html&gt; &lt;body&gt; nope. &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The script it's importing:</p> <pre><code>&lt;?php //Sonos PHP Script //Copyright: Michael Maroszek //Version: 1.0, 09.07.2009 class PHPSonos { private $address = ""; public function __construct( $address ) { $this-&gt;address = $address; } public function Pause() { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: 252 CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Pause" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:Pause xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;/u:Pause&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function Play() { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: 266 CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;Speed&gt;1&lt;/Speed&gt;&lt;/u:Play&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function Next() { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: 250 CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Next" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:Next xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;/u:Next&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function Previous() { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: 258 CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Previous" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:Previous xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;/u:Previous&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function Rewind() { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: 296 CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Seek" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:Seek xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;Unit&gt;REL_TIME&lt;/Unit&gt;&lt;Target&gt;00:00:00&lt;/Target&gt;&lt;/u:Seek&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function SetVolume($volume) { $content='POST /MediaRenderer/RenderingControl/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: 32'.strlen($volume).' CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:SetVolume xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;Channel&gt;Master&lt;/Channel&gt;&lt;DesiredVolume&gt;'.$volume.'&lt;/DesiredVolume&gt;&lt;/u:SetVolume&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function SetMute($mute) { if($mute) { $mute = "1"; } else { $mute = "0"; } $content='POST /MediaRenderer/RenderingControl/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: 314 CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:RenderingControl:1#SetMute" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:SetMute xmlns:u="urn:schemas-upnp-org:service:RenderingControl:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;Channel&gt;Master&lt;/Channel&gt;&lt;DesiredMute&gt;'.$mute.'&lt;/DesiredMute&gt;&lt;/u:SetMute&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function SetPlayMode($mode) { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: '.(291+strlen($mode)).' CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetPlayMode" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:SetPlayMode xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;NewPlayMode&gt;'.$mode.'&lt;/NewPlayMode&gt;&lt;/u:SetPlayMode&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function SetRadio($radio) { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: '.(974+strlen(htmlspecialchars($radio))).' CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;CurrentURI&gt;'.htmlspecialchars($radio).'&lt;/CurrentURI&gt;&lt;CurrentURIMetaData&gt;&amp;lt;DIDL-Lite xmlns:dc=&amp;quot;http://purl.org/dc/elements/1.1/&amp;quot; xmlns:upnp=&amp;quot;urn:schemas-upnp-org:metadata-1-0/upnp/&amp;quot; xmlns:r=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot; xmlns=&amp;quot;urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/&amp;quot;&amp;gt;&amp;lt;item id=&amp;quot;R:0/0/0&amp;quot; parentID=&amp;quot;R:0/0&amp;quot; restricted=&amp;quot;true&amp;quot;&amp;gt;&amp;lt;dc:title&amp;gt;IP-Symcon Radio&amp;lt;/dc:title&amp;gt;&amp;lt;upnp:class&amp;gt;object.item.audioItem.audioBroadcast&amp;lt;/upnp:class&amp;gt;&amp;lt;desc id=&amp;quot;cdudn&amp;quot; nameSpace=&amp;quot;urn:schemas-rinconnetworks-com:metadata-1-0/&amp;quot;&amp;gt;SA_RINCON65031_&amp;lt;/desc&amp;gt;&amp;lt;/item&amp;gt;&amp;lt;/DIDL-Lite&amp;gt;&lt;/CurrentURIMetaData&gt;&lt;/u:SetAVTransportURI&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function SetQueue($queue) { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: '.(342+strlen(htmlspecialchars($queue))).' CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;CurrentURI&gt;'.htmlspecialchars($queue).'&lt;/CurrentURI&gt;&lt;CurrentURIMetaData&gt;&lt;/CurrentURIMetaData&gt;&lt;/u:SetAVTransportURI&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function ClearQueue() { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: 290 CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#RemoveAllTracksFromQueue" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:RemoveAllTracksFromQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;/u:RemoveAllTracksFromQueue&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function AddToQueue($file) { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: '.(438+strlen(htmlspecialchars($file))).' CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#AddURIToQueue" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:AddURIToQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;EnqueuedURI&gt;'.htmlspecialchars($file).'&lt;/EnqueuedURI&gt;&lt;EnqueuedURIMetaData&gt;&lt;/EnqueuedURIMetaData&gt;&lt;DesiredFirstTrackNumberEnqueued&gt;0&lt;/DesiredFirstTrackNumberEnqueued&gt;&lt;EnqueueAsNext&gt;1&lt;/EnqueueAsNext&gt;&lt;/u:AddURIToQueue&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function RemoveFromQueue($track) { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: '.(307+strlen($track)).' CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#RemoveTrackFromQueue" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:RemoveTrackFromQueue xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;ObjectID&gt;Q:0/'.$track.'&lt;/ObjectID&gt;&lt;/u:RemoveTrackFromQueue&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } public function SetTrack($track) { $content='POST /MediaRenderer/AVTransport/Control HTTP/1.1 CONNECTION: close HOST: '.$this-&gt;address.':1400 CONTENT-LENGTH: '.(288+strlen($track)).' CONTENT-TYPE: text/xml; charset="utf-8" SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Seek" &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt;&lt;s:Body&gt;&lt;u:Seek xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"&gt;&lt;InstanceID&gt;0&lt;/InstanceID&gt;&lt;Unit&gt;TRACK_NR&lt;/Unit&gt;&lt;Target&gt;'.$track.'&lt;/Target&gt;&lt;/u:Seek&gt;&lt;/s:Body&gt;&lt;/s:Envelope&gt;'; $this-&gt;sendPacket($content); } private function sendPacket( $content ) { $fp = fsockopen($this-&gt;address, 1400 /* Port */, $errno, $errstr, 10); if (!$fp) throw new Exception("Error opening socket: ".$errstr." (".$errno.")"); fputs ($fp, $content); $ret = ""; while (!feof($fp)) { $ret.= fgets($fp,128); } fclose($fp); if(strpos($ret, "200 OK") === false) throw new Exception("Error sending command: ".$ret); } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload