Greetings!
I have been familiarizing myself with Squeezebox Server's CLI interface over port 9090 for a few days now. I can navigate menus, select songs, stop, pause, skip, etc.
I would like to take the next step and start writing some scripts using the JSON interface. Unfortunately I have zero experience with JSON. I searched these forums and found suggestions for using firefox/firebug to sniff the web interface traffic. Unfortunately the only jsonrpc.js traffic I saw seemed to be coming from the server, I couldn't figure out how to send anything to it.
Here's a dumb question... where does jsonrpc.js actually live on the server side? I searched the entire server directory tree and it's nowhere to be found.
Does anyone have or know of a dead-simple JSON communication example?
Thanks!
Jim
Results 1 to 10 of 11
Thread: JSON help
-
2010-10-31, 06:22 #1
- Join Date
- Oct 2010
- Posts
- 7
JSON help
-
2010-10-31, 06:30 #2
There might be better ways to do this but so far I've been using the "Poster" firefox add-on which allows to to issue a POST to jsonrpc.js.
For example, send a POST message with this body:
Code:{"id":1,"method":"slim.request","params":[ "-", ["albums", "0","100" ]]}
Code:http://localhost:9000/jsonrpc.js
Erland Isaksson (My homepage)
Developer of many plugins/applets
Starting with LMS 8.0 I no longer support my plugins/applets (see here for more information )
-
2010-10-31, 06:30 #3
Try to connect to http://yourserver:9000/jsonrpc.js and send this:
{"id":1,"method":"slim.request","params":["<SB_Player_MAC>",["status","-","1"]]}
This the same as the CLI command "<SB_Player_MAC> status - 1".
Or, to power up a player, use:
{"id":1,"method":"slim.request","params":["<SB_Player_MAC>",["power","1"]]}
You may also want to enable JSON debugging on SBS.
This will log all JSON messages in the server.log.
-
2010-10-31, 06:35 #4
I believe the logic behind jsonrpc.js can be found in the perl code in the "handleURI" function in:
Slim/Web/JSONRPC.pm
If you are using Windows, this will of course be compiled into the exe so you can't see the actual perl code that handles the logic. However, you can get it directly from svn if you like to see what it does:
http://svn.slimdevices.com/repos/sli...Web/JSONRPC.pmLast edited by erland; 2010-10-31 at 06:38.
Erland Isaksson (My homepage)
Developer of many plugins/applets
Starting with LMS 8.0 I no longer support my plugins/applets (see here for more information )
-
2010-10-31, 08:46 #5
- Join Date
- Oct 2010
- Posts
- 7
-
2010-11-01, 09:58 #6
- Join Date
- Oct 2010
- Posts
- 7
I have a quick follow up question...
Can I control apps with this interface? So far I haven't been able to get Slacker, Last.fm or Pandora to give me any data back using commands like:
Code:{"id":1,"method":"slim.request","params":[ "-", ["slacker","items",0,9]]}
-
2010-11-01, 10:45 #7Erland Isaksson (My homepage)
Developer of many plugins/applets
Starting with LMS 8.0 I no longer support my plugins/applets (see here for more information )
-
2010-11-01, 14:06 #8
- Join Date
- Oct 2010
- Posts
- 7
Hmmm, I enabled it, but all I seem to get are 'serverstatus' queries from the web interface:
Code:[10-11-01 17:03:46.1593] Slim::Web::Cometd::requestCallback (861) requestCallback got results for /ef6a4ad8/slim/serverstatus / 1 [10-11-01 17:03:46.1633] Slim::Web::Cometd::Manager::deliver_events (214) Sending event on channel /ef6a4ad8/slim/serverstatus to ef6a4ad8 [10-11-01 17:03:46.1795] Slim::Web::Cometd::Manager::deliver_events (228) Delivering events to ef6a4ad8: [ {
Thanks for the help
-
2010-11-01, 14:34 #9Erland Isaksson (My homepage)
Developer of many plugins/applets
Starting with LMS 8.0 I no longer support my plugins/applets (see here for more information )
-
2010-11-09, 08:46 #10
- Join Date
- Oct 2010
- Posts
- 7
I just wanted to follow up with the solution I found.
I wasn't seeing any JSON traffic after turning on network.cometd debug logging because what I had been using to control the player wasn't sending JSON to the SB server.
I picked up iPeng for my ipod touch, ran SB server, connected my SB Touch to the SB server, turned on network.cometd debug output, and voilà! More JSON data than I could ever want!
By stepping through the server's log file I can now see every query and response, all JSON formatted.
Here is an example JSON query that works for me:
Code:{"id":1,"method":"slim.request","params":[ "<Player MAC>", ["myapps", "items", 0, 3 ]]}
You can then start descending into menus with commands like:
Code:{"id":1,"method":"slim.request","params":[ "<Player MAC>", [ "myapps", "items", 0, 6, "item_id:7dd26ab4.1.0" ]]}
Hopefully this helps someone else who might be trying to implement a software remote using JSON.