Jump to content



Photo

UPnP : Read and Control your devices in side out


  • Please log in to reply
10 replies to this topic

#1 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 13 November 2007 - 08:32 AM

UPnP Protocol

For those who don't know what UPnP is :

Short for Universal Plug and Play, a networking architecture that provides compatibility among networking equipment,
software and peripherals of the 400+ vendors that are part of the Universal Plug and Play Forum.

UPnP works with wired or wireless networks and can be supported on any operating system. UPnP boasts device-driver
independence and zero-configuration networking.

UPnP uses the SSDP protocol :
SSDP uses UDP unicast and multicast packets to advertise their services. The multicast address is 239.255.255.250.
SSDP uses port 1900

Some tilme ago someone in the help forum was asking if it was possible to use UPnP and AU3 ....

Well UPnP can access all UPnP compatible devices and retrieve information from it.
And the beauty of this all is, it can not on retrieve info from it, it can also control it remotely !!
Like you can add port forwarding in your router, remotely. Or block ports etc.

So in theory you can access the sound volume button on your UPnP Media player and turn it up or down, as well.
Like this : UPnP-based media player devices

Here is a little sample of how you get started :

AutoIt         
; http://msdn2.microsoft.com/en-us/library/aa382297.aspx Dim $deviceFinder Dim $DeviceType Dim $Devices Dim $Device Dim $strDescDocURL $DeviceFinder = ObjCreate( "UPnP.UPnPDeviceFinder" ) $DeviceServices = ObjCreate( "UPnP.UPnPServices" ) $DeviceService = ObjCreate( "UPnP.UPnPService" ) $Device = ObjCreate( "UPnP.UPnPDevice" )                             $DeviceType = "upnp:rootdevice" $Devices = $DeviceFinder.FindByType($DeviceType,0) ;$strDescDocURL = $DescriptionDoc.GetDocumentURL ConsoleWrite( $strDescDocURL & @LF) ConsoleWrite( "Found # :" & $Devices.Count & " Devices" & @LF & @LF) ;ConsoleWrite( "Services # :" & $DeviceService.Count & " Devices" & @LF & @LF) For $DeviceObj in $Devices     ConsoleWrite("Children " & $DeviceObj.Children & @CRLF)     ConsoleWrite("Description " & $deviceObj.Description& @CRLF)     ConsoleWrite("FriendlyName " & $deviceObj.FriendlyName & @CRLF)     ConsoleWrite("HasChildren " & $deviceObj.HasChildren & @CRLF)     ConsoleWrite("IsRootDevice " & $deviceObj.IsRootDevice & @CRLF)     ConsoleWrite("ManufacturerName " & $deviceObj.ManufacturerName & @CRLF)     ConsoleWrite("ManufacturerURL " & $deviceObj.ManufacturerURL & @CRLF)     ConsoleWrite("ModelName " & $deviceObj.ModelName & @CRLF)     ConsoleWrite("ModelNumber " & $deviceObj.ModelNumber & @CRLF)     ConsoleWrite("ModelURL " & $deviceObj.ModelURL & @CRLF)     ConsoleWrite("ParentDevice " & $deviceObj.ParentDevice & @CRLF)     ConsoleWrite("PresentationURL " & $deviceObj.PresentationURL & @CRLF)     ConsoleWrite("RootDevice " & $deviceObj.RootDevice & @CRLF)     ConsoleWrite("SerialNumber " & $deviceObj.SerialNumber & @CRLF)     ConsoleWrite("Services " & $deviceObj.Services & @CRLF)     ConsoleWrite("Device URN Type " & $deviceObj.Type & @CRLF)     ConsoleWrite("UniqueDeviceName " & $deviceObj.UniqueDeviceName & @CRLF)     ConsoleWrite("Product Code - UPC " & $deviceObj.UPC & @CRLF)     ConsoleWrite(@LF) next


IMOPORTANT :
- Make sure that you UPnP device has the UPnP feature enabled, by default it might not be so.
- Make sure that you firewall (in XP) is off or has the UPnP Framework trafic allowed.

Enjoy!!

ptrex

Edited by ptrex, 14 September 2012 - 08:59 AM.






#2 Gif

Gif

    Laikon Kafekoption

  • Active Members
  • PipPipPipPipPipPip
  • 1,117 posts

Posted 13 November 2007 - 02:02 PM

great ptrex, another usefull work from you :P

#3 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 13 November 2007 - 02:10 PM

@Gif

Thanks.

The things I showed is only the top of the iceberg.

Once you start digging into the UPnP stuff, you are hitting the jackpot !!

Got myself amazed the last couple of days, playing around with this. :P

regards,

ptrex

Edited by ptrex, 13 November 2007 - 02:10 PM.


#4 Avee

Avee

    Seeker

  • Active Members
  • 7 posts

Posted 19 March 2008 - 05:09 PM

Hi ptrex,

Inspired by your post, I am trying to develop something for my music system. Basically, I want to know when the player is paused or not, so that I can switch my amp on and off. I am a complete novice at autoit, so I might be completely missing something. I added the following bit of test code to your example, and it doesn't work:

$UpCallback = $DeviceService.Addcallback("uuid:RINCON_000E5823005801400") $SinkObject=ObjEvent($UpCallback,"pnpEvent_") while True     sleep(1000) WEnd Func pnpEvent_StateVariableChanged( $Serviceobject, $ChangedVar, $VarVal )         ConsoleWrite("Var CHanged! :" & $ChangedVar & " = " & $VarVal & @CRLF) EndFunc


It does compile, but it never reacts to any event. Did I implement the callback function right?

#5 Avee

Avee

    Seeker

  • Active Members
  • 7 posts

Posted 29 March 2008 - 10:21 PM

anyone else have an idea?

thanks!

#6 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 30 March 2008 - 06:12 PM

@Avee

If the AutoIt is new to you AND UPnP is new as well.

Then I think this might be a bit over your head to get started with.

Anyhow if you want to persist. I recomment to drop the COM interface to UPnP and go for the protocol level.

First thing to do is start reading about the protocol here Universal_Plug_and_Play and UPnP Standards

Furhter you can use the TCP functions in AU3 to implement a UPnP test case.

I hope this get"s you started on this.

regards,
ptrex

#7 Sog

Sog

    Seeker

  • Active Members
  • 10 posts

Posted 06 March 2012 - 12:16 AM

Hi ptrex, I've been trying to get the streaming 'Media ID' of the files on my humax hdr, its a upnp dnla media server but having played around with your amazing script for a while I've managed to find a few xml files but I'm now stumped!

Background (what Im trying to achieve)

I recently started writing a prog to take TV recordings off my TV box, strip the ads and re-encode with the updated humax support files. there is a way to do it but that involves using the remote to copy the file to USB (this decrypts the file if its SD) Then FTP copy it to your PC and run a series of progs to process the file.

I can stream and save the file straight to the PC cutting out the need to copy them to USB as they are decrypted on the way (including the HD recordings!) this also means it can be fully automatic as you won't need to use the remote for any stage of the process.

bottom line...
I can get the filenames but to stream them I need to know the 'Media ID' to initiate the stream
(eg: http://192.168.##.#/MyVideo:56444 instead of http://192.168.##.#/MyVideo/tvrecording.ts)

I'm completely stumped. any help would be greatfully recieved and you will obviously be given credit in the program's About' info window...

Cheers, Sog

#8 Sog

Sog

    Seeker

  • Active Members
  • 10 posts

Posted 06 March 2012 - 02:26 AM

p.s. The program Im writing is an autoit script (and I stupidly searched the web for days for clues. I should have come here first!)

apologies for the double post, Im not allowed to edit my original post...

#9 ptrex

ptrex

    Universalist

  • MVPs
  • 2,399 posts

Posted 06 March 2012 - 05:17 PM

@Sog

A good way to get started is looking here :

http://msdn.microsoft.com/en-us/library/windows/desktop/aa381156(v=vs.85).aspx

Rgds
ptrex

#10 Sog

Sog

    Seeker

  • Active Members
  • 10 posts

Posted 10 March 2012 - 11:04 PM

Thanks ptrex, I'll post back the prog if I can get my head round it, Im new to this so I may be some time... lol...

#11 Sog

Sog

    Seeker

  • Active Members
  • 10 posts

Posted 25 March 2012 - 02:27 AM

Thanks ptrex, I'll post back the prog if I can get my head round it, Im new to this so I may be some time... lol...



sadly lifes got in the way of getting on with this, will reply as soon as Ive sussed it out tho....




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users