Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NotASonosDevice #135

Open
toddmo opened this issue Sep 24, 2022 · 13 comments
Open

NotASonosDevice #135

toddmo opened this issue Sep 24, 2022 · 13 comments

Comments

@toddmo
Copy link

toddmo commented Sep 24, 2022

I made progress in getting my sonos-web server to start, by installing with docker.

I successfully pulled the docker image and ran it, but I got the error:

toddmo@machine:~$ sudo docker run sonosweb/sonos-web

sonos-web@1.0.0 start
node src/server.js

Server listening on port 5050
/sonos-web/server/src/sonos/MusicLibrary.js:14
if (!this.sonos) { throw new Error(NotASonosDevice); }
^

Error: Not A Sonos Device
at new MusicLibrary (/sonos-web/server/src/sonos/MusicLibrary.js:14:30)
at /sonos-web/server/src/sonos/SonosNetwork.js:51:29
at processTicksAndRejections (node:internal/process/task_queues:96:5)

My Sonos is a version 1 and I am currently using the Sonos S1 android app to control it. I'm also controlling it via the Sonos API, so I can't see any reason why this or any other library would not be compatible with Sonos S1 devices. Hopefully it's an issue not related to the hardware version, and which can be fixed.

@stufisher
Copy link
Contributor

stufisher commented Sep 25, 2022

Did you run the container with --net=host (this should be added to the docs) ? Sonos works over broadcast so needs access to the hosts network

@toddmo
Copy link
Author

toddmo commented Sep 25, 2022

Am I doing something wrong with my commands?

toddmo@machinename:~$ sudo docker network ls
NETWORK ID NAME DRIVER SCOPE
abc123 bridge bridge local
def456 host host local
ghi789 none null local

toddmo@machinename:~$ sudo docker run --net=host sonosweb/sonos-web

sonos-web@1.0.0 start
node src/server.js

Server listening on port 5050
/sonos-web/server/src/sonos/MusicLibrary.js:14
if (!this.sonos) { throw new Error(NotASonosDevice); }
^

Error: Not A Sonos Device
at new MusicLibrary (/sonos-web/server/src/sonos/MusicLibrary.js:14:30)
at /sonos-web/server/src/sonos/SonosNetwork.js:51:29
at processTicksAndRejections (node:internal/process/task_queues:96:5)

@ghost
Copy link

ghost commented Oct 11, 2022

Same on my system (Linux):

$ docker run --net=host sonosweb/sonos-web

> sonos-web@1.0.0 start
> node src/server.js

Server listening on port 5050
/sonos-web/server/src/sonos/MusicLibrary.js:14
    if (!this.sonos) { throw new Error(NotASonosDevice); }
                             ^

Error: Not A Sonos Device
    at new MusicLibrary (/sonos-web/server/src/sonos/MusicLibrary.js:14:30)
    at /sonos-web/server/src/sonos/SonosNetwork.js:51:29
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
npm notice 
npm notice New minor version of npm available! 8.15.0 -> 8.19.2
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.19.2>
npm notice Run `npm install -g npm@8.19.2` to update!
npm notice 

@stufisher
Copy link
Contributor

Hmm, all looks ok in terms of starting the container. Are you both using S1 hardware? I've only got S2 compatible gear here.

@edekeijzer
Copy link

Same error here, started with --net=host, using a Beam soundbar and a Roam SL and some Ikea hardware.

@toddmo
Copy link
Author

toddmo commented Oct 25, 2022

I would like to add 2 pieces of information:

  1. I call the Sonos API successfully from my application every day. I created an application on Sonos Developer and I use it to control my Sonos S1 system from Macrodroid with https api calls.
  2. In my browser, which is Brave, the browser extension "Cast to Sonos" works fine, although they intentionally made it laggy on the free tier. This means that my Sonos S1 is hittable via JavaScript, because that's the language of browser extensions. It also means the streaming api point is working against my device.

These two pieces of information indicate to me the issue lies with your code somewhere, not gen 1 devices. Thanks.

If you want to call a bunch of Sonos API from a web page, you need to first go through the OAuth process so I can auth your app to my Sonos household. But I was never prompted. Could that be the issue? At a min, I recommend beefing up this error message. It seems like you're trying to get about this another way. You're trying to connect to my Sonos device over the LAN instead of just controlling it via the API, which we know works fine.

@edekeijzer
Copy link

I would like to add 2 pieces of information:

  1. I call the Sonos API successfully from my application every day. I created an application on Sonos Developer and I use it to control my Sonos S1 system from Macrodroid with https api calls.
  2. In my browser, which is Brave, the browser extension "Cast to Sonos" works fine, although they intentionally made it laggy on the free tier. This means that my Sonos S1 is hittable via JavaScript, because that's the language of browser extensions. It also means the streaming api point is working against my device.

These two pieces of information indicate to me the issue lies with your code somewhere, not gen 1 devices. Thanks.

If you want to call a bunch of Sonos API from a web page, you need to first go through the OAuth process so I can auth your app to my Sonos household. But I was never prompted. Could that be the issue? At a min, I recommend beefing up this error message. It seems like you're trying to get about this another way. You're trying to connect to my Sonos device over the LAN instead of just controlling it via the API, which we know works fine.

There seem to be two ways to communicate with Sonos devices, either through their API or directly by IP address. As the sonos-web application needs host networking, it will most likely detect the Sonos devices through network broadcasting and not use the API. That's why you did not have to authorize anything in an oauth flow.
However, I have tried using a Python library (SoCo) which can also scan for Sonos devices and that worked like a charm with host networking.

@edwaa
Copy link

edwaa commented Nov 20, 2022

Same issue on my system (Linux):

[root@system docker]# docker run --net=host sonosweb/sonos-web

> sonos-web@1.0.0 start
> node src/server.js

Server listening on port 5050
/sonos-web/server/src/sonos/MusicLibrary.js:14
    if (!this.sonos) { throw new Error(NotASonosDevice); }
                             ^

Error: Not A Sonos Device
    at new MusicLibrary (/sonos-web/server/src/sonos/MusicLibrary.js:14:30)
    at /sonos-web/server/src/sonos/SonosNetwork.js:51:29
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
npm notice
npm notice New major version of npm available! 8.15.0 -> 9.1.2
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v9.1.2>
npm notice Run `npm install -g npm@9.1.2` to update!
npm notice

@edekeijzer
Copy link

Very strange, I have installed Docker on my Debian laptop and tried running the image.. On there, it works. The laptop is in only one network (same as the Sonos devices), while my server is in three different VLANs.

@stufisher
Copy link
Contributor

stufisher commented Nov 22, 2022

Interesting, i wonder if we need a way to specify the interface the api is binding to. Does everyone else have multiple network interfaces?

Internally sonos-web uses https://github.com/bencevans/node-sonos to connect locally to the sonos system (cloud is not used).

Related info:
https://github.com/bencevans/node-sonos/blob/master/lib/deviceDiscovery.js#L40
https://nodejs.org/api/dgram.html#socketbindoptions-callback
https://stackoverflow.com/questions/63887856/nodejs-dgram-udp-socket-listen-on-specific-interface

@nvansluis
Copy link

I got the same error here. It turned out to be firewall running on the same host. After disabling the firewall (systemctl stop firewalld) it started to work.

@toddmo
Copy link
Author

toddmo commented Jan 14, 2023

@nvansluis,
Thanks for your research

PORT=5051
--
2 | CLIENT_PORT=5050

As an experiment, can you try re-enabling your firewall but opening these two ports which are used by this application?

systemctl start firewalld
firewall-cmd --zone=public --add-port=5050/tcp
firewall-cmd --zone=public --add-port=5051/tcp

More Information

If this works, maybe we should work on a PR to make the error message tell exactly what's going on.

@meironke
Copy link

@toddmo & @nvansluis & @stufisher - thanks for your research an posts.

I think I have an firewall issue. Have SONOS Web up and running with docker-compose on Ubuntu, as long as my firewall is disabled.

My question: Which ports need to be opend to have SONOS Web woking?

My Docker Compose file is:

  sonosweb:
    image: sonosweb/sonos-web:latest
    container_name: sonos_web
    hostname: sonos_web
    restart: always
    network_mode: host
    ports:
      - "5050:5050"
      - "5051:5051"

Enabling the firewall results in this error:

/sonos-web/server/src/sonos/MusicLibrary.js:14
    if (!this.sonos) { throw new Error(NotASonosDevice); }
                             ^
Error: Not A Sonos Device
    at new MusicLibrary (/sonos-web/server/src/sonos/MusicLibrary.js:14:30)
    at /sonos-web/server/src/sonos/SonosNetwork.js:51:29
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

My Ubuntu machine has firewall ports 5050 and 5051 opened:

5050/tcp                   ALLOW       Anywhere
5051/tcp                   ALLOW       Anywhere

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants