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

adding player to coordinator Bathroom with streamurl x-rincon:RINCON_00000000000000000


I added some entity encoding stuff to support the favorites, I guess there are some scenarios where this will pass null that I need to take into account.

However, that streamurl points to a device with no MAC-adress, which is kind of odd? It should never be all zeros like that.
Userlevel 2
For now it's on my home git repo but I'll upload it on my fork on github and send you the link.

I'm looking for the icons used for the music library browsing : back icons, Favorites and Music library icons. If you already have them that would help me otherwise I'll try to get them from the windows app too.

I've also looked to implement the "Radio" feature but haven't had the opportunity to do the packet captures to understand how the TuneIn implementation in Sonos works.

Regards
Userlevel 4
Badge +14

On my wish list:
- Queue management, add/remove/clear spotify tracks and/or playlists.
- Control shuffle/repeat/crossfade
- No autoplay when changing presets

My goal is to have a simple mobile GUI with some presets buttons;
Morning - Group all players, set volumes, start radio.
Evening - Group some players, set volumes, set shuffle, set repeat, set crossfade, replace queue with spotify playlist.
Party - Same as above but different playlist and maybe moving items in queue to play select item as next song.
Mute - Muting or changing volume in selected rooms.
Stop all - Stop all players with a single click (useful when leaving the home).

I've tried some of the unsupported APIs and this is the best so far, keep up the good job!


Control shuffle/repeat etc is next on my todo.
You can disable Auto-play on the preset by adding the following to your preset:

code:

{ "state": "stopped",
players:
[ { roomName: 'Bathroom', volume: 11 },
{ roomName: 'Kitchen', volume: 11 },
{ roomName: 'Master Bedroom', volume: 11 },
{ roomName: 'Living Room', volume: 10 } ] }


It's not part of my example, but should be.
Party mode is also an idea I've had for a long time. I started a .NET based app for it, but I never finished it. I will probably do a web-based version instead based on this API, that handles multiple clients (think, smartphone control).

You might want to check out the web controller-project that I started in your case, since the http-api is just a wrapper around sonos-discovery. If you plan on hosting a web client, you should probably skip that layer. https://github.com/jishi/node-sonos-web-controller

The web controller isn't working, but you might get the idea on how you can create and host the web client within node completely.

Oh, and finally, I did a commit to fix the null-check as well, but I'm not sure that it will resolve your issue completely. Let me know what kind of error you receive. Oh, I just struck me that you probably anonymized the streamurl, DOH! 🙂
Userlevel 4
Badge +14
For now it's on my home git repo but I'll upload it on my fork on github and send you the link.

I'm looking for the icons used for the music library browsing : back icons, Favorites and Music library icons. If you already have them that would help me otherwise I'll try to get them from the windows app too.

I've also looked to implement the "Radio" feature but haven't had the opportunity to do the packet captures to understand how the TuneIn implementation in Sonos works.

Regards


Let me know if you manage to extract them (I think I used Telerik JustDecompile http://www.telerik.com/products/decompiler.aspx), otherwise I can fix it easily.

I think TuneIn and most music services connect directly from the controller to the services without using the players, which makes it a bit more troublesome to implement. TuneIn doesn't have a free API and you need some credentials (I think) in order to get it to work.
Userlevel 2
Thanks, yes I removed my real Mac-address... ;)

Will continue my testing tonight. The Web-controller looks very cool but I think it might be a bit heavy weight for me. Just want to have a few predefined buttons that should trigger some custom actions like your new IR remote project.

Looks like I can get Morning, Mute and Stop All buttons running quite easily now.
Userlevel 2
Hello again,

You can check my changes on my github forks :
* https://github.com/gfraysse/node-sonos-discovery
* https://github.com/gfraysse/node-sonos-web-controller

Let me know if you feel it is of any interest it lacks some polishing but I'm still working on it.
I still need to get the missing icons and integrate them.
Userlevel 4
Badge +14
So, I spent the evening with coming up with a rather unique feature (haven't seen it yet anywhere else, enlighten me if I'm wrong!).

I call it "volume enforcement", which basically means that you can "lock" the volume for all your players, both up and down. This might be useful at a party, in an office environment, or just when you are going to sleep (if another family member decides to have a party in your house or something).

How it works? When you tell it to lock volumes, it will register the current volume for all players, and every time the volume changes, it will just send another volume adjustment to reset it back to whatever it was. This will of course not be rock solid, but might be useful never the less.

This is part of the http-api, since it needs some sort of trigger to function.

I might change it to only lock for increasing volume, since this effectively makes it impossible to mute a player with the buttons. If you have any feedback regarding that, please let me know.
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

Cheers!


Awesome Library! I've used it to create a tool that does store the listening positions of titles longer 10 minutes (configurable). And it restores the last known position when you start it again.

http://www.schrankmonster.de/2014/03/23/give-you-sonos-audiobook-podcast-auto-bookmarker-lose-listening-progress-again/

Of course everything also on Github: https://github.com/bietiekay/sonos-auto-bookmarker
Userlevel 2
Thanks for the new preset options - perfect!

But some problems with grouping speakers. If I have 3 speakers grouped (Bathroom, Kitchen, Master Bedroom) and would like to regroup two of them.

Sending the following
code:
{"players":[{"roomName":"Bathroom","volume":15},{"roomName":"MasterBedroom","volume":25}],"state":"stopped","uri":"x-sonosapi-stream:s47341?sid=254&flags=32"}


Server output
code:
{ action: 'preset',
value: '%7B%22players%22:[%7B%22roomName%22:%22Bathroom%22,%22volume%22:15%7D,%7B%22roomName%22:%22Master%20Bedroom%22,%22volume%22:25%7D],%22state%22:%22stopped%22,%22uri%22:%22x-sonosapi-stream:s47341?sid=254&flags=32%22}' }
applying preset { players:
[ { roomName: 'Bathroom', volume: 15 },
{ roomName: 'Master Bedroom', volume: 25 } ],
state: 'stopped',
uri: 'x-sonosapi-stream:s47341?sid=254&flags=32' }
applying preset { players:
[ { roomName: 'Bathroom', volume: 15 },
{ roomName: 'Master Bedroom', volume: 25 } ],
state: 'stopped',
uri: 'x-sonosapi-stream:s47341?sid=254&flags=32' }
skipping breakout because already coordinator
current volume 15
setting volume 15
current volume 25
setting volume 25
callback
STATUS: 200
volume success? true
Volume
STATUS: 200
Volume
STATUS: 500


The group still contains 3 speakers. However if ungrouping all speakers first and then send the command it works ok. It doesn't load the Radio from the URI command either.
Badge +2
...

Hi Jishi,

Thanks for your project and support you provide. Would it be possible to get an image for my Raspberry Pi from you. I'm not so used to compiling and more. An alternative would be a detailed installation guide. Is one or the other possible?

Best regards, Olly
Userlevel 4
Badge +14

The group still contains 3 speakers. However if ungrouping all speakers first and then send the command it works ok. It doesn't load the Radio from the URI command either.


Yeah, that's a glitch. If the first player already is a coordinator, I need to check which group members it has and detach the ones that shouldn't be part of it. Right now it just works with the players listed. It worked in an earlier version where I always detached the coordinator, but that became kind of choppy if you reapplied the same preset twice. I will fix it in the coming days.

uri is only useful for line-ins and hardcoded http-streaming urls. The x-sonosapi-stream urls require the DIDL metadata in order to be applicable. Next on the todo is to support favorites in presets as well, that should be a no brainer to solve.
Userlevel 4
Badge +14
Hi Jishi,

Thanks for your project and support you provide. Would it be possible to get an image for my Raspberry Pi from you. I'm not so used to compiling and more. An alternative would be a detailed installation guide. Is one or the other possible?

Best regards, Olly


I'm a little rusty on how to create an image but I can probably write up a step-by-step how-to on the raspberry installation, but I would need to redo it all from scratch to take note of all steps. If I manage to create a clean installation I may even be able to create an image for it, but in that case it would be preferable to have some sort of easy update feature as well.
Userlevel 2
Yeah, that's a glitch. If the first player already is a coordinator, I need to check which group members it has and detach the ones that shouldn't be part of it. Right now it just works with the players listed. It worked in an earlier version where I always detached the coordinator, but that became kind of choppy if you reapplied the same preset twice. I will fix it in the coming days.

uri is only useful for line-ins and hardcoded http-streaming urls. The x-sonosapi-stream urls require the DIDL metadata in order to be applicable. Next on the todo is to support favorites in presets as well, that should be a no brainer to solve.


Looking forward to play with the upcoming fixes!
Badge +2
I'm a little rusty on how to create an image but I can probably write up a step-by-step how-to on the raspberry installation, but I would need to redo it all from scratch to take note of all steps. If I manage to create a clean installation I may even be able to create an image for it, but in that case it would be preferable to have some sort of easy update feature as well.

That's great news. I was doing some little projects with the Raspberry in the past and I have to some extend experience with programming and computers, but not as much as you are talking about in this whole thread. So I'm a little worried, but I'll start soon. Still waiting for the IR receiver, case and some other accessories. Maybe I can help with the HTML/CSS UI support. My use case is your mentioned BigPicture-Support (what is playing now and next) and IR support (for basic navigation like Play/Stopp, Next, Previous, Favorite 10).
Userlevel 4
Badge +14
So, now it's possible to use favorites in your presets. It will replace the queue if it's a queue. If it's a radio, it will just start playing it and leave the queue intact.
Badge
I installed this app on a Raspberry Pi an it looks great! But now I'm trying to get it running on boot (with Forever) and there is one strange thing. When I navigate to the sonos folder first, it runs just fine:

cd /home/pi/sonos
node server.js


But when I run it from any other folder I only get a blank screen in the web browser:

node /home/pi/sonos/server.js


No error message. It seems to be running though...
Userlevel 4
Badge +14
Looking forward to play with the upcoming fixes!

Just pushed a commit where the issue with players not leaving the group is fixed. Enjoy.
Userlevel 4
Badge +14
I installed this app on a Raspberry Pi an it looks great! But now I'm trying to get it running on boot (with Forever) and there is one strange thing. When I navigate to the sonos folder first, it runs just fine:

cd /home/pi/sonos
node server.js


But when I run it from any other folder I only get a blank screen in the web browser:

node /home/pi/sonos/server.js


No error message. It seems to be running though...


Found the problem. I have pushed an update to the git-repo that fixes that.
Badge
Thank you for fixing that. Boots fine how.
In Firefox it works great. But in Safari (iMac, iPhone, iPad) I have several small issues. For example the queue is not scrollable on iMac. But on iPhone and iPad it is fully expanded but also not scrollable. The volume behaves strangely. When I change the volume, the group volume slider goes wild and sometimes the button even flies off the slider. Keep up the good work.
Userlevel 4
Badge +14
Seems like I had a bad fallback. I pushed a fix for it to sonos-discovery. Remove your node_modules folder and run npm install again.
Userlevel 4
Badge +14
As I have stated in the readme, I will never target Safari personally. Focus will be on cross-platform available browsers.

Webkit is also seriously broken when it comes to some newer css-techniques which makes it difficult to support for this.

It is also not intended for mobile devices, since it doesn't handle touch events. The plan is to create a touch-friendly layout instead (when I find the time).
Userlevel 2
Seems like I had a bad fallback. I pushed a fix for it to sonos-discovery. Remove your node_modules folder and run npm install again.

Much better, thanks!
Userlevel 4
Badge +14
I just ordered a CuBox-i2 from http://cubox-i.com/

It has a really nice form factor, with built-in IR-receiver. I ordered the i2 because I am going to run Plex on it, but for only controlling Sonos via IR, hosting the http api and run the web-controller the i1 would probably be more than enough.

Maybe I can even make a pre-made image with everything needed 😃
Userlevel 4
Badge +14
I have added support for:

groupVolume
groupMute
mute (single player)
repeat
shuffle

I rewrote the previous groupmute/volume implementation and because of that, the calls for volume and mute are now different (this doesn't concern the http-api, only sonos-discovery).

enjoy.
I remember my first single board computer. It was ground breaking at the time with a four character seven segment display, a numeric keypad, and was about the size of the larger iPads. I paid several times the cost of CuBox.