Skip to main content
Headliner II
March 5, 2013

Sonos with node.js, my attempt!

INFO

Source code here: https://github.com/jishi/node-sonos-http-api
Sonos Web Controller draft (work in progress!): https://github.com/jishi/node-sonos-web-controller
Sonos IR control (requires lircd and IR reciever): https://github.com/jishi/node-sonos-remote-control

==============================================================


I know that there already is an attempt at this by this guy: http://forums.sonos.com/showthread.php?t=32643, but I found it to be a bit lacking in functionality so I decided to write up my own.

I have created a simple web-based API using what I have, which could be useful for integrating stuff with other applications. This web based API is inspired by other RESTful APIs, however I don't think it follows the correct guidelines to be called a REST API.

IT supports most basic features like:

play, pause, seek, next, prev, volume, mute, setAVTransportURI

It also supports these advanced fatures:

State of player as JSON, zone info as JSON, Play favorite item, presets (grouping, volume, avTransportURI)

You can read more in the README for each project.

To run it as a service under linux, I suggest using pm2 (https://github.com/Unitech/pm2). You need to run it in forked mode (-x)!

For Windows, you might try Winser http://jfromaniello.github.io/winser/

Cheers!
    This topic has been closed for further comments. You can use the search bar to find a similar topic, or create a new one by clicking Create Topic at the top of the page.

    391 replies

    jishiAuthor
    Headliner II
    November 21, 2013
    Multiple nodes on one machine can you run both versions of your server on the same windows pc any I trying the web based and the html they seems to hang during init if one is running and thoughts? Is it better to run a Linux box and then run both servers? If so what flavor of Linux would be best?

    Many thanks and what a great project ........super job!


    Do you mean that you want to run both the http-api and the web-controller on the same machine? Unfortunately at the moment, the use a fixed port for notifications, which means that they don't start. You can combine them though, if you want, and use the same underlying sonos-discovery, which would save memory, but that's a bit of a hack at the moment.

    I might add some autodiscovery for the listening port to make it less error prone.
    Lyricist III
    November 21, 2013
    Yes it would be very cool to have both running as I am trying to integrate it with my home automation system and both are just what I have been looking for .......:D Thank You
    jishiAuthor
    Headliner II
    November 21, 2013
    I changed the port behavior for discovery and notifcations to support multiple instances, which means that:

    for ssdp it will randomize a port between 1902 and 2702 (it was impossible in node to identify occupied ports). For notification it will try and bind to port 3500 (like the android client), but if that one is taken it will try 3501, 3502 etc. This is usually not a problem for you, unless you have a segmented network and need to handle firewall rules.

    I also added support for settings.json for sonos-web-controller, to let you configure listening port (for web GUI) and cache dir without changing the source. That way it will live through an update.

    I have also verified that this runs on the raspberry pi. It has to work for it a bit, but it's not overwhelming.
    Contributor I
    November 22, 2013
    Unfortunately with the latest update, the empty queue error has returned.
    Lyricist III
    November 22, 2013
    Favorites in the html server....

    Does it support radio Fav Like Pandora etc or am I doing something wrong?

    Ordered a raspberry pi to run this very cool it really will make a amazing package for sonos integration.

    Thank You Robert
    jishiAuthor
    Headliner II
    November 22, 2013
    Okay, I added some checks when trying to parse the XML, seems like it act up occasionally, I don't know why yet.

    And seems like I had forgotten to commit the empty queue fixes, my bad. They should be up in the git repo now. Make sure that you are using v 0.7.4 of the sonos-discovery module (check packages.json in the module folder), if not, delete it and run npm install again.
    jishiAuthor
    Headliner II
    November 22, 2013
    Does it support radio Fav Like Pandora etc or am I doing something wrong?

    Ordered a raspberry pi to run this very cool it really will make a amazing package for sonos integration.


    Hi, it is supposed to support Pandora, however I have no way of testing it (we don't have pandora here in Sweden). If you are using the http-api, you could send me the /favorites output so that I can see what the pandora items looks like.

    Regarding the raspberry, I tested it with the B version (the one with 512 MB RAM and ethernet). I suggest you buy that one, at least for the ethernet port (you can just jack it into any ZonePlayer).
    Contributor I
    November 22, 2013
    How nice would it be if this code (once completed) ultimately resided in the Sonos bridge or one of the players themselves. A fully native web based controller that would be good. No issues of operating systems, client apps, etc..

    Just a thought.
    jishiAuthor
    Headliner II
    November 22, 2013
    How nice would it be if this code (once completed) ultimately resided in the Sonos bridge or one of the players themselves. A fully native web based controller that would be good. No issues of operating systems, client apps, etc..

    Just a thought.


    I don't see that happening though, I'm afraid. I saw that someone suggested this over at ask.sonos.com, https://ask.sonos.com/sonos/topics/bridge_web_server_to_control_the_system_extend_the_memory_limit

    But in my experience, this is not something that would benefit the majority of the users, which means that it isn't likely to be produced.

    Either way, a raspberry pi is very inexpensive (even cheaper than a bridge), and it would even be possible to make a preinstalled image for it (with node and stuff already installed), to flash on an SD-card. And if I had a 3D printer I would build a small Sonos-like casing for it as well 🙂
    jishiAuthor
    Headliner II
    November 22, 2013
    If you have a player that is currently playing a queue, and you start playing that pandora radio, will the queue remain on that player and say (not in use)?