Skip to main content
Headliner II
Mar 5, 2013 10:27 PM UTC

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
    Mar 7, 2013 10:42 PM UTC
    Thought there would be more interest in something like this.

    However, following up myself:

    I bought a raspberry pi primarily to test this out, and it was even easier than expected, to get this running. Installed a precompiled version of Node 0.8.16 on the default raspbian image and everything works as expected.

    Also implemented the following:

    +/-volume support
    seek
    next/previous

    I'm guessing it would be possible to utilize some sort of button board to get physical buttons to control your Sonos (I'm thinking presets), but even some sort of wireless keyboard could be useful.
    Translate
    Contributor III
    Mar 8, 2013 6:13 AM UTC
    A lot of us will definitely be interested in your progressions on this project, but (like me) they are probably just waiting to see what happens.

    Maybe if you release/reveal the code you allready have, and some quick instructions of how to use it, you will probably get more response.

    Don't know if this is part of your plans, but what I would like to see is a good looking web based controller that can run on an IIS server. (An alternative to the old perl-based controller)

    Good luck with this project and keep up the good work!
    Translate
    jishiAuthor
    Headliner II
    Mar 8, 2013 9:35 AM UTC

    Don't know if this is part of your plans, but what I would like to see is a good looking web based controller that can run on an IIS server. (An alternative to the old perl-based controller)

    Good luck with this project and keep up the good work!


    Thank you for your reply, it helps knowing that there is a demand to keep the spirit up :)

    Yes, the next step is to try and reproduce a simple html5 controller based on websockets (with socket.io) to get a more native look and feel. I have never seen the perl-based controller though. Since node doesn't interact with IIS as far as I know, this will not be hosted on IIS. However, node has built-in support for http, so there is no need for this, and this would be platform agnostic.

    The tough nut to crack as I see it is the music and queue management. I have no insight on how the music browsing works, since I exlusively rely on spotify myself.

    I will add my progress so far to my github as soon as I figure out the smartest way to handle topology events and how to structure the npm, hopefully this weekend.
    Translate
    Trending Lyricist I
    Mar 8, 2013 11:52 AM UTC


    Yes, the next step is to try and reproduce a simple html5 controller based on websockets (with socket.io) to get a more native look and feel. I have never seen the perl-based controller though.

    The tough nut to crack as I see it is the music and queue management. I have no insight on how the music browsing works, since I exlusively rely on spotify myself.



    Sonospy has an optional HTML GUI front end (using jQuery and Javascript) that supports browsing - you ought to be able to work out how browsing works from that.
    Translate
    jishiAuthor
    Headliner II
    Mar 8, 2013 12:03 PM UTC
    Sonospy has an optional HTML GUI front end (using jQuery and Javascript) that supports browsing - you ought to be able to work out how browsing works from that.

    Good tip. However, the main problem for me is that I have no indexed music om my system, so I have no way of inspecting the actual traffic.
    Translate
    buzz
    Grand Maestro
    Mar 8, 2013 7:11 PM UTC
    jishi,

    SONOS allows up to 16 shares, you could create a small share on the computer for testing purposes. I keep a few small folders for such purposes. And, there is a large folder that can be expanded if I ever need to test beyond the 65000 limit. The metadata is distinct even though the track contents might not be distinct.
    Translate
    jishiAuthor
    Headliner II
    Mar 17, 2013 10:12 PM UTC
    Okay, here is the first draft.

    https://github.com/jishi/node-sonos-http-api

    if you don't want to muck around with git, I have a zip-file which you can use:

    http://upload.grabbarna.se/files/sonos-http-api.zip

    unzip it to a folder, then just invoke from a command prompt or powershell or bash or whatever while standing in the folder:

    code:

    node server.js


    I don't handle topology yet, had some issues with timing and haven't had time to look into it.

    I have only tested it in node 0.8.16, should work fine in 0.8.x but unsure about earlier versions. It works on a raspberry pi, and should be okay on any nodejs supported platform.

    Feedback is welcome, forking and patches as well.

    Have fun!
    Translate
    jishiAuthor
    Headliner II
    Mar 23, 2013 2:46 PM UTC
    Here is an update.

    I have managed to implement the topology stuff now as well, which basically means that you are able to send commands to any player, and it will control the coordinator instead.

    This means that if:

    Kitchen and Office is grouped, command to either player will control them both (except for volume). This is probably much more handy.

    Posted a pre-zipped package here:

    http://upload.grabbarna.se/files/sonos-http-api-v2.zip

    And also pushed the latest version to github.
    Translate
    jishiAuthor
    Headliner II
    Mar 25, 2013 10:16 PM UTC
    For those interested in the progress:

    http://upload.grabbarna.se/files/sonos-web-controller-draft-3.png

    Man, does it takes forever to replicate the GUI in HTML...
    Translate
    jishiAuthor
    Headliner II
    Mar 28, 2013 1:39 PM UTC
    Finally pushed the web controller to a public repository:

    https://github.com/jishi/node-sonos-web-controller

    Nothing is actually working (except for zone discovery), but if you want to try it out to get a feeling on how it will behave in the browser, please feel free to do so. You will also be able to follow my commit logs :)

    If you want to help out, give me a shout. The main reason for me doing this, is because I want to expose a working controller for all my co-workers. Being behind firewalls and on different nets, it would simplify it a lot if I could just expose a web-based controller for everyone to use. It could also be useful for controlling a system remotely.
    Translate