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
Multiple nodes on one machine can you run both versions of your server on the same windows pc any I trying the web based and the html they seems to hang during init if one is running and thoughts? Is it better to run a Linux box and then run both servers? If so what flavor of Linux would be best?

Many thanks and what a great project ........super job!


Do you mean that you want to run both the http-api and the web-controller on the same machine? Unfortunately at the moment, the use a fixed port for notifications, which means that they don't start. You can combine them though, if you want, and use the same underlying sonos-discovery, which would save memory, but that's a bit of a hack at the moment.

I might add some autodiscovery for the listening port to make it less error prone.
Userlevel 4
Badge +14
Empty queue is pretty common if you move your sonos around the house. Thanks for the fix.

I still do get the occasional null value error as well which crashes nodejs. Likely due to malformed or empty ID tags on mp3's. Have these issues been addressed yet? If to the best of your knowledge they have been addressed, I will look into more closely where exaclty I'm getting the null value.
Thanks, yvon


Yeah, I didn't mean to sound rude, I was more being rude to myself for not testing it :)

I thought the most of the null fails was adressed, but if you can give me error logs I will see what I can do.
Userlevel 2
Multiple nodes on one machine can you run both versions of your server on the same windows pc any I trying the web based and the html they seems to hang during init if one is running and thoughts? Is it better to run a Linux box and then run both servers? If so what flavor of Linux would be best?

Many thanks and what a great project ........super job!
Userlevel 2
Empty queue is pretty common if you move your sonos around the house. Thanks for the fix.

I still do get the occasional null value error as well which crashes nodejs. Likely due to malformed or empty ID tags on mp3's. Have these issues been addressed yet? If to the best of your knowledge they have been addressed, I will look into more closely where exaclty I'm getting the null value.
Thanks, yvon
Userlevel 2
I can confirm that artwork issue has now been fixed :)

I've written a blog entry about this project which may help some people not too familar with git/node.js.

http://danonit.blogspot.com.au/2013/11/web-api-for-controlling-sonos-system.html

I'm running the web controller on my NAS (Drobo-FS) and it's working a treat for basic control.
Userlevel 4
Badge +14
Well, of course it would break totally if you have an empty queue. Since 4.2 I rarely have empty queues any more, so I never noticed this. Anyway, I committed a fix for it. Thanks for the report.
Userlevel 2
Good news its running (my fault forgot to change port) but will post error log as there are a few popping up

Thank You....

Robert
Userlevel 4
Badge +14
I fixed the queue and favorites-update. It now reflects changes from other controllers, and it will switch queue when changing zones.

Favorites will also be updated as soon as some other controller adds one.

If you don't want to muck around with git, I did a pre-zipped version with all modules. Just unzip and run it with node.

http://upload.grabbarna.se/files/node-sonos-web-controller-0.5.1.zip

I also did a new screen cap to reflect the current state: https://www.youtube.com/watch?v=_7Dke5LsTF0

Today I also installed this at work, which will be the main control interface for my co-workers. Will also use a screen-computer which runs chrome in kiosk mode, to present the currently playing track (today it just shows this interface, but I will make a "TV" interface for it which is only for information. Much like my Dashboard application I wrote in .NET, but which will run fine under a lightweight linux installation with X.
Userlevel 4
Badge +14
Found the volume control over the last release or two to be getting kinda funky. Response for volume control is slow and a bit less predictable. By that I mean, when I go to slide the volume up, it seems to go down a bit then up. The behaviour seems to be less predictable than a few releases ago. I will test further t o see if it's just me.

I did a major rewrite of the volume element to support individual volumes, and I did notice similar behavior during development, but now I can't reproduce it? It's a bit problematic because when I adjust volume, I also get a notification that volume has changed, which i should act on IF another controller is the source of it. Problem being, I don't know that. What I do is that I don't act on the notification for a set time (800ms) after my own adjustment, to compensate for it. However, this isn't rock solid and might need tweaking.

In which scenario do you experience it? mouse wheel, click or drag? And is it master volume or the player volumes that is worst?
Userlevel 4
Badge +14
one is using fix output setting correct

Hm, what version are you actually running? It looks like it's an old version. I have zipped up a new one and you can test with that.

http://upload.grabbarna.se/files/node-sonos-http-api_0.4.3.zip
Userlevel 2
one is using fix output setting correct
Userlevel 4
Badge +14
Is one of them using fixed volume perhaps? Seems like it choke on the xml sent by a volume event. I should probably add an error handler for the xml parsing, since it fails occasionally for no apparent reason too.
Userlevel 2
yes one is wired and the wireless:

C:\xampp\htdocs\sserver>node server.js
http server listening on port 5005
scanning for players...
trying to subscribe to topology 192.168.1.209
trying to subscribe to topology 192.168.1.111
subscribing to events 192.168.1.111 Patio uuid:RINCON_000E5813DC2801400 120
subscribing to events 192.168.1.209 Master Bedroom uuid:RINCON_000E5813DC7201400
120
subscribed to topology 192.168.1.111 412
subscribed to topology 192.168.1.209 412
trying to subscribe to topology 192.168.1.162
type LastChange
Volume
subscribing to events 192.168.1.162 Living Room uuid:RINCON_000E5850693601400 12
0
type LastChange
TransportState
type LastChange
TransportState
trying to subscribe to topology 192.168.1.50
type LastChange
Volume
type LastChange
Volume

events.js:72
throw er; // Unhandled 'error' event
^
Error: Unclosed root tag
Line: 0
Column: 1240
Char:
at error (C:\xampp\htdocs\sserver\node_modules\sonos-discovery\node_modules\
sax\lib\sax.js:616:8)
at strictFail (C:\xampp\htdocs\sserver\node_modules\sonos-discovery\node_mod
ules\sax\lib\sax.js:636:22)
at end (C:\xampp\htdocs\sserver\node_modules\sonos-discovery\node_modules\sa
x\lib\sax.js:623:27)
at Object.SAXParser.end (C:\xampp\htdocs\sserver\node_modules\sonos-discover
y\node_modules\sax\lib\sax.js:137:24)
at SAXStream.end (C:\xampp\htdocs\sserver\node_modules\sonos-discovery\node_
modules\sax\lib\sax.js:209:16)
at IncomingMessage.onend (_stream_readable.js:483:10)
at IncomingMessage.g (events.js:175:14)
at IncomingMessage.EventEmitter.emit (events.js:92:17)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)

C:\xampp\htdocs\sserver>
robertboca,

I'm not using jishi's package, but I would not expect any model specific issues at the level jishi's program operates. Is there something different about the connection (Wired? Wireless?) to these two units?
Userlevel 4
Badge +14

it maybe that you are not supporting the older sonos units upon scanning zp80 and the zp100 as the code seems to die when it finds that unit


I don't have any old units my self so I haven't tested it. However, I can't think of anything that should misbehave just because of this. If you have any errors, please post them here and maybe it will give me a hint. In the meantime maybe someone else can confirm if old units work?
Userlevel 2
First I am hacker not a programmer but i have manage to install your code and looking forward to learning from it but I have a few ?

Could you provide a complete zip for the html and web interface as i keep getting init errors when running server will forward errors later

it maybe that you are not supporting the older sonos units upon scanning zp80 and the zp100 as the code seems to die when it finds that unit


Many thanks for all your amazing work .....I now have some more work to play with for my hobby

Regards

Robert
Userlevel 4
Badge +14
Yeah, currently known issues:

Queue and favorites doesn't update when changes are made.

Queue doesn't list correctly when having multiple zones.

Volumes for all players are always shown, regardless of selected zone.

group volume doesn't really work correctly when having multiple zones.

Sonza favorites doesn't seem to work (maybe other services as well, please let me know)
Userlevel 2
Ran for a few minutes last night, looks good. Found the volume control over the last release or two to be getting kinda funky. Response for volume control is slow and a bit less predictable. By that I mean, when I go to slide the volume up, it seems to go down a bit then up. The behaviour seems to be less predictable than a few releases ago. I will test further t o see if it's just me.

Secondly, when you queue up a favorite playlist, the queue display is not updated. in order to update it, you need to refresh the web controller form the browser. This refresh should be automatic when queuing up a mew playlist.

Other than that, initial test looks good. I will try more detailed testing over the next couple of days. Good work.
Userlevel 4
Badge +14
Alright guys, did push some fixes right now for everything reported. I still have some issues with random coverarts not loading, but that's minor.

I also have indivual volume control working, and it behaves like the official controller (click once to show). I removed the mute button for now since it wasn't working anyway, that is a later problem.

Enjoy!
Userlevel 4
Badge +14
Perfect timing... I was going to post an error for the "enametoolong"....

Just got the new code, and it working now....

I think I've found a different flavour of bug though.

Are you grabbing just the art directly from the player? Or are you limiting it to say 300x300?

I have a screen cap from chrome 31, where it's loading the art, but it's "full" size.... so it's layered through the queue list.


Yeah, I'm aware of that issue. I have that fixed so the maximum size will be 180px width or height, which fixes this.

Oh, and the n -> ff is a rather clumsy bug introduced by me 🙂 I didn't thought the img src would expand to a complete url, so I just replace "on" with "off" to switch state. This of course creates a weird effect if your hostname includes sONos, which becomes sOFFos, heh. I'll try and fix this tonight, hopefully I will have the individual volume control in place then as well.
Perfect timing... I was going to post an error for the "enametoolong"....

Just got the new code, and it working now....

I think I've found a different flavour of bug though.

Are you grabbing just the art directly from the player? Or are you limiting it to say 300x300?

I have a screen cap from chrome 31, where it's loading the art, but it's "full" size.... so it's layered through the queue list.
Userlevel 4
Badge +14
Hi, yeah got the same report from another user. I have pushed an update which will use a hash for filename instead, which will prevent the filename too long error.

run a git pull and try again. No changes to the dependencies so you don't need to remove the node_modules folder or run npm install this time.
Userlevel 2
Hey guys, great project - I'm looking forward to getting this up and running.

I've tried getting this up and running on my NAS and think I'm pretty close but may have possibly run into a bug.

I git cloned the latest web controller, ran npm install and started node server.js which seems to start fine, but once I browse to the website it half loads and crashes - it appears to be related to album art.

code:

# node server.js
scanning for players...
info - socket.io started
http server listening on port 8080
creating cache dir failed, this is probably normal { [Error: EEXIST, mkdir './cache'] errno: 47, code: 'EEXIST', path: './cache' }
trying to subscribe to topology 192.168.188.26
subscribing to events 192.168.188.25 Lounge Room RINCON_000E58B0B84E01400 600
subscribing to events 192.168.188.26 Bedroom RINCON_000E5880C3F401400 600
topology change emit
trying to subscribe to topology 192.168.188.25
triggering state volume Bedroom 6
calculating group volume Bedroom
Lounge Room "urn:schemas-upnp-org:service:ContentDirectory:1#Browse" STATUS: 200
triggering state volume Lounge Room 16
calculating group volume Lounge Room
trying to subscribe to topology 192.168.188.50
Bedroom "urn:schemas-upnp-org:service:ContentDirectory:1#Browse" STATUS: 200
Lounge Room "urn:schemas-upnp-org:service:ContentDirectory:1#Browse" STATUS: 200
fetching album art from 192.168.188.25
fetching album art from 192.168.188.26
fetching album art from 192.168.188.25
fetching album art from 192.168.188.26
404 'linking' 'L2dldGFhP3U9eC1maWxlLWNpZnMlM2ElMmYlMmZkcm9ibyUyZm11c2ljJTJmQXVkaWFibGUlMmZBdEhvbWVBU2hvcnRIaXN0b3J5b2ZQcml2YXRlTGlmZVVuYWJyaWRnZWRQYXJ0MV9tcDMzMl9kYW5pZWxzY2hlbGwuYWEmdj0yNzk='
serving /getaa?u=x-file-cifs%3a%2f%2fdrobo%2fmusic%2fAudiable%2fAtHomeAShortHistoryofPrivateLifeUnabridgedPart1_mp332_danielschell.aa&v=279

stream.js:81
throw er; // Unhandled stream error in pipe.
^
Error: ENAMETOOLONG, open './cache/L2dldGFhP3U9eC1maWxlLWNpZnMlM2ElMmYlMmZkcm9ibyUyZm11c2ljJTJmTWFqb3IlMjUyMExhemVyJTI1MjAtJTI1MjBGcmVlJTI1MjB0aGUlMjUyMFVuaXZlcnNlJTI1MjAoMjAxMyklMmYwMSUyNTIwWW91J3JlJTI1MjBObyUyNTIwR29vZCUyNTIwKGZlYXQlMjUyMFNhbnRpZ29sZCwlMjUyMFZ5YnolMjUyMEthcnRlbCwlMjUyMERhbmllbGxlJTI1MjBIYWltJTI1MjAlMjUyNiUyNTIwWWFzbWluKS5tcDMmdj0yOTA='
#


Screenshot of how much loads can be found here:
https://www.dropbox.com/s/f8bnu621qcevxbb/webcontrollercrash.png

Any suggests would be appreciated!
Userlevel 4
Badge +14
Seems like one doesn't always have an albumArtURI for the queue and favorites, i added a fallback for it. I don't think it has anything to do with socket.io, at least the error show no indication of that.

I also added dynamic favicon and title. Maybe it's just confusing if it keeps changing the favicon, however I thought it was nice :)

Anyway, I just pushed an update for sonos-discovery and the web controller, update as per usual. I have also lowered the amount of output generated from the process, especially from socket.io, which will greatly reduce the log file size.
Heh, I still don't follow. What exactly was the problem? Didn't it update? Or did it update and you didn't expect it to?

No... it's was fine. Giving you context for the memory stuff. Didn't want you to think I was clicking around or modifying things. Just letting it do it's thing in the background. Just like to do with one of the desktop controllers....

Found after running 24+ hours, ram was between 35->50megs or so....

Bigger issue was a log file generated with pm2....

/root/.pm2/logs/[pm2-name]-out.log

Was 35ish meg.

tail/view the log file, it was all the info dumps server.js ... When you start in console window with node server.js, it dumps a running log right... well the -out.log file was basically those screen dumps put to log file. Longer, or more activity, the faster the growth in the file.

I'm sure there's a pm2 option I need to set to prune the logs after x. I just haven't found it in the documentation.