Sonos plugin

Hi,
I am having trouble getting the device created to show up under the actions in the scene. I have tried installing it several times…the device shows up, IP address sets, but no actions available in the scene edit. I am using firmware .1245 and UI4…
any ideas?
Thanks
Tim Alls
AllSeas Yachts

Hi TimAlls,

You need to create a new device - then select advanced tab and pick a device.

Can you pls check if the sonos device you created is available in this drop down or not?

Regards,

anker

@guessed:

Can you pls help digging into the socket.http? I am trying to loo into doing upnp events and was wondering if the socket.http supports a “SUBSCRIBE” method at all? I can see that it supports GET and POST, but not more… Are you familiar with this?

Sorry if this is a stupid question!

/anker

Hi TimAlls,

You need to create a new device - then select advanced tab and pick a device.

Can you pls check if the sonos device you created is available in this drop down or not?


Thanks. I’m sure others are making the same mistake I did.
For clarification…
Upload the files
Create the device
Set the IP address
Then to create an action …create a scene…go to the advanced tab …pick a device…pick the action.
I will give it a try! Thanks
Has anyone tried this when multiple units are grouped?
The volume control gets tricky in this mode…I used a program I wrote in Labview to control the sonos system using TCPIP calls but I never mastered the group volume control.

Regards
Tim Alls

[quote=“anker, post:57, topic:169644”]I will however need to have a look if an upgrade will help me out here. I was under the impression that my version 1.1.1245 was the latest stable release, but maybe I lost track of this? :wink:

What is the latest version you would recommend for Vera 1?[/quote]
Sorry for the old replies, just going through my backlog…

You might want to ask that question more generally on the upgrade forums. My Vera2 uses 1.1.1337 which has been good-enough for me for quite a while.

[quote=“anker, post:58, topic:169644”]@guessed:

I have made a new revision (11) trying to add some logic for a upnp DeviceProperties call. The upnp call is succesfull from the logs and returns XML that is usefull. I however cannot find out your table code and find out what the UPnP_request function returns.

Can you help me out on examles on how I should read the data ???

Here is my code snip that I have added:

[code]-- Get Device info and populate variables
local l_DeviceInfo = upnp.UPnP_request(luup.devices[lul_device].ip, ipPort, UPNP_DEVICE_PROPERTIES_URL,
“GetZoneAttributes”, upnp.UPNP_DEVICE_PROPERTIES_SID,
{CurrentZoneName=“”, CurrentIcon=“”})

– The following fails as Deviceinfo is nil… what am I doing wrong? (The UPnP call is successfull)
– log("DeviceInfo: " … DeviceInfo)[/code]

i have commented my trouble out, so that the files are operational.

/anker[/quote]

I haven’t tried this, but eyeballing the code above you declare a variable called [tt]l_DeviceInfo[/tt], but you print/log a variable called [tt]DeviceInfo[/tt].

The latter will be considered a non-defined variable, so will return a nil result. Note that the current implementation of [tt]UPnP_request[/tt] is very simple, and returns a Lua Table object, and not a string, so it won’t be directly printable anyhow.

It current has an assumption that the data is not array-oriented XML… which is why the implementation is a little too simple for all UPnP responses

[quote=“anker, post:63, topic:169644”]@guessed:

Can you pls help digging into the socket.http? I am trying to loo into doing upnp events and was wondering if the socket.http supports a “SUBSCRIBE” method at all? I can see that it supports GET and POST, but not more… Are you familiar with this?

Sorry if this is a stupid question!

/anker[/quote]
Yes, it can pass any method [string] you’d like.

You can see the example usage here:
L_Sonos1.lua in trunk – Sonos Wireless HiFi Music Systems

In this case, I’m passing a “POST” method, but you could pass other strings as needed. For reference, here’s the documentation for this library:

http://w3.impa.br/~diego/software/luasocket/http.html

Of course, for Subscribe (like WebDAV [tt]SUBSCRIBE[/tt]), you’ll need to have a URL that can be called back when the data changes, but it’s possible to at least make the registration call.

You could use [tt]http://wiki.micasaverde.com/index.php/Luup_Lua_extensions#function:_register_handler[/tt] to create a callback [tt]URL[/tt].

Right, I’m assuming that’s what they were planning on doing, or even just a regular service decl, but it’s not really for the feint of heart :wink:

…so basicly I cannot get an upnp callback to work? Hmm - too bad. The only other option is to poll frequently, or?

That’s been my experience. The process seems to be:

  1. Client sends a UPnP request to Vera, which does a in the plugin. Vera returns “5” Job not complete.
  2. Vera starts doing whatever it does as part of the job.
  3. Client polls Vera for job status, gets “5” Job not complete.
    (Repeat steps 2-3 as long as job takes.)
  4. Vera finishes job and stores the return value in its Lua interpreter in a global variable.
  5. Client polls Vera for job status, gets “4” Job complete.
  6. Client calls Vera’s registered handler URL.
  7. Vera invokes handler Lua function, which produces a result that goes into the HTTP response from step 6.
  8. HTTP response is returned to client.

It’s really fiddly and I had to reverse-engineer step 5 from string-sniffing the LuaUPnP executable, but I’ve since been told by MCV that it’s kosher.

I’d love a method of doing it that doesn’t involve three+ client requests, but I’m not aware of any. There are absolutely no callbacks, not even a long-poll that blocks until something interesting happens.

There’s source code to do the above in the Caddx alarm plugin, if anyone wants to mine it for ideas.

It’s more that the secret sauce, and bulk of the research, will be in getting the HTTP response back into Vera from the calling UPnP Device. As @futzle indicates above, this is possible, but it’ll likely be the devil in the details of how that’s actually done for XML response payloads.

From the library perspective, it’ll be simple to add the code to let a UPnP Event be registered, provided

a) that call can be given an appropriate MiOS-based URL to call back into AND;
b) the resulting Callback’s XML Body Payload can be ready/handled by the MiOS/Device Mechanisms that @futzle indicates.

One (a) and (b) are done, the event handler can call back into the UPnP Lib to “process” the XML that comes back from the device, and turn it into something structured for the Device to handle.

Hi,

I was thinking of a work around like this:

  1. Make the SUBSCRIBE UPnP call with a callback url externally on a private webserver (if possible?).
  2. Setup a receiving perl script on the external server url that
    a. Stores the data as a file
    b. Actives a scene on Vera through http request
  3. The scene that is activated initiates a wget to the external server fetching the data.

Would above work? Comments please :slight_smile:

/anker

If the XML SOAP body cannot directly be processed (not proven yet) then you can put something in the middle as you describe. There’s no need to put it into a file, you can simply transform the XML body payload into a HTTP parameter/value (with appropriate URL encoding) and pass it straight through.

Same sort of URL you use to call an handler, but with an extra URL parameter in the end.

I could test this for you but not sure how to install.
I’m on ui5 by the way…

hi Mario23,

I am only on UI4, so do not know if it works on UI5 or even how to install it in UI5.

/anker

[quote=“guessed, post:74, topic:169644”]If the XML SOAP body cannot directly be processed (not proven yet) then you can put something in the middle as you describe. There’s no need to put it into a file, you can simply transform the XML body payload into a HTTP parameter/value (with appropriate URL encoding) and pass it straight through.

Same sort of URL you use to call an handler, but with an extra URL parameter in the end.[/quote]

@guessed:

Rethinking my work around I thought of the following:

Why not use vera itself for the ‘middle’ http server. It should be possible to do a script and place it in the web directory of vera (via ssh), or am I wrong? This script could be the callback url and should simply just call vera upnp wise with an action of a plugin with the data as parameter?

What do you think of this? Am I way off or does it sound okay? I cannot follow you on the XML SOAP body processing bit…

/anker

I can confirm all is working with my firmware version .1245
I can’t follow your work as I am not that kind of programmer but I was wondering if will be difficult to add the set volume command. The voulme up / down doesn’t give you the ability to take a scene…set the lights…lower the shades…and then start the music at a known value.
For what is worth, attached is the code I used to accomplish this in Labview.
The volume “value” was inserted between the header and footer.
Regards
Tim Alls

Thanks a lot Anker, Guessed and the others.
It works!!!

Not only UI4 but UI5 as well.
I tried few versions of luua files and this one works on Vera2 and Vera3.
Play, Stop, Mute, Mute(2nd), unMute, SkipDown, SkipUp, Pause, Down and Up (volume) functions work very well,
but FastForward, Rewind, Slow seems not working.

And I don’t understand the other commands ChapterUp, ChapterDown, DiskDown, DiskUp and GetTransportInfo.
What are they for?
How to use them?

I would like to make Sonos to play chosen audio file.
It would be nice when you leaving the house, to hear voice: “Window is open in the bathroom, please close it.”.
Anybody knows how to do it?

Hi all,

As your expertise on sonos, i would likw to ask you if can trigger a specific song in sonos?

I would to use it to play voice information, “welcome home”, “goodbye”…

Thank u guys
Matteo