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 24, 2013
    Thank you everyone for your feedback, I think I have resolved some of the radio problems now.

    Make sure that you are using v 0.7.5 of the sonos-discovery module, and try again.

    Regarding the notification.log and positioninfo.log, they are debuglogs that I have used, and will be removed when I feel like I don't need them anymore. You will have to live with them for a while longer 🙂
    Lyricist III
    November 25, 2013
    Looking very good ! Que seems to function well and the server sees no errors radio to local content and back 😉 will bang on it some more thank you...
    Trending Lyricist I
    November 25, 2013
    Confirmed here too....

    Both the rdio, and slacker streams are starting from the websonos favourites list.

    Memory use seems to be 35->45 meg here.... over extended runs of 24->48 hours.

    Just an FYI though.... I've seen this bug when forcing the sonos-discovery to reinstall after deleting the directory. No impact other then seeing it...

    code:

    node_modules# npm install sonos-discovery
    npm WARN package.json sonos-web-controller@0.5.4 No repository field.
    (next line is this)
    npm http GET https://registry.npmjs.org/sax
    (skipping some normal output)
    .....
    npm http 304 https://registry.npmjs.org/html-entities
    npm http 200 https://registry.npmjs.org/xml2js
    sonos-discovery@0.7.5 sonos-discovery
    ...
    └── sax@0.5.5


    Well done sir. This is definitely coming together....
    jishiAuthor
    Headliner II
    November 25, 2013

    npm WARN package.json sonos-web-controller@0.5.4 No repository field.
    (next line is this)


    Is it that one you are wondering about? Or the scrambled output from the sax install?
    Lyricist III
    November 25, 2013
    Just a Observation of the Index page not tablet friendly. Fav cannot be selected by touch group can not be moved etc. Aslo will you be updating the other lib to reflect the new que changes. Many thanks again...
    jishiAuthor
    Headliner II
    November 25, 2013
    Just a Observation of the Index page not tablet friendly. Fav cannot be selected by touch group can not be moved etc. Aslo will you be updating the other lib to reflect the new que changes. Many thanks again...

    I will not make this layout tablet friendly, mainly because the layout itself isn't tablet friendly, nor the controls. The plan is to implement alternate layouts for mobile and tablet (/m, /t) with different behaviors. Hopefully they can be a bit more user friendly than the current mobile apps (which I think is a pain to use). I have already made a custom /dashboard version: http://upload.grabbarna.se/files/IMG_20131125_105225.jpg which runs on one of the screens here at work. It took me about 30 minutes to complete, because all of the backend is already in place. Most of the time was just to implement client-side interaction with Spotify to get high resolution images of the tracks.

    And the queue changes doesn't affect the http-api atm. I'm not sure if a "seek" instruction should switch back to the queue and start playing it through a http API to be honest?
    Lyricist III
    November 25, 2013
    Bravo I agree and will await your plans......

    As per the http-api the fav radio function seems to be broken when asking for a fav the server sees the request but nothing happens not even errors even when i sens the /fav it comes back empty. PS both servers running in windows as long as you start http first then web it seems happy .......
    jishiAuthor
    Headliner II
    November 25, 2013
    Bravo I agree and will await your plans......

    As per the http-api the fav radio function seems to be broken when asking for a fav the server sees the request but nothing happens not even errors even when i sens the /fav it comes back empty. PS both servers running in windows as long as you start http first then web it seems happy .......


    Well, they both use the same component, "sonos-discovery" so when I updated it for the web controller, I also fixed the favorites for the http api. Just delete the sonos-discovery folder under node_modules and run npm install again, and restart it. I might have introduced some bugs iin the http-api with the recent updates, I haven't tested it at all personally, but just let me know if you find any troubles and I will try and fix them.
    jishiAuthor
    Headliner II
    November 25, 2013
    Seems like your preset is broken?

    It should look like this:

    code:

    {
    "all":{
    "players":[
    {
    "roomName":"Bathroom",
    "volume":10
    },
    {
    "roomName":"Kitchen",
    "volume":10
    },
    {
    "roomName":"Office",
    "volume":10
    },
    {
    "roomName":"Bedroom",
    "volume":10
    },
    {
    "roomName":"TV Room",
    "volume":15
    }
    ]
    }
    }
    jishiAuthor
    Headliner II
    November 25, 2013
    So I did a redesign of my TV dashboard template and created a video of it.

    http://www.youtube.com/watch?v=0x-Nhzd0ueg&feature=youtu.be

    It would be interesting to see how well it would look in a regular home consumer TV web browser, like samsung or whatever (or even a PS3/Xbox or similar).