Captured XML

Forum to ask for any help
Post Reply
starwarsmike
Posts: 146
Joined: Mon May 13, 2013 12:48 pm

Captured XML

Post by starwarsmike » Sun Aug 09, 2015 5:31 pm

Untitled.jpg
Hi

Really needing some help....I am wanting send command from Demopad which starts a song in my Cyrus UpNp streamer, songs are stored on my NAS on 192.168.1.100.

I have tested this using UpNp Tools, and works fine, invoking the commands, so i know my NAs and Streamer as capable.

Using UPnP tools, I have captured the the following XML, the Cyrus Streamer is the 192.168.1.190

Question, how do i test this on Demopad? setup my streamer as a device? and send the XML data?

Any help is more than appreciated
You do not have the required permissions to view the files attached to this post.

User avatar
DemoPad
Site Admin
Posts: 769
Joined: Thu Jun 14, 2012 10:46 am
Contact:

Re: Captured XML

Post by DemoPad » Mon Aug 10, 2015 8:45 am

Yes, set up a device on port 8080, and send the data. See the Sonos commands from the device library forum, they are very similar.

starwarsmike
Posts: 146
Joined: Mon May 13, 2013 12:48 pm

Re: Captured XML

Post by starwarsmike » Mon Aug 10, 2015 11:55 am

Hi


I have setup a device 192.168.1.190, port 8080, ticked disconnect after each, Default sufix

I tried this but nothing happened? could you have a look below to see if is correct, I tried without the IP in the command line, only port 8080, didn't work either

POST /MediaRenderer/AVTransport/Control HTTP/1.1\x0D\x0ACONNECTION: close HOST: 192.168.1.190:8080\x0D\x0ACONTENT-LENGTH: 482\x0D\x0ACONTENT-TYPE: text/xml; charset="utf-8"\x0D\x0ASOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"\x0D\x0A\x0D\x0A<?xml version="1.0" encoding="utf-8"?><s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelop ... ansportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><InstanceID>0</InstanceID><CurrentURI>http://192.168.1.100:9000/disk/NON-DLNA ... RIMetaData /></u:SetAVTransportURI></s:Body></s:Envelope>\x0D\x0A

cv27
Posts: 233
Joined: Sat Nov 24, 2012 10:15 pm
Location: Montréal, QC, Canada

Re: Captured XML

Post by cv27 » Mon Aug 10, 2015 5:04 pm

If you've modified the content in any way, make sure the value for CONTENT-LENGTH reflects the true length.

User avatar
DemoPad
Site Admin
Posts: 769
Joined: Thu Jun 14, 2012 10:46 am
Contact:

Re: Captured XML

Post by DemoPad » Wed Aug 12, 2015 8:49 am

and make sure you include the \x0D\x0A line breaks where necessary. Hercules is a good tool for diagnosing - you can set up as a TCP Server & see the commands that both the app, and other devices (eg your browser) send, to compare.

starwarsmike
Posts: 146
Joined: Mon May 13, 2013 12:48 pm

Re: Captured XML

Post by starwarsmike » Sat Aug 29, 2015 10:28 am

I hope this helps someone along the way to build their own Media player.

How did I program this media player to play songs on my UPNP Streamer, which accessed songs from my NAS drive.

Here you go............

First i used Developer Tools for UPnP™ Technology Tools, free from the internet, & Wireshark, once you have found and captured one song, then the rest should be straight forward, see further below

Here is what i captured (note current URl below, this is the root of the song on my NAS drive (will explain later how to find this information)

Original XML

&r:KE.@E0|]/EP>[POST /AVTransport/ctrl HTTP/1.1
HOST: 192.168.1.190:8080
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 503

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
<InstanceID>0</InstanceID>
<CurrentURI>http://192.168.1.100:9000/disk/DLNA-PNM ... CurrentURI>
<CurrentURIMetaData />
</u:SetAVTransportURI>
</s:Body>
</s:Envelope>

In Demopad format

POST /AVTransport/ctrl HTTP/1.1\x0D\x0AHOST: 192.168.1.190:8080\x0D\x0ASOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"\x0D\x0ACONTENT-TYPE: text/xml; charset="utf-8"\x0D\x0AContent-Length: 503\x0D\x0A\x0D\x0A<?xml version="1.0" encoding="utf-8"?>\x0D\x0A<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encodin ... ansportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">\x0D\x0A<InstanceID>0</InstanceID>\x0D\x0A<CurrentURI>http://192.168.1.100:9000/disk/DLNA-PNM ... RIMetaData />\x0D\x0A</u:SetAVTransportURI>\x0D\x0A</s:Body>\x0D\x0A</s:Envelope>

You will now probably have to capture the play command, which will be send straight after to send the command above. To do this, there is a tool in the download developers tool called av wizard. select your UPnP device from the control app. Play a song normally with your remote, then use the Stop button on the av wizard, the run wirelshark and hit the Play button on av wizard. find the data in wireshark, which will look something like this...

&r:KEF&@mi[>|EPy3POST /AVTransport/ctrl HTTP/1.1
HOST: 192.168.1.190:8080
SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"
CONTENT-TYPE: text/xml; charset="utf-8"
Content-Length: 356

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<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>

In demopad format

POST /AVTransport/ctrl HTTP/1.1\x0D\x0AHOST: 192.168.1.190:8080\x0D\x0ASOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#Play"\x0D\x0ACONTENT-TYPE: text/xml; charset="utf-8"
\x0D\x0AContent-Length: 356\x0D\x0A\x0D\x0A<?xml version="1.0" encoding="utf-8"?>\x0D\x0A<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encodin ... x0A<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">\x0D\x0A <InstanceID>0</InstanceID>\x0D\x0A<Speed>1</Speed>\x0D\x0A</u:Play>\x0D\x0A</s:Body>\x0D\x0A</s:Envelope>

You can repeat this process for command like stop/pause/skip etc.

So, you now have a command to play a song & command to play it. Setup a button (song name) sent the song command, then sent the play command half second later.

Next, you don't have to capture every song, use one of the developers tools called av media controller. click on Content Directories, your NAS should be there, click music, All tracks, find your song and right click it, hit resources, then you can see the content uri something like this,
http://192.168.1.100:9000/disk/DLNA-PNM ... 034380.mp3

You copy and paste this into the above song command format, you might need to change the content length, I didn't, i just increased it by 10, e.g. the content length above is 503, when i copied and pasted my next song, i changed the content length to 513. It worked for me, not saying it will for everyone.

How to calculate content length

Morning Michael,

Glad it worked! Very strange that they all worked however… I thought only the last one I sent you would have worked because the others had varying content lengths..

So question is, I think i will need to change the content length each time pending on the length of the above HTTP, how do i check what the content length of a command?

Considering the content-lengths worked on the others I sent you, it gives the impression that as long as the content-length is equal-to or longer than the http data it’ll work. So with that being said, you could cheat the system and just use a large content-length that never changes.. Or, do it properly as follows:

Take all the data after the header part, so from <?xml… all the way to </s:Envelope> and count the number of characters using an online tool or similar (http://www.charactercountonline.com/ this one seemed to do the trick).

Once you have that number, take the xml in it’s proper form i.e:

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
<InstanceID>0</InstanceID>
<CurrentURI>http://192.168.1.100:9000/disk/DLNA-PNM ... CurrentURI>
<CurrentURIMetaData />
</u:SetAVTransportURI>
</s:Body>
</s:Envelope>

then for each line, add two characters (for the CR/LF), so the total length for the above xml would be 485 + 2 * 9 (ignore the last line) which is 503.

I am sure there is much easier ways to the highly skilled out there....

Michael

Post Reply