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

    jishiAuthor
    Headliner II
    December 20, 2013
    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?
    Lyricist III
    December 20, 2013
    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?

    Yes the flirc could (and should) esy be setup for any remote in Windows and then moved to the target platform, in this case the rpi.
    http://flirc.tv/ I have ordered it but not got it yet. https://www.m.nu/flirc-universal-ir-remote-receiver-p-1116.html

    Were could I find your early rpi version with keystroke instead of IR on the GIT hub?

    Citate from this link http://thepihut.com/pages/flirc-a-review-of-the-ultimate-media-centre-companion

    The key is that FLIRC reports itself to the operating system as a standard USB Human Interface Device (HID), so any modern OS will be able to read it as if it was a keyboard. Even if the device or OS you want to use FLIRC on has no included support for remote controls, you can program FLIRC to “press” keys that the system will understand. For example, I was able to program FLIRC to interpret the directional pad on my remote to standard keyboard arrow keys; I then plugged FLIRC into my Android device and was able to navigate through the applications with my remote.

    This allows for incredible flexibility. Being able to program FLIRC from a different device than what you end up using it on and the fact that it emulates a USB keyboard means you can use FLIRC where other products would be useless.
    jishiAuthor
    Headliner II
    December 20, 2013
    No, I don't have that code in github. I will have to dig through my home laptop or the rpi to see if I still have it. It was merely a prototype and I could reproduce it once again probably.

    See here:

    http://forums.sonos.com/showpost.php?p=192751&postcount=13

    And here (my question regarding it, a bit technical):

    http://stackoverflow.com/questions/15742172/would-it-be-possible-to-read-out-physical-keyboard-strokes-in-node-js
    Lyricist III
    December 20, 2013
    No, I don't have that code in github. I will have to dig through my home laptop or the rpi to see if I still have it. It was merely a prototype and I could reproduce it once again probably.

    See here:

    http://forums.sonos.com/showpost.php?p=192751&postcount=13

    And here (my question regarding it, a bit technical):

    http://stackoverflow.com/questions/15742172/would-it-be-possible-to-read-out-physical-keyboard-strokes-in-node-js


    Thanks Jishi,
    I will do some test with the std rpi keyboard first before adding in the flirc. I supose it will work fine to run the remote node code on windows first just for me to learn how the code is working (after removing the lirc code)?
    jishiAuthor
    Headliner II
    December 20, 2013
    Thanks Jishi,
    I will do some test with the std rpi keyboard first before adding in the flirc. I supose it will work fine to run the remote node code on windows first just for me to learn how the code is working (after removing the lirc code)?


    Unfortunately, reading out keystrokes is highly linux-specific, so you won't be able to test that. This is because you want it to run in the background, and not be dependent on an active console session. It would be possible to enable auto login and a bash startup script but I don't think it would be a nice solution...
    Lyricist III
    December 20, 2013
    Unfortunately, reading out keystrokes is highly linux-specific, so you won't be able to test that. This is because you want it to run in the background, and not be dependent on an active console session. It would be possible to enable auto login and a bash startup script but I don't think it would be a nice solution...

    Ok Thanks, I understand the difference between keyboard reading in Linux and Windows. The question was more if the rest of the remote code would execute in windows so I could do some tests by changing code and so on just to learn how it works. I assume the only code to deal with is sonos-lirc.js ?
    jishiAuthor
    Headliner II
    December 20, 2013
    Ok Thanks, I understand the difference between keyboard reading in Linux and Windows. The question was more if the rest of the remote code would execute in windows so I could do some tests by changing code and so on just to learn how it works. I assume the only code to deal with is sonos-lirc.js ?

    Yes it would. I use Windows as my development platform so that isn't a problem. Node.js is fairly platform agnostic.
    Lyricist III
    December 23, 2013
    Jimmy:

    Happy Holiday to you and yours and thank you for a amazing project......

    Regards

    Robert
    jishiAuthor
    Headliner II
    December 23, 2013
    Jimmy:

    Happy Holiday to you and yours and thank you for a amazing project......

    Regards

    Robert


    Thanks, I will be silent for 3 weeks but don't be alarmed, I haven't abandoned it, yet. :)

    Happy holidays!
    Lyricist III
    January 5, 2014
    Hello,

    i like install it on windwos 7 system.

    - i have download the node and web zip files.
    - i have installed the node this will be fine
    - the zip file i have unzipped to a folder
    - in cmd i have "npm install" but then i get this logfile

    0 info it worked if it ends with ok
    1 verbose cli [ 'C:\\Program Files (x86)\\nodejs\\\\node.exe',
    1 verbose cli 'C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
    1 verbose cli 'install' ]
    2 info using npm@1.3.21
    3 info using node@v0.10.24
    4 verbose node symlink C:\Program Files (x86)\nodejs\\node.exe
    5 error install Couldn't read dependencies
    6 error package.json ENOENT, open 'C:\Program Files (x86)\nodejs\package.json'
    6 error package.json This is most likely not a problem with npm itself.
    6 error package.json npm can't find a package.json file in your current directory.
    7 error System Windows_NT 6.1.7601
    8 error command "C:\\Program Files (x86)\\nodejs\\\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
    9 error cwd C:\Program Files (x86)\nodejs
    10 error node -v v0.10.24
    11 error npm -v 1.3.21
    12 error path C:\Program Files (x86)\nodejs\package.json
    13 error code ENOPACKAGEJSON
    14 error errno 34
    15 verbose exit [ 34, true ]

    Can somenoe help me what the error is, what can i do? And how can i install the web controller?

    Thanks best regards Thomas