Hi,
I don't really understand how to remotely get, or set the status or volume of a client thanks to JSON RPC API.
The port seems to be 1705.
May I achieve this with a HTTP request?
My aim is to integrate Snapcast to the Fibaro Home Center 2 (a smart box)
Sorry for my stupid question...
Open a TCP connection on port 1705. Send and receive messages formatted according to JSON RPC spec. You can see an implemention in Python here.
Thank you for your answer.
It works fine with the Python script!
But I can't install the Python package on my box.
Is it possible to control Snapcast with a simple URL request?
If so, could you please provide an example?
You should be able to use curl with the --data-binary argument and a valid JSONRPC message.
I've tried without success with the Chrome extension POSTman:
Your Message Looks good but I don't have a clue whether it can work via post. But from what happyleavesaoc said, I would try binary instead of raw
OK finally it works with JSON api, I've added "rn" at the end of my request.
Other question : Is there a JSON method for connecting or disconnecting a specified client?
Yep, the snapserver expects "Newline Delimited JSON" (ndjson). Not wrapped into HTTP, but pure ascii json over TCP. The newline \n is used to mark the end of a json message.
There is a "spec" (work in progress) here:
https://github.com/badaix/snapcast/tree/master/doc/json_rpc_api
You can find a java implementation in the Android client's source code.
There is no method to connect or disconnect a client. You can mute/unmute a client, but you cannot disconnect a client.
What is the idea behind connecting/disconnecting a client?
BTW: thanks for the hint about POSTman 馃憤
This is what I do, I mute the client where I don't want to listen music, but I suppose the stream is still sent to the client.
In order to save bandwidth on my LAN, I think it whould be better to disconnect the client (like Logitech Media Server do)
true, but the "control connection" must be there to be able to reconnect.
Good idea, but not yet implemented.
closing, as it is related to #150
hi, same issue here: should be possible to post an example of the json message to use ? i tried several time with no luck... i would like to use a curl command.
There are examples here.
Curl will use HTTP, but you have to use raw TCP (i.e. without HTTP header, just the json messages, delimited by 'n')
thanks for quick reply: something like that should be ok ? 'cause doesn't work
curl --data-binary '{"id":8,"jsonrpc":"2.0","method":"Server.GetRPCVersion"}n' 127.0.0.1:1705
curl will still use HTTP, when I get it right:
from curl -h:
--data-binary DATA HTTP POST binary data (H)
Hi, If u are interested I developed a python deamon that listens and bridges http request to raw socket.I can share it pushing on github if u want. regards
Yes, why not :smiley:
People often ask for some HTTP-like access. It would be quite easy to natively support json wrapped in HTTP POST or GET as done in Kodi.
The main problem (also true for REST) is the lack of push notifications. Kodi supports notifications via raw TCP (as Snapcast does) and via WebSockets (I don't know how convenient WebSockets are for clients).
On the other hand, I was thinking of an external bridge, which would keep Snapcast small and still generic. Hence your approach sounds highly interesting.
I will reopen this issue. Just to collect some more ideas, as my knowledge of what kind of "webservice" is most convenient is rather limited.
Perfect , I'll clean the code and I'll push on github. I you like it i'll do a pull request.
I tried with garmin smartwatch simulator to control music with the watch and it works.
I'll write you an email when ready.
Marco
https://github.com/freedreamer82/snapcastHttpd
try it with :
curl -d '{"id":8,"jsonrpc":"2.0","method":"Server.GetRPCVersion"}' 127.0.0.1:7777
let me know if it works from your side.
Marco
curl didn't work for me.
i managed to get an answer from the snapcast server with that command:
echo '{"id":8,"jsonrpc":"2.0","method":"Server.GetRPCVersion"} ' | nc -w 1 <ip-of-snapcast-server> 1705
the space after GetRPCVersion"} and ' is very important. without it I got an error. it took me long time to find this hack...
@badaix to answer your question of how convenient Websockets are for clients, the answer (in my opinion) is: very!
Connecting via TCP is generally limited to server-side clients, whereas Websockets are client-ready as well a server-ready. In my experience Websockets are much more widely supported than TCP. This is supported by the number of people asking for help connecting to the Snapcast API from their applications.
I believe the request for Websocket functionality is already opened: https://github.com/badaix/snapcast/issues/250. Do you think this is something that you'll be looking to implement?
HTTP Put and Websockets are meanwhile implemented and accessible via port 1780
Most helpful comment
curl didn't work for me.
i managed to get an answer from the snapcast server with that command:
echo '{"id":8,"jsonrpc":"2.0","method":"Server.GetRPCVersion"} ' | nc -w 1 <ip-of-snapcast-server> 1705the space after GetRPCVersion"} and ' is very important. without it I got an error. it took me long time to find this hack...