I am new to smartapps and still learning the platform, but I am writing a smartapp to work with a Sonos and I am trying to communicate with it using a HubSoapAction. I am trying to get a list of the sonos favorites from the sonos by querying the contentDirectory which I have done for other apps.

def doCall(evt){
	log.debug "doCall"
	def hubAction = sonosFavorites()
   	def end = sendHubCommand(hubAction)
        log.trace "hello $end"
private sonosFavorites() {
	log.trace "sonosFavorites()"
	def hubaction = new physicalgraph.device.HubSoapAction(
	path:    "/MediaServer/ContentDirectory/Control",
	urn:     'urn:schemas-upnp-org:service:ContentDirectory:1',
	action:  "Browse",
	body:    ["ObjectID":"FV:2","BrowseFlag":"BrowseDirectChildren","StartingIndex":"0","RequestedCount":"100"],
	headers: [Host:"", CONNECTION: "close"])

The preceding code will always result in a soap fault. I believe this is because the sendHubCommand is putting the xml declaration in the soap message and the sonos doesn’t like it. Is there a way to not include the declaration?

Also, how do I get a hold of the return of the request to parse through the favorites list?

Below is the raw Request

POST /MediaServer/ContentDirectory/Control HTTP/1.1
Accept: */*
User-Agent: Linux UPnP/1.0 SmartThings
SOAPAction: "urn:schemas-upnp-org:service:ContentDirectory:1#Browse"
Content-Type: text/xml; charset="utf-8"
Content-Length: 410

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="" s:encodingStyle=""><s:Body><u:Browse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1"><ObjectID>FV:2</ObjectID><BrowseFlag>BrowseDirectChildren</BrowseFlag><StartingIndex>0</StartingIndex><RequestedCount>100</RequestedCount></u:Browse></s:Body></s:Envelope>

which results in

HTTP/1.1 500 Internal Server Error
CONTENT-TYPE: text/xml; charset="utf-8"
Server: Linux UPnP/1.0 Sonos/27.2-80271 (ZPS3)
Connection: close

<s:Envelope xmlns:s="" s:encodingStyle=""><s:Body><s:Fault><faultcode>s:Client</faultcode><faultstring>UPnPError</faultstring><detail><UPnPError xmlns="urn:schemas-upnp-org:control-1-0"><errorCode>402</errorCode></UPnPError></detail></s:Fault></s:Body></s:Envelope>

Any help would be appreciated.

Thank you in advance,

Never-mind folks, the xml declaration is fine. I was missing another parameter. Sorry :blush:

But the other question still stands. Sonos is now returning me my favorites list… But, how do I get a hold of the response in the smartapp? Documentation is so very sparse for this command.

I would suggest looking at locationHandler() code in the Sonos (Connect) SmartApp example available from the IDE. You register it with [filterEvents:false] so you get everything it can get, but you need to make sure that the responses are what you are expecting as you will get responses being sent to other SmartApps as well.

1 Like

thanks swanny. I got it. Man, neither Sonos nor ST made this a particularly easy task.

Just so I can learn, Is the only way to do this with an async callback? Is it possible to do synchronously? Can I just manually hacked up an httpPost and stuffed the whole soap envelope in the body?

Also, do you know why logging seems so painful? Many times if I try to log something coming back from ST, it wont output anything in the entire block of groovy. Is this because of the sandbox?

I believe you can do synchronous calls to the web/cloud but not on the local network (currently). I haven’t done much on the cloud front yet, so I’m not sure what’s possible there.

Logging seems to be limited in size and that is often the cause of text not appearing. There was some discussion about that in the last developer discussion video. They are looking to change it, so at least you get a truncated log instead of nothing. It’s especially painful if you are trying to log out text you receiving from an external source. You can manually output only a part of it to help get past what you are seeing. There are also some other cases where logging works funny, but I’m guessing this may be the one you were running into.

1 Like

I recognize this is an old topic, but I’m having the exact same problem. I’m trying to retrieve and enable/disable the alarms in Sonos. Can you help me with how you figured out what parameters were missing? The http 500/upnp 402 error is pretty non-specific and unhelpful. Based on packet traces, I’m stumped, the manufactured request and the client request look nearly identical.