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

    Contributor I
    December 14, 2013
    you can use the screen command to launch individual sessions on linux. Attach and detach from sessions at will
    Contributor I
    December 14, 2013
    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??
    jishiAuthor
    Headliner II
    December 14, 2013
    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.
    Contributor I
    December 15, 2013
    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.
    jishiAuthor
    Headliner II
    December 15, 2013
    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
    jishiAuthor
    Headliner II
    December 15, 2013
    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.
    Trending Lyricist I
    December 15, 2013
    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.
    jishiAuthor
    Headliner II
    December 15, 2013
    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
    Contributor I
    December 15, 2013
    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.
    jishiAuthor
    Headliner II
    December 15, 2013
    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.