Home of the Squeezebox™ & Transporter® network music players.
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: JSON help

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    7

    Question JSON help

    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

  2. #2
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    11,289
    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" ]]}
    To the following url:
    Code:
    http://localhost:9000/jsonrpc.js
    And you should get back a JSON response with the first 100 albums in your library.
    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 )

  3. #3
    Senior Member flattermann's Avatar
    Join Date
    Oct 2009
    Location
    Dortmund, Germany
    Posts
    774
    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.
    Christian

    Home of SqueezeCommander - The SqueezeBox Remote Control App for Android

  4. #4
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    11,289
    Quote Originally Posted by jimsheldon View Post
    where does jsonrpc.js actually live on the server side? I searched the entire server directory tree and it's nowhere to be found.
    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.pm
    Last 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 )

  5. #5
    Junior Member
    Join Date
    Oct 2010
    Posts
    7
    Quote Originally Posted by erland View Post
    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.pm
    Ah yes, that makes perfect sense.

    Thanks for the other two responses as well. The Poster firefox addon is working great for me already. Thanks very much!

  6. #6
    Junior Member
    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]]}

  7. #7
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    11,289
    Quote Originally Posted by jimsheldon View Post
    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]]}
    I can't look for myself since neither of these works in Sweden, but if you enable debug logging on network.cometd, and browse them using the Controller, Touch, Radio or SqueezePlay Desktop, you should be able to see the JSON commands used in the server log.
    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 )

  8. #8
    Junior Member
    Join Date
    Oct 2010
    Posts
    7
    Quote Originally Posted by erland View Post
    I can't look for myself since neither of these works in Sweden, but if you enable debug logging on network.cometd, and browse them using the Controller, Touch, Radio or SqueezePlay Desktop, you should be able to see the JSON commands used in the server log.
    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:
    [
      {
    You mentioned that those services don't work where you live, have you been able to control other apps via JSON?

    Thanks for the help

  9. #9
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    11,289
    Quote Originally Posted by jimsheldon View Post
    Hmmm, I enabled it, but all I seem to get are 'serverstatus' queries from the web interface:
    Do you see logs for other queries when you browse the local library ?

    It could be that these queries are sent to mysqueezebox.com and not towards SBS. Maybe you can enable some logging in SqueezePlay that logs sent requests on the client side ?
    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 )

  10. #10
    Junior Member
    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 ]]}
    This returns the first three apps available on the player.

    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" ]]}
    Where item_id is returned by the previous command.

    Hopefully this helps someone else who might be trying to implement a software remote using JSON.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •