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

    Lyricist III
    November 28, 2013
    Ok been testing presets in httpsonos and I believe we have a bug if error in preset file misspellings etc not in syntax the server needs to be rebooted other wise it will fail to read the next request for preset I see no errors in the log .but will keep looking.
    Trending Lyricist I
    November 28, 2013
    Hi You have missed the "," after ""Acid Jazz Radio" } " I added it in the code above.

    Thanks... I tried the "," after both new presets, didn't realize that you need to not have it after the last one.....

    OK, so now the server is starting....

    Connecting through a browser and using:

    :5005/presets/Thiev/Play

    Output on the screen:

    code:

    { room: 'presets', action: 'AcidJazz', value: 'play' }
    { room: 'presets', action: 'Thiev', value: 'Play' }


    But it's not doing anything to the players....

    If I do the

    code:

    :5005/office/favorite/thievery corporation rdio radio


    It was starting the stream.... with the current grouping. I was also able to stop it.

    Thoughts?
    jishiAuthor
    Headliner II
    November 28, 2013
    Thanks... I tried the "," after both new presets, didn't realize that you need to not have it after the last one.....

    OK, so now the server is starting....

    Connecting through a browser and using:

    :5005/presets/Thiev/Play

    Output on yeah,I think screen:

    code:

    { room: 'presets', action: 'AcidJazz', value: 'play' }
    { room: 'presets', action: 'Thiev', value: 'Play' }


    But it's not doing anything to the players....

    If I do the

    code:

    :5005/office/favorite/thievery corporation rdio radio


    It was starting the stream.... with the current grouping. I was also able to stop it.

    Thoughts?


    yaEah, I think you are sending in /play at the end of the URL,which yuou shouldn't, it confuses it.

    only invoke /preset/thiev and you should be golden.
    jishiAuthor
    Headliner II
    November 29, 2013
    Just to make sure, there can be no end slash either, or it will interpret the command incorrectly.
    Trending Lyricist I
    November 29, 2013
    Just to make sure, there can be no end slash either, or it will interpret the command incorrectly.

    Check.... no trailing slash... unless chrome is "auto" adding....

    Sample:

    :5005/presets/test2
    jishiAuthor
    Headliner II
    November 29, 2013
    Check.... no trailing slash... unless chrome is "auto" adding....

    Sample:

    :5005/presets/test2


    Well, it should be /preset/test2, it will parse it errorneous if you call it "presets", unfortunately.
    Lyricist III
    November 30, 2013
    Player playing display.....I saw you created a page to display what is playing etc could you or would you send it our way to play with many thanks

    Robert

    PS rasberry on its way oh boy more confusion on my life thanks again really enjoying your stuff and learning slow but learning
    jishiAuthor
    Headliner II
    November 30, 2013
    Player playing display.....I saw you created a page to display what is playing etc could you or would you send it our way to play with many thanks

    Robert

    PS rasberry on its way oh boy more confusion on my life thanks again really enjoying your stuff and learning slow but learning


    Well, I can't really distribute it as is since it is both only Spotify centric (only works for spotify tracks because I download high-res covers from their web services), and because the font used is copyrighted. I will need some work to adjust this and have like a last.fm fallback for the cover arts or something.
    Lyricist III
    December 1, 2013
    No worry could you just create a simple example showing how to display in simple formatted

    the return from the http call ip/zone/state I am trying but getting no where fast .... thank you Robert
    jishiAuthor
    Headliner II
    December 2, 2013
    I can't reproduce that error. What is Office playing when you try and request the state? What does http://192.168.1.50:1400/status/perf say as current track?