node-sonos icon indicating copy to clipboard operation
node-sonos copied to clipboard

Stuck Searching for Sonos devices on network...

Open ktec opened this issue 11 years ago • 41 comments

So I started by trying to use the airsonos app, but it just gets stuck at

Searching for Sonos devices on network...

I've documented it more closely here https://github.com/stephen/airsonos/issues/135 I've not had any success finding anyone who can help guide me through debugging but it was suggested that someone here may know enough to help.

To summarise, I've got these installed:

sudo n 0.10.36
sudo npm install -g airsonos
sudo n 0.12.0
n use 0.10.36 /usr/local/bin/airsonos

Airsonos project uses this projects sonos.LogicalDevice.search feature to locate devices on the network, and its this bit thats not working for me. I really don't know anything about node.js so I'm poking around in the dark here, but so far I've:

  • ensured that I'm not running a firewall
  • i have great connection with the sonos device
  • the sonos app can actually find and control the device

I'm not sure what to do to make any progress with this, but I'm really keen to be able to send music to my Sonos speaker without using the main app. I've just installed node-inspector and I'm trying to debug and step through the code but I'm really not sure what I'm looking for.

Any help would be great thanks...

ktec avatar Mar 26 '15 22:03 ktec

Thanks for the report @ktec.

What Sonos devices have you got on your network that you're trying to find?

bencevans avatar Mar 27 '15 14:03 bencevans

Hi Ben, its the PLAY:1

I was debugging through the code for hours last night but I'm no good at javascript debugging so i didn't really get anywhere....was only able to stop the code before it defined the Search() class, but I couldn't get it to stop inside the searching call

ktec avatar Mar 27 '15 14:03 ktec

Same issue, I have a Soundbar and a PLAY:1

jweinstein avatar Mar 29 '15 23:03 jweinstein

Mmmh, I have 2x PLAY:1 and 1x Sub and no problem to discover them (in less than 2 seconds).

Where do you run the script. Is it a physical machine, has it multiple network adapters, is it a virtual machine and is bridged networking active?

HarlekinX avatar Mar 30 '15 10:03 HarlekinX

Regular Mac OS X machine on the same network. Nothing fancy. :(

jweinstein avatar Mar 30 '15 17:03 jweinstein

Me too, regular mac book air, nothing fancy, and the Sonos app seems to locate the device without trouble. Can you suggest how/where I can drop debug in to actually step through the discovery thing and I can probably help resolve this.

On 30 March 2015 at 18:31, Jeff Weinstein [email protected] wrote:

Regular Mac OS X machine on the same network. Nothing fancy. :(

— Reply to this email directly or view it on GitHub https://github.com/bencevans/node-sonos/issues/73#issuecomment-87762973.

[email protected]

ktec avatar Mar 30 '15 17:03 ktec

@ktec @jweinstein: are you both using the airsonos module?

I'm able to discover devices on a linux box running [email protected] and the node-sonos@master

Best way to debug this is to use Wireshark and check the broadcast packet is actually being sent and whether any Sonos devices are sending anything back.

bencevans avatar Mar 31 '15 00:03 bencevans

Would it be possible to set up a time to screen share with you to walk through that?

On Mon, Mar 30, 2015 at 5:51 PM, Ben Evans [email protected] wrote:

@ktec https://github.com/ktec @jweinstein https://github.com/jweinstein: are you both using the airsonos module?

I'm able to discover devices on a linux box running [email protected] and the node-sonos@master

Best way to debug this is to use Wireshark and check the broadcast packet is actually being sent and whether any Sonos devices are sending anything back.

— Reply to this email directly or view it on GitHub https://github.com/bencevans/node-sonos/issues/73#issuecomment-87889384.

jweinstein avatar Mar 31 '15 00:03 jweinstein

Hey Ben, Yup I'm using the airsonos module, I'll give it a whirl with wire shark, you wouldn't happen to have a packet filter that will help zero in on the relevant packets?

On Tuesday, March 31, 2015, Ben Evans [email protected] wrote:

@ktec https://github.com/ktec @jweinstein https://github.com/jweinstein: are you both using the airsonos module?

I'm able to discover devices on a linux box running [email protected] and the node-sonos@master

Best way to debug this is to use Wireshark and check the broadcast packet is actually being sent and whether any Sonos devices are sending anything back.

— Reply to this email directly or view it on GitHub https://github.com/bencevans/node-sonos/issues/73#issuecomment-87889384.

[email protected]

ktec avatar Mar 31 '15 00:03 ktec

I'm afraid it's a busy week, ping me Friday and I might be able to help.

Else If you're able to do a packet capture in Wireshark and send it to me (assuming you're comfortable sharing your net packets!) and run maybe with screen recording the node-sonos program/code.

bencevans avatar Mar 31 '15 01:03 bencevans

@ktec Cheers! I'll see what I can come up with...

bencevans avatar Mar 31 '15 01:03 bencevans

@ktec just http should get rid of the noise so long as you haven't got loads of other requests being made by fb etc.

bencevans avatar Mar 31 '15 01:03 bencevans

Thanks mate I'll do a snoop and let you know what I come up with

On Tuesday, March 31, 2015, Ben Evans [email protected] wrote:

@ktec https://github.com/ktec just http should get rid of the noise so long as you haven't got loads of other requests being made by fb etc.

— Reply to this email directly or view it on GitHub https://github.com/bencevans/node-sonos/issues/73#issuecomment-87891107.

[email protected]

ktec avatar Mar 31 '15 01:03 ktec

@ktec Ta

bencevans avatar Mar 31 '15 01:03 bencevans

I hit the exact same issue today and I have a workaround/fix. It would need someone with more knowledge of how it all works to figure out why it works in some environments and not in others. My basic understanding is that the default broadcast that is used to search for Sonos devices fails. I have a theory that it might be due to the broadcast address being invalid.

Anyway if you located the following in the sonos.js file:

this.socket.bind(function() { _this.socket.setBroadcast(true); _this.socket.send(PLAYER_SEARCH, 0, PLAYER_SEARCH.length, 1900, '239.255.255.250'); });

and replace it with the broadcast address for your network, in my case it was 192.168.0.255, therefore it looks like:

this.socket.bind(function() { _this.socket.setBroadcast(true); _this.socket.send(PLAYER_SEARCH, 0, PLAYER_SEARCH.length, 1900, "192.168.0.255"); });

This should allow you to discover the devices automatically on the network segment.

hypascend avatar Jun 02 '15 16:06 hypascend

Sorry I didn't finish up with this, I went off on holiday and my laptop died. Thanks for Sharing your solution @hypascend I'll give it a try when I get my laptop back.

ktec avatar Jun 02 '15 19:06 ktec

Works perfectly, thanks for sharing :bow:

ktec avatar Jun 02 '15 20:06 ktec

You are welcome. :)

hypascend avatar Jun 02 '15 21:06 hypascend

Thanks for sharing! I'm not sure why we broadcast on that address to be honest. It was probably just what the Sonos Controller was doing back when this was written.

Maybe we could broadcast on both. On 2 Jun 2015 10:42 pm, "hypascend" [email protected] wrote:

You are welcome. :)

— Reply to this email directly or view it on GitHub https://github.com/bencevans/node-sonos/issues/73#issuecomment-108107330 .

bencevans avatar Jun 03 '15 18:06 bencevans

239.255.255.250 is the Simple Service Discovery (SSDP) multicast address. I suppose the question is, why are we trying to broadcast to a multicast address and is it setting up the socket correctly to do it. I think it might be worth doing some analysis on the setup of the broadcast socket.

It could be that some networks/OS don't allow a broadcast to a multicast address and that is why we are seeing it only affect some people. I think your idea works, to cover both scenarios, but maybe we don't need the SSDP part anymore?

If I get time I will do some packet analysis on when it does the current broadcast compared to the subnet specific broadcast.

hypascend avatar Jun 03 '15 21:06 hypascend