Jump to content

UPnP : Read and Control your devices in side out


ptrex
 Share

Recommended Posts

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 :

; 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
Link to comment
Share on other sites

@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
Link to comment
Share on other sites

  • 4 months later...

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?

Link to comment
Share on other sites

  • 2 weeks later...

@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

Link to comment
Share on other sites

  • 3 years later...

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

  • 2 weeks later...

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....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...