Skip to main content
Headliner II
June 20, 2016

Simplified HTTP API (node.js)

  • June 20, 2016
  • 36 replies
  • 13200 views
Hi, I'm starting a new thread regarding this (old one here https://en.community.sonos.com/advanced-setups-229000/sonos-with-nodejs-my-attempt-33834) since that one grew out of hand.

I have made some major improvements to the simple HTTP API that I've built, and it now also comes with a pre-composed raspberry pi image that runs from a RAM-drive (based on AlpineLinux) for even simpler installation.

This software is useful for simple integration with home automation in mind, or for small hobby projects.

For more information, see http://jishi.github.io/node-sonos-http-api/

File issues at github https://github.com/jishi/node-sonos-http-api/issues

Have fun!
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.

36 replies

Lyricist II
January 23, 2017
Hi,
really great job - I got your api working on my RaspberryPi.

But there are a few things open which I couldn't find out. Maybe I'm blind :-)

I get an event every time the current track changes. That works fine. I can save the json element of the state. Now I like to play a track again. But how can I start a specific track? My tracks are from my music library, from spotify and from apple music. Those tracks aren't saved in any playlist or favorite list.

What I'm doing wrong? Can someone post an example for me?

Regards


I'm not really following your question. You need to provide more details for me to be able to help you. "Event every time", are you using the webhook?

Tracks are usually part of the queue, So you usually just do a trackSeek to the correct trackNo if you want to jump back and forth between sources, but I'm guessing that is not what you are asking. Again, if you could be more specific and paint the scenario, I might be able to give you an answer.


Hi jishi,
thanks for your response.

Let me try to explain better what I like to do. Sorry for my late response and my bad english.

I've installed your http-api on a RaspberryPI and I'm using the webhook.
So I get a call every time a new song gets played at one of my players. This works very fine. I'm saving the message data (ok, not the whole message) to a database (mongdb). I've written an Android app which displays all saved entries from that database.

Now I like to play one of those songs. My tracks are coming from AppleMusic, a local library and maybe Spotify in the future. I know from where a song originally comes from.

Since my last post here I've found some solutions:

For songs from AppleMusic I found the following command
code:
/RoomName/applemusic/{now,next,queue}/song:{songID}

With this command I'm able to play a song from AppleMusic.

For songs from Spotiy, there must be the following command. I couldn't test it since now, because I currently have no Spotify account:
code:
/RoomName/spotify/now/spotify:track:4LI1ykYGFCcXPWkrpcU7hn


And finally for my local library I've found the following commands.
code:
/Playroom/musicsearch/library/song/red+hot+chili+peppers+dark+necessities

This command is a "search" command. It is searching for a song that matches the criteria. The command is working, but it is not that what I want. So I'm looking for a better way to select and play a specific song from my local library.


I would be very happy if you can support me with some hints.

Many thanks
Regards
jishiAuthor
Headliner II
January 24, 2017

And finally for my local library I've found the following commands.
code:
/Playroom/musicsearch/library/song/red+hot+chili+peppers+dark+necessities

This command is a "search" command. It is searching for a song that matches the criteria. The command is working, but it is not that what I want. So I'm looking for a better way to select and play a specific song from my local library.


I would be very happy if you can support me with some hints.

Many thanks
Regards


There is no convenient way to "queue and play" form local library today. It would make sense to support that in the same manner as the music services, I just haven't looked at it. I'll create an issue for it in github and look at it when I get the time. It's a good suggestion.
Lyricist II
January 25, 2017

There is no convenient way to "queue and play" form local library today. It would make sense to support that in the same manner as the music services, I just haven't looked at it. I'll create an issue for it in github and look at it when I get the time. It's a good suggestion.

that would be great.

Many thanks to you. You did a really great job.
Contributor I
February 7, 2017
Hi @jishi,

Thanks for the library. I have working with it for a while, trying to understand the code. I am experimenting to build an Angular2 service out of it - with Observables (first experiments on https://github.com/Tommertom/ng2sonos).

I am struggling to understand how you get to all the data from the Sonos system. For example, the AlbumArtUri for a Radio stream. I have put some trackers on the soap.invoke method to see if that returns values, but it doesn't. Where do you get that data from? And how many soap calls are needed to build the Sonossystem data tree (volume, position, etc.)?

Anyway, hope you can indicate where I can find this in the code.

Regards,

Tom
jishiAuthor
Headliner II
February 7, 2017
Hi @jishi,

Thanks for the library. I have working with it for a while, trying to understand the code. I am experimenting to build an Angular2 service out of it - with Observables (first experiments on https://github.com/Tommertom/ng2sonos).

I am struggling to understand how you get to all the data from the Sonos system. For example, the AlbumArtUri for a Radio stream. I have put some trackers on the soap.invoke method to see if that returns values, but it doesn't. Where do you get that data from? And how many soap calls are needed to build the Sonossystem data tree (volume, position, etc.)?

Anyway, hope you can indicate where I can find this in the code.

Regards,

Tom


Hi Tom.

Most of the data is actually "evented" from the players, meaning that they do HTTP POST requests to my software with state changes. That's why you don't see them on the soap.invoke calls, because those are mostly explicit calls for action from the user (play, pause, skip change track etc). The only exception to that is the GetPositionInfo call which is used periodically to "sync" the current state, in case it has gotten out of sync. The code that is responsible for handling these requests are the NotificationListener, which emits it and then each player handles their own data to update their state.

You also need to subscribe to the events, in order to make the Sonos players send these requests. This is handled in the Subscriber class.

Hope that helps!
Contributor I
February 8, 2017
Hi Jishi

Thank you for your prompt reply. I already suspected (and feared) this would be the case. But now I know, at least I can finally go to sleep :)

Next step is I to figure out how to do the same in angular2, which should be doable.

Regards

Tom
jishiAuthor
Headliner II
February 8, 2017
Hi Jishi

Thank you for your prompt reply. I already suspected (and feared) this would be the case. But now I know, at least I can finally go to sleep :)

Next step is I to figure out how to do the same in angular2, which should be doable.

Regards

Tom


Looks like you are depending on some chrome native functions for the network traffic. You might already be aware of this, but https://github.com/siboulet/zonos is a chrome implementation of the Sonos network stack that might help you.

However, for maximum flexibility, having a separate server with no networking boundaries would be a lot easier.
Contributor I
February 8, 2017

Looks like you are depending on some chrome native functions for the network traffic. You might already be aware of this, but https://github.com/siboulet/zonos is a chrome implementation of the Sonos network stack that might help you.

However, for maximum flexibility, having a separate server with no networking boundaries would be a lot easier.


That indeed looks like an implementation to copy from, which is better than relying on a cordova plugin.

Will post if I got it to work.
Contributor III
February 13, 2017
Hi,
I don't understand how to install this. I Need a step-by-step description for a raspberry Pi with Raspian.
Thank you very much,
Baenker
Trending Lyricist I
February 18, 2017
Hi Jishi,

Is it possible to move a sub between rooms using the api?

Cheers,
Dave