Sending AVTransport commands to UPNP DMR using command line

If you are working on developing DMR (Digital Media Renderer) or DMC ( Digital Media Controller) for UPNP, its possible that we need to emulate the communication between two during the development. We tried to do the same by trying to send the HTTP Post commands to our DMR in our Sony TV from the command line. ( These same commands will be sent by DMC to DMR )

Follow the steps from “Script to find UPNP devices / servers in a network” to run the upnp_info.py python script to identify the UPNP devices available in your network.

Although our network right now has 5 active UPNP devices, in this post we will just try to send UPNP commands to DMR using command line, and as can be seen below, our DMR details are at http://192.168.0.100:52323/dmr.xml

$ python upnp_info.py 
[+] Discovering UPnP locations
[+] Discovery complete
[+] 5 locations found:
	-> http://192.168.0.100:52323/dmr.xml

[+] Loading http://192.168.0.100:52323/dmr.xml...
	-> Server String: Linux/2.6 UPnP/1.0 KDL-32W600A/1.7
	==== XML Attributes ===
	-> Device Type: urn:schemas-upnp-org:device:MediaRenderer:1
	-> Friendly Name: BRAVIA KDL-32W600A
	-> Manufacturer: Sony Corporation
	-> Manufacturer URL: http://www.sony.net/
	-> Model Name: KDL-32W600A
	-> Model Number: MINT1.7.0.1
	-> Services:
		=> Service Type: urn:schemas-upnp-org:service:RenderingControl:1
		=> Control: /upnp/control/RenderingControl
		=> Events: /upnp/event/RenderingControl
		=> API: http://192.168.0.100:52323/RenderingControlSCPD.xml
			- ListPresets
			- SelectPreset
			- GetMute
			- SetMute
			- GetVolume
			- SetVolume
		=> Service Type: urn:schemas-upnp-org:service:ConnectionManager:1
		=> Control: /upnp/control/ConnectionManager
		=> Events: /upnp/event/ConnectionManager
		=> API: http://192.168.0.100:52323/ConnectionManagerSCPD.xml
			- GetProtocolInfo
			- GetCurrentConnectionIDs
			- GetCurrentConnectionInfo
		=> Service Type: urn:schemas-upnp-org:service:AVTransport:1
		=> Control: /upnp/control/AVTransport
		=> Events: /upnp/event/AVTransport
		=> API: http://192.168.0.100:52323/AVTransportSCPD.xml
			- SetAVTransportURI
			- SetNextAVTransportURI
			- GetMediaInfo
			- GetTransportInfo
			- GetPositionInfo
			- GetDeviceCapabilities
			- GetTransportSettings
			- Stop
			- Play
			- Pause
			- Seek
			- Next
			- Previous
			- GetCurrentTransportActions
			- X_DLNA_GetBytePositionInfo
		=> Service Type: urn:dial-multiscreen-org:service:dial:1
		=> Control: /upnp/control/DIAL
		=> Events: None
		=> API: http://192.168.0.100:52323/DIALSCPD.xml
		=> Service Type: urn:schemas-sony-com:service:IRCC:1
		=> Control: http://192.168.0.100/sony/IRCC
		=> Events: None
		=> API: http://192.168.0.100:52323/IRCCSCPD.xml
			- X_SendIRCC
			- X_GetStatus
		=> Service Type: urn:schemas-sony-com:service:ScalarWebAPI:1
		=> Control: /upnp/control/ScalarAPI
		=> Events: None
		=> API: http://192.168.0.100:52323/ScalarWebApiSCPD.xml

When we opened the dmr.xml from http://192.168.0.100:52323/dmr.xml we can see that details of AVTransport service are available at http://192.168.0.100:52323/AVTransportSCPD.xml as can be seen from “< SCPDURL >” and the controlURL is “/upnp/control/AVTransport”

<service>
<serviceType>urn:schemas-upnp-org:service:AVTransport:1</serviceType>
<serviceId>urn:upnp-org:serviceId:AVTransport</serviceId>
<SCPDURL>/AVTransportSCPD.xml</SCPDURL>
<controlURL>/upnp/control/AVTransport</controlURL>
<eventSubURL>/upnp/event/AVTransport</eventSubURL>
</service>

Now, with this much details with us, we can check the different actions supported by the AVTransport service for this DMR from http://192.168.0.100:52323/AVTransportSCPD.xml

Sending commands to this DMR from command line using http post

As we know from above “192.168.0.100” is the IP address of DMR, “52323” is the Port (as can be seen from http://192.168.0.100:52323/dmr.xml ) on which DMR is running and “/upnp/control/AVTransport” is the control URL to which we can send the commands to get the action details.

Below script just send “GetTransportInfo” command from AVTransport service,

$ vim getTransportInfo.sh
#!/bin/bash
#OUR DMR is at http://192.168.0.100:52323/dmr.xml
IP_ADDR=192.168.0.100
PORT=52323
UPNP_COMMAND=GetPositionInfo
AVTransport_PATH=upnp/control/AVTransport

curl -X POST -i -H "Content-type: text/xml; charset=\"utf-8\"" -H "SOAPACTION: \"urn:schemas-upnp-org:service:AVTransport:1#$UPNP_COMMAND\"" http://$IP_ADDR:$PORT/$AVTransport_PATH -v -d "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body><u:$UPNP_COMMAND xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\"><InstanceID>0</InstanceID></u:$UPNP_COMMAND></s:Body></s:Envelope>"

when we run this script as,

$ bash getTransportInfo.sh

we will get the details as,

$ bash getTransportInfo.sh 
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 192.168.0.100...
* TCP_NODELAY set
* Connected to 192.168.0.100 (192.168.0.100) port 52323 (#0)
> POST /upnp/control/AVTransport HTTP/1.1
> Host: 192.168.0.100:52323
> User-Agent: curl/7.58.0
> Accept: */*
> Content-type: text/xml; charset="utf-8"
> SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#GetTransportInfo"
> Content-Length: 274
> 
* upload completely sent off: 274 out of 274 bytes
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Content-Length: 420
Content-Length: 420
< Content-Type: text/xml; charset="utf-8"
Content-Type: text/xml; charset="utf-8"
< EXT: 
EXT: 
< Connection: Keep-Alive
Connection: Keep-Alive
< Date: Sun, 31 May 2020 09:50:55 GMT
Date: Sun, 31 May 2020 09:50:55 GMT
< Server: Linux/2.6 UPnP/1.0 KDL-32W600A/1.7
Server: Linux/2.6 UPnP/1.0 KDL-32W600A/1.7
< X-AV-Server-Info: av=5.0; cn="Sony Corporation"; mn="BRAVIA KDL-32W600A"; mv="1.7";
X-AV-Server-Info: av=5.0; cn="Sony Corporation"; mn="BRAVIA KDL-32W600A"; mv="1.7";
< X-AV-Physical-Unit-Info: pa="BRAVIA KDL-32W600A";
X-AV-Physical-Unit-Info: pa="BRAVIA KDL-32W600A";

< 
* Connection #0 to host 192.168.0.100 left intact
<?xml version="1.0"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><u:GetTransportInfoResponse xmlns:u="urn:schemas-upnp-org:service:AVTransport:1"><CurrentTransportState>STOPPED</CurrentTransportState><CurrentTransportStatus>OK</CurrentTransportStatus><CurrentSpeed>1</CurrentSpeed></u:GetTransportInfoResponse></s:Body></s:Envelope>

Leave a Comment