Skip to main content
Headliner II
Mar 5, 2013 10:27 PM UTC

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

    Lyricist III
    Nov 25, 2013 11:20 PM UTC
    Ok so where am I missing some thing this is my preset file and it bombs every time....Sorry to be ....Ps love the interface

    {
    "all":{
    "players":[
    {
    "roomName":"Bathroom",
    "volume":10
    },
    {
    "roomName":"Family Room",
    "volume":10
    },
    {
    "roomName":"Office",
    "volume":10
    },
    {
    "roomName":"Bedroom",
    "volume":10
    },
    {
    "roomName":"Living Room",
    "volume":15
    }
    ],
    "state": "stopped",
    "favorite": "carlos",
    "playMode": "normal"
    }
    }
    Translate
    jishiAuthor
    Headliner II
    Nov 26, 2013 10:03 AM UTC
    Hm, yeah, it does seem correct. I will need to test it when I'm at home.
    Translate
    Lyricist III
    Nov 26, 2013 11:11 AM UTC
    throwing this error
    thank you
    C:\sonos1>node server.js
    binding SSDP to port 2188
    scanning for players...
    notification server listening on port 3500

    module.js:485
    throw err;
    ^
    SyntaxError: C:\sonos1\presets.json: Unexpected string
    at Object.parse (native)
    at Object.Module._extensions..json (module.js:482:27)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at C:\sonos1\server.js:12:13
    at Object.cb [as oncomplete] (fs.js:168:19)

    C:\sonos1>
    Translate
    Contributor I
    Nov 26, 2013 11:43 AM UTC
    Jishi,
    If you provide a template (unless it's there and I didn't notice 🙂 then I can test on PS3 to see how it acts.
    Translate
    jishiAuthor
    Headliner II
    Nov 26, 2013 1:38 PM UTC
    Seems like your presets.json contains some invalid syntax, you could try and verify the syntax in some online tool: http://jsonlint.com/ first

    The second error is due to a change I did yesterday which I didn't foresee. I'll try and fix that later.
    Translate
    Lyricist III
    Nov 26, 2013 2:12 PM UTC
    Thank You .....!;)
    Translate
    Lyricist III
    Nov 27, 2013 3:31 AM UTC
    Will give it try could it be names with a space I know that if you have a space in fav name it fails...
    Thanks..
    Translate
    jishiAuthor
    Headliner II
    Nov 27, 2013 9:42 AM UTC
    Will give it try could it be names with a space I know that if you have a space in fav name it fails...
    Thanks..


    It shouldn't, are you sure about that? I have a few favorites with spaces and never had a problem.
    Translate
    Lyricist III
    Nov 27, 2013 1:57 PM UTC
    I will double check and get back after i update the files but no all the rooms are correct but they do have spaces....will test and forward logs thank you again
    Translate
    jishiAuthor
    Headliner II
    Nov 27, 2013 6:12 PM UTC

    I have one SONOS PlayBar and it's no prblem to manage music/radio on it but I also would like to be able to switch to the TV sound (optical SPDIF).

    In org SONOS i select TV input as a source "TV" the same way I do for Spotify, Rado etc.

    Any clue?


    Unfortunately you can't add a line-in as a favorite, and listing music library and line-ins aren't the priority for now. Great info though, since I don't have a playbar myself, wasn't aware of the different URI format for spdif line in.

    I will probably finish presets before I start with music browsing, and in that case you will be able to specify "x-sonos-htastream:RINCON_000E5XXXXXXX01400:spdif" as a preset uri (you could be able to bind this to an IR remote if you get a IR receiver to your raspberry).

    Doesn't the playbar have an auto line-in feature like all the other players though?
    Translate