NFC project - Raspi & SoCo

58 views
Skip to first unread message

John Crighton

unread,
May 17, 2019, 7:37:29 AM5/17/19
to SoCo - Sonos Controller
Hi, and firstly thanks to the community and creator of SoCo.

I'm trying to expand my knowledge in a few areas and really want to get to grips with Python, and get comfortable with Linux (I come from a Windows, VB and SQL background). I find it easiest to learn when I have an objective, so I've decided to try and make an NFC based interface for Sonos, mainly so that my (young) kids can choose and play music without my input, just like I did when I was their age.

The project might sound familiar, it's been done a few times, but with varying languages and technologies. I have the pi working with NFC, and have set up a MySQL db/table to hold playlist information. Next is SoCo.

I have SoCo installed ok, but I'm struggling with discovery. I have 2x Sonos 1s (currently in a stereo pair) and one Sonos Connect (not Amp). If I run:

import soco

for zone in soco.discover():
    print (zone.player_name)

I get nothing at all in return, which I believe indicates nothing's been found.

I checked the issues in github and confirm that the most recent fix for discovery is in place on my installation (only installed today from a git clone, so should be current).

I've tried tcpdump (my first time using this, wow!) and although it looks busy I can't see much that would indicate that SoCo is even looking for devices.

Any ideas would be very welcome.

Thanks in anticipation,

John.

DPH

unread,
May 18, 2019, 4:45:55 AM5/18/19
to SoCo - Sonos Controller
Hi John,
that should work - assuming your Pi and Sonos are on the same network, and network speed is ok.

I have just tried it and on the official code it doesn't work, but using a clone of the development on Github it does. 
There is a release in the works. 

If you go to the github page https://github.com/SoCo/SoCo and clone the repository then extract the soco folder and put it in the same directory as your script. 
Python will look in your script directory first then elsewhere. My guess is you are still running old code which started to fail when Sonos changed things with the latest release!

The other way to make it work is to name the Sonos unit by IP address:

import soco
zone
= soco.SoCo('192.168.1.25')
print(zone.player_name)

Hope this helps - ask more if it doesn't or you need more help
Cheers David

John Crighton

unread,
May 21, 2019, 5:23:23 AM5/21/19
to SoCo - Sonos Controller
Hi David,

Thanks for your post!

I pulled the latest version from git, just to keep things clean. Not many updates, as I'd only recently installed it.

Even if I run the code and specify the IP, I get a return of 'None'.

I can ping the IP of something on my network called 'SonosZP.lan' and get a decent response. I've attached a screenshot in case it helps.

I'm starting to think maybe I've missed something really simple. I've never tried anything like this, so it's entirely possible.

John.
Capture.JPG

DPH

unread,
May 21, 2019, 6:39:58 AM5/21/19
to SoCo - Sonos Controller
Hi John,
all your screenshots look good - as you say there must be something obvious missing!
It is always hard to track these down, and when you do it is really rewarding.

Can you try the following to prove what version of SoCo you are running. I see you pulled the latest v0.17 I am suspicious it is not what you are running.

import sys
print('Python version: ', sys.version)

import soco
print('SoCo version: ', soco.__version__)
print('Path used to load SoCo:', soco.__file__)

The locations python searches to load modules can cause confusion....if in doubt put it in the script directory as this is the first place python searches.
Are you running on Windows 10? 

We will make it work - keep persevering....
Cheers David

William Charles

unread,
May 21, 2019, 6:43:31 AM5/21/19
to DPH, SoCo - Sonos Controller
FYI I have had zero luck running Python and SoCo on Windows 10; either native or in the Linux environment. I installed Linux Mint on an external USB drive and booted off that, and everything started to work as expected...

Will.

--
You received this message because you are subscribed to the Google Groups "SoCo - Sonos Controller" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-soco...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-soco/373ec89f-00ad-44b6-991d-b854a7dc30d0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

DPH

unread,
May 21, 2019, 8:07:57 AM5/21/19
to SoCo - Sonos Controller
I code and test on Windows 10 and run "home operational" things on raspberry pi Linux.
Once set up all work fine, and the benefit of Python is it moves well between systems. 
Linux distros often have Python already installed, whereas Windows 10 you need to install Python - but there is lots of online help.

Cheers David
To unsubscribe from this group and stop receiving emails from it, send an email to python-soco+unsubscribe@googlegroups.com.

John Crighton

unread,
May 21, 2019, 8:40:42 AM5/21/19
to SoCo - Sonos Controller
Spot on... that suggests 0.16.

Will fix that and come back.

John Crighton

unread,
May 21, 2019, 8:49:09 AM5/21/19
to SoCo - Sonos Controller
David,

Fantastic, that worked!

So, I knew that there was a problem and had corrected the installation. I just wasn't running the script from the (correct) installation directory.

All of my Sonos kit now shows up. Now comes the fun part! Thanks so much.

As an aside, yes, I'm running Win 10 with a VNC to the Pi.

John.
Reply all
Reply to author
Forward
0 new messages