Home AMX User Forum NetLinx Studio

UpNP and NETLINX

Hi,

I was wondering if anyone could shed some light on how to send UPnP commands from Netlinx or a Netlinx Module. It would be greatly appreciated if anyone could post an example.

Comments

  • AMXJeffAMXJeff Posts: 450
    Hi,

    I was wondering if anyone could shed some light on how to send UPnP commands from Netlinx or a Netlinx Module. It would be greatly appreciated if anyone could post an example.

    I guess it would really help to know what your trying to do, control, discovery, or get information on with uPnP. Please shed some light on the purpose of your request,

    Thanks!

    Jeff
  • a_riot42a_riot42 Posts: 1,624
    Hi,

    I was wondering if anyone could shed some light on how to send UPnP commands from Netlinx or a Netlinx Module. It would be greatly appreciated if anyone could post an example.

    Its no different than sending any TCP packet. UPNP uses a weird mixture of http, xml, soap and a few other ingredients to communicate, so its just a matter of creating http packets and sending them. Here's an example of a function for a Sonos module that uses UPNP. It won't format correctly it seems but you get the point.
    define_function addURIToQueue(long lInstanceID, char sID[], 	 char sParentID[],  char sRestricted[],  char  sTitle[],  char sClass[], integer bPlayNow, integer bPlayNext)
    {
    	stack_var volatile char sCmd[2048]
    	stack_var volatile integer length
    
    
    	sCmd = "stEnvelope.sOpenTag,
    		'<s:Body>',
    		'<u:AddURIToQueue xmlns:u="urn:schemas-pnp-org:service:AVTransport:1">',
    		'<InstanceID>',itoa(lInstanceID),'</InstanceID>',
    		'<EnqueuedURI>',sID,'</EnqueuedURI>',
    		'<EnqueuedURIMetaData>',
    		'&lt;DIDL-Lite ',
    		'xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot; ',
    		'xmlns:upnp=&quot;urn:schemas-upnp-org:metadata-1-0/upnp/&quot; ',
    		'xmlns:r=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot; ',
    		'xmlns=&quot;urn:schemas-upnp-org:metadata-1-0',
    		'/DIDL-Lite/&quot;&gt;',
    		'&lt;item id=&quot;',sID,'&quot; ',
    		'parentID=&quot;',sParentID,'&quot; ',
    		'restricted=&quot;',sRestricted,'&quot;&gt;',
    		'&lt;dc:title&gt;',urlEncode(sTitle),'&lt;/dc:title&gt;',
    		'&lt;upnp:class&gt;',sClass,'&lt;/upnp:class&gt;',
    		'&lt;desc id=&quot;cdudn&quot; nameSpace=&quot;urn:schemas-rinconnetworks-com:metadata-1-0/&quot;&gt;',
    		'RINCON_AssociatedZPUDN&lt;/desc&gt;',
    		'&lt;/item&gt;',
    		'&lt;/DIDL-Lite&gt;',
    		'</EnqueuedURIMetaData>',
    		'<DesiredFirstTrackNumberEnqueued>',itoa(bPlayNext),'</DesiredFirstTrackNumberEnqueued>',
    		'<EnqueueAsNext>',itoa(bPlayNow),'</EnqueueAsNext>',
    		'</u:AddURIToQueue>',
    		'</s:Body>',
    		stEnvelope.sCloseTag"
    
    	length = length_string(sCmd)
    	
    	sendToControlPort( "stHeader.sPOST[cnServiceAVTransport],cnNL,
    					stHeader.sConnection[cnConnectionClose],cnNL,
    				       stHeader.sAcceptEncoding[cnEncodingZip],cnNL,
    					stHeader.sHost,cnNL,
    					stHeader.sUserAgent[cnUserAgentSonos],cnNL,
    					stHeader.sContentLength,itoa(length),cnNL,
    					stHeader.sContentType[cnContentTypeTextXML],cnNL,
    					stHeader.sSoapAction[cnSoapAddURIToQueue],cnNLNL,
    					sCmd")
    }
    
    
  • UPNP

    Theres also some good books around, there's an Intel one that I used to get background info when I was developing a Module for a mediastreamer. Its partly about UPNP design but it gives you all the basic - think its called UPNP design by example - I found it quite useful. Also there is quite a bit on the web, some of it crap, some good.

    As others have said, it depends what you are looking for....

    Duncan
  • Theres also some good books around, there's an Intel one that I used to get background info when I was developing a Module for a mediastreamer. Its partly about UPNP design but it gives you all the basic - think its called UPNP design by example - I found it quite useful. Also there is quite a bit on the web, some of it crap, some good.

    As others have said, it depends what you are looking for....

    Duncan

    ...or alternatively grab an app that already controls the device you are looking at and watch it on wireshark.takes a bit of getting used to but works
  • UPnP control point for AMX (beta):
    https://github.com/ok1mpd/Netlinx-UPnP-control-point
Sign In or Register to comment.