Sonos ZonePlayer Integration

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
Post Reply
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Sonos ZonePlayer Integration

Post by Osler »

I have been thinking/working on this for quite a while and stumbled across a relatively "brute force" way to integrate control of the Sonos ZonePlayer into HouseBot. There is a free program called AutoIt (http://www.autoitscript.com) that provides a core scripting system as well as an ActiveX DLL for Windows Automation. The basic methods of AutoIt are available via VBScript and, thus, HouseBot. I looked at doing this via UPnP...but I have neither the time nor inclination to do all of the coding to create a UPnP control point for integration of these devices. Find below a script (unfinished) with all of the capabilities for basic control of the Sonos Desktop Controller (the provided system software that acts as the UPnP control point for all attached ZonePlayers). Core functionality is provided by Subroutines within the script. You will need to download and install AutoIt3 to obtain the AutoItX3.dll which is used for the CreateObject.

I will update this post as I continue the process.

Osler
Last edited by Osler on Fri Feb 15, 2008 11:05 pm, edited 1 time in total.
Richard Naninck
HouseBot Guru Extraordinaire
Posts: 1121
Joined: Tue Sep 28, 2004 7:49 am
Location: The Netherlands

Post by Richard Naninck »

I don't have the Sonos system yet, but I can borrow one to check some stuff out. Many people want to have multiroom audio and Sonos is one of these systems that nicely provides this. If this could work using a housebot swremote next to the current sonos wireless remote, I guess it is very much worth it to give it a try. If you get any more concreet, I will try to get my hands on a Sonos system and pitch in some time to work this thing.

Nice to know someone is looking into this!
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Post by Osler »

Get one to play with....just simply because they are very, very cool.

I have basic control at this point thanks to AutoIt. It is much more robust and reliable than SendMessage in HouseBot. The hurdle is going to be displaying track info, library info, etc. and allowing one to build a queue from HouseBot. At this point, I have to rely on music selection via playlist only. At least now I can pause the ZonePlayers when the phone or doorbell rings....its a start. Maybe this is all I need....dunno.

Osler
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

UPnP Primer: Not as difficult as I thought

Post by Osler »

Alright, so I had some time and started digging into the UPnP.dll provided by Microsoft and working with it is not as bad as I thought it would be. This DLL exposes most everything needed to control a Sonos system from VBScript. This may not be the best method to do this and a stand-alone application (likely) or HB specific DLL (impossible since I don't code in C) may be required. For those interested (i.e., those with a ZonePlayer or thinking about getting a ZonePlayer), find below a script that walks you through the steps needed for device discovery, identification of device services, and invoking actions of services. It should be noted that these scripts should work with any UPnP compliant device (Roku, SqueezeBox, various routers, etc.). They just need to be modified for the targeted device. You will find the UPnP Device Spy from Intel extremely helpful when working with UPnP devices.
Last edited by Osler on Fri Feb 15, 2008 11:06 pm, edited 1 time in total.
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Step 1: Initial set-up script.

Post by Osler »

This is doable via scripting. It will need to be broken apart into a few scripts, though. Find below a "Set-Up" script that will need to be used during initial integration of a Sonos system into HouseBot or when adding an additional ZonePlayer to the system. The rationale for a seperate "discovery" script is that using the UPnP.FindByType Function is EXCEEDINGLY SLOW (4-5 s to perform the find) and would cause LONG delays if used everytime one wanted "talk" to a ZonePlayer. The UPnP.FindByUDN is much faster for finding a particular ZonePlayer and will be used for later scripts controlling the ZonePlayer. All the following script does is search for ZonePlayers, get their UDN (UniqueDeviceName), and populate a device.property in HouseBot with the UDN. This property can later be passed to other scripts that will do the actual work.

For this script to work, you need to create a Null Device for each Sonos ZonePlayer in your system. The DeviceName should be "ZonePlayer_<ZoneName> with the ZoneName corresponding to whatever you called the zone when you set it up with the Sonos software(i.e., "ZonePlayer_FamilyRoom" or ZonePlayer_Garage"). Each Null Device should have an alphanumeric Property called "UDN".


I will post additional scripts as I get them done. Control and status of the system will be very simple to do. I still haven't figured out how to obtain the index from the mediaserver (i.e., what songs are available for queue population). However, this should come in time.

Osler
Last edited by Osler on Fri Feb 15, 2008 11:07 pm, edited 1 time in total.
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

A little help...

Post by Osler »

Richard or Scott:

A little help would be appreciated. I have VBScripts that function in VBSEdit (a program I use for scripting) but when I try them with the HouseBot scripting engine HouseBot coughs, sputters, and then dies a horrible death. I can add a HouseBot COM component to the script for communication with HouseBot, but I will need to "SHELL" out the script to a different scripting engine. How exactly do I do this? Currently, the two scripts I have work flawlessly in a non-HouseBot environment for control of a Sonos system. I don't do this for a living and this is just supposed to be a hobby....

Osler
ScottBot
Site Admin
Posts: 2786
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: A little help...

Post by ScottBot »

Osler wrote:... HouseBot coughs, sputters, and then dies a horrible death.
If HouseBot crashes, it should create a dump file that may be helpful. If there is a recent file in the \HouseBot\Dump directory, please send it to me at [email protected]
Scott
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Post by Osler »

Here is the result of the dump file from trying to call into the UPnP.dll.

Code: Select all


====== Begin Dump - Wednesday, November 15, 2006 14:11:56 ======
Server Version = 2.22
Exception code: C0000005 ACCESS_VIOLATION
Fault address:  00501B5B 01:00100B5B C:\Program Files\Meedio\Meedio HouseBot\HouseBotServer.exe

Registers:
EAX:0971FF2C
EBX:00DB3198
ECX:0056F570
EDX:00000005
ESI:0104C008
EDI:00EE75B0
CS:EIP:001B:00501B5B
SS:ESP:0023:0972EDF8  EBP:005C60F2
DS:0023  ES:0023  FS:003B  GS:0000
Flags:00010202

Call stack:
Address   Frame
00501B5B  005C60F2  CxImage::`copy constructor closure'+1000EB
6E497265  76726553  0000:00000000 


====== End Dump ======
I have gotten this to work by calling wscript.exe from an Execute Program Device and passing the command line argument of the full path to the script. I need to put together some documentation because it is not exactly a simple thing to set up (multiple devices, multiple specific properties, etc.). I successfully discovered my ZonePlayers last night on the network and was able to send transport commands, rendering commands (mute, volume, bass, treble, etc), and obtain some basic information regarding the current track.....all from within the HouseBot interface. Very cool indeed.

Osler
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

The primer continues

Post by Osler »

Since I don't really comment the actual scripts I am posting for ZonePlayer control, I will continue to post my idea scripts that are fruitful so that anyone seeking to understand the code can follow the logic. Below are the steps involved with obtaining album, artist, and current track info from the queue of a ZonePlayer.


I haven't gotten a whole lot of response from this but I am posting this mostly as a resource for others. I found my attempts at understanding UPnP extremely frustrating and would have loved to have had commented source code to look at when doing this.

Enjoy.

Osler
Last edited by Osler on Fri Feb 15, 2008 11:07 pm, edited 1 time in total.
CouchPotatoe
Senior Member
Posts: 103
Joined: Sun Jul 31, 2005 2:43 pm
Location: Yorkshire UK

Re: The primer continues

Post by CouchPotatoe »

Osler wrote: I haven't gotten a whole lot of response from this ...
Osler
Hi there - just to say that I'm watching this topic with great interest and appreciate all the information you're posting. As well as obviously the objective of integrating Sonos (which I have) with HouseBot I'm also keen to learn a lot more about uPNP so this is great...

Thanks Kevin
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Post by Osler »

Thanks CP. Keep watching...it's a work in progress. Updated scripts posted.

Osler
Post Reply