Sonos with node.js, my attempt!



Show first post
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.

397 replies

Userlevel 4
Badge +14
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
Userlevel 4
Badge +14
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.
Userlevel 4
Badge +14
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?
Userlevel 2
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.
Userlevel 4
Badge +14
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.
Userlevel 2
Looking really good.....will try it out thnak you for sharing..

Regards

Robert
Userlevel 4
Badge +14
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.
Userlevel 4
Badge +14
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...
Userlevel 4
Badge +14
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.
Userlevel 4
Badge +14
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!
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.
Userlevel 4
Badge +14
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.
Badge


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.
Userlevel 4
Badge +14

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.
Userlevel 2
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!
Userlevel 4
Badge +14
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.