-
Notifications
You must be signed in to change notification settings - Fork 77
Discovery
Sonos devices can be easily discovered using SSDP, part of the uPnP set of protocols.
Inspired by https://github.com/rahims/SoCo and https://github.com/turboladen/upnp, our library does a simple UDP multicast broadcast, then waits synchronously for a response. If nothing responds with a second, it errors.
There's another way to do discovery - the way that the Sonos client itself does it. The following code sort of works:
require 'socket'
require 'ipaddr'
require 'timeout'
socket = UDPSocket.open
socket.setsockopt(Socket::IPPROTO_IP, Socket::IP_MULTICAST_TTL, 2)
socket.bind('0.0.0.0', 6969)
loop do
message, info = socket.recvfrom(2048)
puts info[2] # the ip address
break
end
The catch: it requires you to be listening on UDP port 6969, and the Sonos desktop client does that by default. You'll have to shut it down for this to work.
To use, have that code running, then press the discovery buttons on your Sonos device. You should get the IP address almost immediately. I haven't figured out how to turn off the blinking discovery light. More to learn some other day.