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

    Lyricist III
    April 3, 2013
    Looking really good.....will try it out thnak you for sharing..

    Regards

    Robert
    jishiAuthor
    Headliner II
    April 4, 2013
    I managed to map one of my airmouse volume buttons to control a specific player with my raspberry pi without any problems.

    It read out the events on /dev/input/event0 (the keyboard) and maps the appropriate keycode to invoke the setVolume() method, this was with approx 20 lines of js.

    It works if run as a daemon as well, I started node.js from a ssh session and controlled it with a USB attached keyboard. Main problem is that the Airmouse operates in the 2.4 GHz span so it seems to drop about 5% of the keystrokes... it's a crappy china-keyboard as well, so that might explain it.
    Contributor I
    May 2, 2013
    Thanks and keep up the good work. I would love to see a quick how to of how to get this working with a RasPI.
    jishiAuthor
    Headliner II
    May 7, 2013
    Thanks and keep up the good work. I would love to see a quick how to of how to get this working with a RasPI.

    I'll try and write something up. Is it node.js installation and how to start a node app that you are interested in?
    jishiAuthor
    Headliner II
    July 2, 2013
    Glad it worked out for you. It's strange that you would need to npm install all libs separately. The package.json file is supposed to keep track of the dependencies for you, making a "npm install" invoke from the same folder to trigger a dependency-check and download stuff that is missing globally. That was my experience when I tested it out, will have to check it out again.

    Haven't had much time to work on it, but another guy has forked the project and is pushing minor improvements to it.

    Regarding running it as a service, it is doable but requires some manual setup. It's easier on linux afaik, but it's possible on Windows as well.
    jishiAuthor
    Headliner II
    September 13, 2013
    Okay, finally got some time to work in this and I got around to implement support for presets.

    A preset in this sense is a group of players with a predefined volume. This means that you can, by supplying a valid js object, send a signal to the players to group themselves, set the preferred volume and start playing whats in the queue.

    A preset looks like this:

    code:

    {
    "players": [
    { "roomName": "room1", "volume": 15},
    {"roomName": "room2", "volume": 25}
    ]
    }


    The first player in the group will be assigned to coordinator role.

    Next step will be to implement some playback options, like random, gapless, a favorite queue etc. It would also be of interest to keep track of which track it was actually playing last time, in order to resume where it left of.

    Check it out here: https://github.com/jishi/node-sonos-http-api
    jishiAuthor
    Headliner II
    September 30, 2013
    I made some improvements to the preset signals, previously it did spam a lot which confused the players and failed to add everyone to the group. I also identify if the coordinator already is a coordinator, and skips the BecomeCoordinatorOfStandaloneGroup call.

    It also support predefined presets, which you can store in a file, which gives you the ability to define something like an "all" preset, that you can apply by invoking:

    code:
    http://localhost:5005/preset/all
    jishiAuthor
    Headliner II
    October 1, 2013
    And today I read about this thing: http://tessel.io/
    jishiAuthor
    Headliner II
    October 12, 2013
    If anybody is interested, I did add support for replacing queue with one of your favorites.

    example:

    code:
    http://localhost:5005/TV Room/favorite/MyAwesomePlaylist


    Would replace the queue for the current group that TV Room is part of, with the favorite "MyAwesomePlaylist"

    I will eventually add support for this in the presets as well, which means that you can resume a specific grouping, with pre-defined volume set and a predefined favorite list.

    I will probably use this my self instead of the built in alarm, using the crontab daemon on the raspberry pi and do a 2-step wake-up call 🙂 slow music in the bedroom first 30 minutes, then all players in my apartment with some more up beat playlist.
    buzz
    Grand Maestro
    October 12, 2013
    And today I read about this thing: http://tessel.io/

    I'm well aware that clock speed is only part of the story, but at 180MHz I wonder if it is fast enough for large JavaScript programs.