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 2
jishi,

The group volume worked great and I thought the presets was working fine but now I see that it will only group on a fresh start of sonos-remote.

For example:
-Group the speakers via IR key
-Ungroup speakers via the Sonos app
-Attempt to regroup the speakers via IR key; it does not succeed (#1)
-Kill sonos-remote and restart sonos-remote
-Attemp to group via IR key and it does regroup. (#2)

#1:
00 KEY_POWER
before action true
applying preset { players:
[ { roomName: 'Living Room', volume: 51 },
{ roomName: 'Dining Room', volume: 51 } ] }
skipping breakout because already coordinator
after action false
Living Room "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume" STATUS: 200
Dining Room "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume" STATUS: 200
Living Room "urn:schemas-upnp-org:service:AVTransport:1#Play" STATUS: 200
emitting group-volume

#2
00 KEY_POWER
before action true
applying preset { players:
[ { roomName: 'Living Room', volume: 51 },
{ roomName: 'Dining Room', volume: 51 } ] }
skipping breakout because already coordinator
after action false
01 KEY_POWER
before action false
after action false
Living Room "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume" STATUS: 200
Dining Room "urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI" STATUS: 200
Dining Room "urn:schemas-upnp-org:service:RenderingControl:1#SetVolume" STATUS: 200
Living Room "urn:schemas-upnp-org:service:AVTransport:1#Play" STATUS: 200
emitting group-volume
emitting group-volume

You can see the contents of my sonos-lirc.js here:

http://ur1.ca/gvtr8

Also, out of curiosity:

-What is the difference between player.coordinator.groupSetVolume and player.groupSetVolume
-Are you using pm2 to run sonos-lirc as a forked daemon on your rapi?

P.S. I appreciate your support but if I'm consuming too much of your time feel free to tell me to bugger off.
Userlevel 4
Badge +14
I've got node-sonos-remote setup working great but it only manages one speaker at a time, even if they are grouped.

How could I manage the group volume?

Also, would it be possible to create a group. For example a preset that would always join Speaker A+B.


You can invoke
code:
player.coordinator.groupSetVolume("+2")


To control group volume instead. Personally I have mapped the channel up/down on my IR remote to control group volume, which means that to the "actions" object, I have added:

code:
"ch_up": function (player) {
player.groupSetVolume("+1");
return true;
}


Your IR codes probably differs from mine, but hopefully you get the idea. As you probably realize, +1, +2, +3 indicates increment steps (relates to % of volume)

Grouping can be achieved with presets, yes. There's an example preset (called "all") in sonos-lirc.js, you can just change that, and then map it to a key:

code:

var buttonToPreset = {
"KEY_1": "all"
};
Userlevel 2
I've got node-sonos-remote setup working great but it only manages one speaker at a time, even if they are grouped.

How could I manage the group volume?

Also, would it be possible to create a group. For example a preset that would always join Speaker A+B.
Userlevel 2
For those having issues getting lirc setup and configured the best how to I found was here:

http://www.jamesrobertson.eu/blog/2013/may/19/2326hrs.txt
Userlevel 2
Agree with guigui. Just got the web-controller up and running on my os-x machine.

And I've ordered a RaPi with IR to try to get your remote working.
Userlevel 2
Your software is exactly what I was looking for, great interface, responsive and easy to use.

Keep up the good work, can't way for music library browsing functionnality to be implemented.
Userlevel 4
Badge +14
HI Jishi,

How hard would it be possible to put a check so that if a favorite is already playing it won't attempt to reload the same favorite? I have found that certain Internet Radio stations take a long time to load in Sonos. If the command gets sent twice it can cause a long pause in what is playing.

Thanks


For radiostations, not hard at all. For playlists it would be impossible to make a reliable identification of a certain favorite. It makes sense to not try and load the same radiostation twice.
Userlevel 2
HI Jishi,

How hard would it be possible to put a check so that if a favorite is already playing it won't attempt to reload the same favorite? I have found that certain Internet Radio stations take a long time to load in Sonos. If the command gets sent twice it can cause a long pause in what is playing.

Thanks
Badge +2
Good Morning :

Just checking to see if your or will you combine the mod into one so it is easier to install and run ...

Alo trying to install and run pm2 beside fork any other sug for rasp pi to make it run I seems to hitting a wall many thanks

Robert
Userlevel 2
Finally got a chance to try this - great work !. Just what I was looking for. Just set it up on a VM.

As a Squeezebox refugee, I was used to embedding the web control for music into other interfaces for geeky home automation projects. After switching to Sonos, I was forced to lose the integration and use separate official applications - always less elegant no matter how nice the dedicated app may be.

Took about 10 minutes to re-integrate into Command Fusion interfaces at home.

Keep up the good work.
Badge +2
We await the new version and thank you the ir part is off the hook and all 3 combined is the answer to complete the package any chance when you look at the code that you could allow us to send tts to the zones for a door bell or announcements etc ( when you have spare time) yea right :)

Thank You for all your hard work........

Regards

Robert
Userlevel 4
Badge +14
Could you upload your version with it combined I am also using the remote control code. I keep blowing it up for some reason ........

:~(
Thank You
Robert


I don't run the IR remote and the web controller together, since they aren't modularized. Adding the http api is no problem, but I need to rework some stuff to make it easier to package it all together. Right now I'm doing a rewrite of all XML parsing to speed things up, but the plan is to create a complete distribution which contains all parts, which you can configure on/off instead. That would probably make it easier to install.
Badge +2
Could you upload your version with it combined I am also using the remote control code. I keep blowing it up for some reason ........

:~(
Thank You
Robert
Userlevel 4
Badge +14
Hi there :

Do you think if i merged both lib http and web to one server there would be a conflict ?

Many Thanks

Regards

Robert


No, that is actually preferred. Use a single instance of SonosDiscovery. I do that my self.
Badge +2
Hi there :

Do you think if i merged both lib http and web to one server there would be a conflict ?

Many Thanks

Regards

Robert
Userlevel 4
Badge +14
One theory is that you started it in cluster mode once, which would have made the pm2 daemon hog the relevant ports. When you later on tried in forked mode or forever, it wouldn't bind to them. It should have raised an error though...
Userlevel 2
Yep did all that :)

As I said, suddenly started working this morning.
Userlevel 4
Badge +14
Make sure that it is running in forked mode. If you started under cluster mode, then stopped it, and started it again with -x (without deleting it from pm2) it will still start in cluster mode.

Also, did you fix the startup script for pm2? (pm2 startup) That should fix environment variables, and then you should start pm2 using the init.d script.
Userlevel 2
so everything is running as root (I'm lazy 🙂 )

If I do not use PM2 or FOREVER and run directly from the terminal window in x-windows then it works.

Run under PM2 from the terminal window in clustered mode it works.

Run under PM2 from the terminal window in forked mode it doesn't work.

The api program works without problem. It's just the web controller that has issues. The web browser seems to be connecting but just not receiving data (it doesn't even timeout??) have tried with Chrome and Firefox.
Have even tried with only starting the web controller and leaving the api down - but I really want to use both.

OS is RASPIDAN

Port settings are all the defaults - I have not changed any of your settings


UPDATE::::::
Tried it again this morning and PM2 works!!!!
FOREVER still doesn't work but if PM2 is working I'm happy. The only thing that I can think of that I had changed in the mean time was to put the node and application paths into the PATH statement in the etc/.profile
Userlevel 4
Badge +14
Jishi,
first of all - a great piece of work.

I have spent the whole day installing it (both web controller and API) on my RASPI and in the final step come across a problem when trying to run it in the background.

I have tried using both FOREVER and PM2 to start the processes during boot time. This it does quite happily with no errors shown in the log files.

The problem that I observe however is that the web client wont display in a browser if the process is started with FOREVER (or PM2 when the -x option is used).

PM2 works if the mode is cluster - however this then eats 100% CPU.

The log file contents are identical when starting in the background or when starting from a terminal window. It indicates no errors or warnings.

The browser doesn't complain that the website is not there - it just sits and waits and displays nothing.

Anyone have any ideas?

I'm using the latest versions of everything (node 0.10.2) and the sonos-web-controller_0.6.0_pi build.

Peter


Hm, that is odd. I just tried it out and it works on my raspberry. I do however run it as root, which you might not.

What does the output from "netstat -ntpl" say? What OS are you running? Rasbian? Which port are you trying to run it under?

And, does it work, if you run it directly from the shell? Even as the same user that pm2 will run under?
Userlevel 2
Jishi,
first of all - a great piece of work.

I have spent the whole day installing it (both web controller and API) on my RASPI and in the final step come across a problem when trying to run it in the background.

I have tried using both FOREVER and PM2 to start the processes during boot time. This it does quite happily with no errors shown in the log files.

The problem that I observe however is that the web client wont display in a browser if the process is started with FOREVER (or PM2 when the -x option is used).

PM2 works if the mode is cluster - however this then eats 100% CPU.

The log file contents are identical when starting in the background or when starting from a terminal window. It indicates no errors or warnings.

The browser doesn't complain that the website is not there - it just sits and waits and displays nothing.

Anyone have any ideas?

I'm using the latest versions of everything (node 0.10.2) and the sonos-web-controller_0.6.0_pi build.

Peter
Userlevel 4
Badge +14
Hi guys.

I remember reading somewhere that somebody wanted the LED state of the players to be on when something was playing, and off when the player was paused/stopped.

Realized that isn't such a hard thing to accomplish, so I did a quick function for it.

Doing something like this:

code:

var SonosDiscovery = require('sonos-discovery');
var discovery = new SonosDiscovery();
discovery.setToggleLED(true);


Unfortunately there is a bit of delay (1s or something). I think someone wanted it for a light sensor that would power on/off an amplifier. I thought it was a fun feature anyway, even if nobody finds it useful 🙂
Userlevel 2
I pushed an update to the git repo with "trackseek" implemented. It will take total seconds that you want to seek into (for 2:00):

/Office/trackseek/120



nice thx
Userlevel 4
Badge +14

It would be nice if you can implement the trackseek in the http-api.


I pushed an update to the git repo with "trackseek" implemented. It will take total seconds that you want to seek into (for 2:00):

/Office/trackseek/120
Userlevel 2
Perfect! Works great.

Previously I had tried copying the function directly out of your http-api and it threw errors when I ran the script via node. Not sure what I did but I messed up somewhere.

This works great, Thanks!