Home of the Squeezebox™ & Transporter® network music players.
Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12
  1. #11
    Junior Member
    Join Date
    Aug 2020
    Posts
    22
    Quote Originally Posted by jeroen2 View Post
    Simply using JSON (in Python or in Shell scripts) is way easier, but the info is much harder to find..

    In Python, for more complicated stuff, I use Request.
    Hi @jeroen2,

    I am trying to setup volume control using JSON in Python 3.9 (with requests.post) and encountering errors as below. Could you please share a full sample python program for JSON post ?

    urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

  2. #12
    Senior Member
    Join Date
    Jul 2020
    Posts
    312
    Quote Originally Posted by sh1ntomi View Post
    Hi @jeroen2,

    I am trying to setup volume control using JSON in Python 3.9 (with requests.post) and encountering errors as below. Could you please share a full sample python program for JSON post ?

    urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
    I haven't tried using Python for volume, but I do have one setup where the remote (through Lirc) sends JSON to the server through a bash script to set the volume. So in principle I would think that setting volume through JSON should work. :-)

    Did you try using Curl on the command line to check the JSON?
    Code:
    curl -X POST -d '"$command"' "$LMSIP":9000/jsonrpc.js"
    (where $command is the JSON data, and $LMSip is the address of the server)

    An example of the full python code would be this:
    Code:
    #!/usr/bin/env python
    
    import requests
    
    # ----------configure players and set base values
    ServerLMS = 'http://314.local:9000/jsonrpc.js'
    PlayersOn =  ["xx:xx:xx:xx","xx:xx:xx:xx","xx:xx:xx:xx"]
    
    
    for EachPlayer in PlayersOn:
    	try:
    		data = '{ "id": 1, "method": "slim.request", "params":["'+EachPlayer+'", ["power", 1]]}'
    		requests.post(ServerLMS, data=data)
    	except:
    Where replacing ["power", 1] with something like ["mixer", "volume", 70] should work to set the volume.

    As an alternative, when your script is running on the same Pi that runs the player, you could just use the command line shortcuts. ("pcp up", "pcp down") through os.system?

Posting Permissions

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