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
Hi Jishi,
On one of my Raspberry Pi running wheezy-raspbian I have installed NodeJS and the "Hello World" example is working. But I can't understand how to install the LIRC driver. The problem are due to my limited Linux skills. The IR code and Electronics isn't no problem for me.

So I plan to use FLIRC (emulates keyboards keys then IR is recivied) and wonder how difficult it's to change the Node code (sonos-remote-control) to act on some key pressed instead and were to start?

I'm a windows programmer but are not used with Java and WEB interface.


I did a version that reads out keystrokes instead of data from the lirc socket. That could be used for flirc instead. However, you still need to program your flirc, and that requires a graphical UI as I understand it. I don't think it will be that much easier. Do you already have a flirc receiver or are you planning on buying it? If the keyboard mapping is stored in the dongle, then I can see the simplicity of it. Then you can program it on your laptop/desktop and then plug it into the rpi, is that the case?
Userlevel 2
Hi Jishi,

I´m also interessted in the queue capability. So that we are able to queue an uri. I currectly write a module for "fhem" a opensource homeautomation system to support your node. Let you know about the progress.

Best regards

Sacha
Userlevel 2
Hi Jishi,
On one of my Raspberry Pi running wheezy-raspbian I have installed NodeJS and the "Hello World" example is working. But I can't understand how to install the LIRC driver. The problem are due to my limited Linux skills. The IR code and Electronics isn't no problem for me.

So I plan to use FLIRC (emulates keyboards keys then IR is recivied) and wonder how difficult it's to change the Node code (sonos-remote-control) to act on some key pressed instead and were to start?

I'm a windows programmer but are not used with Java and WEB interface.
Userlevel 2
Thanks for the info. I understand the magnitude of the tasks and the time it takes and certainly do appreciate the effort.

I will consider the pull request if I can wrap my head around the existing code and comm techniques early in the new year. I would like to be able to access my local music library and have search and queue up capabilities similar to those in the official controller as well as the old purple controller.

Thanks again. Yvon.
Userlevel 4
Badge +14
If I might ask, what are the future plans for this controller. Do you plan to support local music libraries, query tools, add / remove tracks form queue, etc. similar to the native controller.

Are you also planning to support other browsers and in particular mobile browsers.

This is a very nice tool and it seems to perform well and is quite flexible. Good job.


Well, my main goal was to implement the basic functionality for desktop browsers. That is pretty much there now, because I settled for only handling favorites to begin with. When I have made the final tweaks I will package it as version 1.0. I will not support additional browsers for the desktop version for the time being. Firefox and Chrome are available on all desktop/laptop platforms, including chromebook, so I consider that a waste.

Phase two was to implement a spotify-centric version of the web controller, that would use the spotify search engine and behave more like the spotify client when it comes to functionality. Mostly because I more or less use Sonos exclusively for Spotify streaming.

Some other loose ideas is party lockdown mode with a basic web controller for smartphones (only queue), a better mobile controller for all modern mobile platforms etc. When the basic functionality is there, all those other ideas wouldn't be that hard to implement.

Also note that the web controller functions has been prioritized based on my own usage pattern. For example, I never edit my queue, so that hasn't been a priority for me. If enough people think that it would be useful, I might prioritize that function. But the main focus will be to make it useful for as many as possible.

And lastly, I have done this in my spare time, by myself, and I don't have an infinite amount of time 😉. It has been fun and quite a challenge, but every now and then I need to rest as well. If people want to help out, I'll gladly accept pull requests.
Userlevel 2
If I might ask, what are the future plans for this controller. Do you plan to support local music libraries, query tools, add / remove tracks form queue, etc. similar to the native controller.

Are you also planning to support other browsers and in particular mobile browsers.

This is a very nice tool and it seems to perform well and is quite flexible. Good job.
Userlevel 2
Now i got it. I have to upgrade "node" itself. Sorry.

Will do it tomorrow.

Sacha


Hi jishi,

Works perfect. Well done. Very usefull.

Sacha
Userlevel 2
Yes, this is because you are running node 0.6.x. You need 0.8 or higher, and you might need to install it manually of it isn't in the ubuntu repos.

Now i got it. I have to upgrade "node" itself. Sorry.

Will do it tomorrow.

Sacha
Userlevel 4
Badge +14
Did some updates to the web-controller, it now has working player mute buttons, and you can seek in tracks by dragging the progress-bar.

Will add mousewheel/click to it later on.

Enjoy!
Userlevel 2
The fall back works well. Thank you.

As suspected, FreeBsd 91.p5 returns the following output:

{}

when interrogating for the network interface list

Thanks again. Yvon.
Userlevel 4
Badge +14
Okay, ynot, I pushed a fix for freeBSD.

Could you please also test this (relevant for a bug report):

code:

var os = require('os');
console.log(os.networkInterfaces());


Add that to a js file (test.js or similar) and invoke it with "node test.js", and send me the output? I want to see if it actually finds any interfaces, or if they are incorrectly labeled as "internal". It would be nice if I didn't have to install a VM with freeBSD just to test this 🙂
Userlevel 4
Badge +14
looks like all versions of node lead to the same issue i tried versions 0.8 and 0.10.

Can I define the sonos bridge, server interface IP(1 only) or even a list of networks to scan in the settings.json file and have it passed on instead?

Just a thought.


That's not necessary. I can make a fallback to the old behavior if no interfaces are found, that should resolve your issue.

I should file a bug ticket for the freebsd version as well, they might wanna fix that.
Userlevel 2
looks like all versions of node lead to the same issue i tried versions 0.8 and 0.10.

Can I define the sonos bridge, server interface IP(1 only) or even a list of networks to scan in the settings.json file and have it passed on instead?

Just a thought.
Userlevel 4
Badge +14
I've been looking through the thread, but can't seem to see if you have a webpage or a file outlining instructions on how to set all this up from scratch?

I have a 2008 R2 server running as a NAS to host, but can probably set up a VM running Linux if required.


I haven't really made a how-to yet since I haven't packaged it for distribution. But the short version is:

Install node.js, there is an installer for windows (http://nodejs.org/download/)

Download the repo that you want, there is a downloadable zip at each repo (a button to the right, says "Download ZIP"). for the web controller, this is https://github.com/jishi/node-sonos-web-controller/archive/master.zip

unzip it to a folder, invoke in that folder(from cmd or powershell):

npm install
node server.js
Badge
I've been looking through the thread, but can't seem to see if you have a webpage or a file outlining instructions on how to set all this up from scratch?

I have a 2008 R2 server running as a NAS to host, but can probably set up a VM running Linux if required.
Userlevel 4
Badge +14
A bit off topic but how does one run your code as a server on a raspberry as a service every time i redirect node server.js > robert.txt i do not return to the bash so i can run the other script .....thanks

It does run though so the install is correct.....But have no clue what I am doing yet but learning....

Thanks


The best option that I have found is to use pm2 (https://github.com/Unitech/pm2)

Basically, what you do is (as root):

code:

npm -g install pm2
pm2 startup
cd /your/app/folder
pm2 start server.js


This will persist through reboot and such because "pm2 startup" installed the necessary init scripts for it.

pm2 will revive running processes at reboot, but not stopped processes. This means that if the process crashed, then a reboot won't fix it.
Userlevel 4
Badge +14
Thanks for the quick reply. I am running FreeBSD 9.1p5 and Node-Devel-0.9.3 the latest port that I am aware of.

The dev build and the stable build are different packages, could you try it with the stable build, which should be 0.8.x something?

I'm not sure how the package system on freebsd works, but there seems to exist ports for 0.10 as well, but maybe not for your version?http://www.freshports.org/www/node
Userlevel 2
Thanks for the quick reply. I am running FreeBSD 9.1p5 and Node-Devel-0.9.3 the latest port that I am aware of.
Userlevel 4
Badge +14
tried the new version works well in puppy linux but not so well in FreeBSD where it worked previously. Now the IP detection for the controler no longer functions. I get the following:
- binding SSDP to port 2509
- relevant IPs {}
- info - socket.io started
- http server listening on port 8000
notification server listening on port 3500

looks like it does not detect the network interface and then scan for sonos. This worked in previous versions. Any advice??


Which version of node are you running? Apparently the interfaces aren't detected on freebsd for some reason, probably an incompatibility in node.
Userlevel 2
tried the new version works well in puppy linux but not so well in FreeBSD where it worked previously. Now the IP detection for the controler no longer functions. I get the following:
- binding SSDP to port 2509
- relevant IPs {}
- info - socket.io started
- http server listening on port 8000
notification server listening on port 3500

looks like it does not detect the network interface and then scan for sonos. This worked in previous versions. Any advice??
Userlevel 2
you can use the screen command to launch individual sessions on linux. Attach and detach from sessions at will
Badge +2
A bit off topic but how does one run your code as a server on a raspberry as a service every time i redirect node server.js > robert.txt i do not return to the bash so i can run the other script .....thanks

It does run though so the install is correct.....But have no clue what I am doing yet but learning....

Thanks
Userlevel 4
Badge +14
I'm sorry but I broke compatibility with node 0.8 in my last changes. This is fixed now. This is mostly for rasberry Pi-users, since it's a pain upgrading from source on it.

EDIT: Actually, you can download pre-compiled version here:
http://nodejs.org/dist/v0.10.22/node-v0.10.22-linux-arm-pi.tar.gz
Badge +2
A gift for the holiday thank you ....:D
Userlevel 4
Badge +14
Been silent the last week, been trying to reclaim some sleep.

However, got some news for you. The web controller now has a working master mute. I also re-made the content of all buttons in SVG which means that it will scale nicely when making the interface bigger. Also added some css effects for a better feeling.

I also tried to make a fix when having multiple interfaces in your computer. Now it will search for Sonos players on all networks, and use then one which find a player first. Probably not of concern for most of you, but might help some of you with more advanced setups.

Enjoy!