Home of the Squeezebox™ & Transporter® network music players.
Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24
  1. #11
    Senior Member
    Join Date
    Sep 2005
    Posts
    2,845
    Quote Originally Posted by bpa View Post
    I don't know what is available on pcp but once you understand the CLI commands then for an application you might find it easier to use "curl"
    Since another Member successfully uses my hd44780 script on PCP nc should be available on pcp.

  2. #12
    Senior Member
    Join Date
    Oct 2005
    Location
    Ireland
    Posts
    17,833
    nc would be a good alternative especially as output can be redirected into a file or piped for later processing

    Example of the "players" command
    Code:
    echo "players" | nc -w 1 192.168.1.250 9090
    The "-w 1" (timeout of 1 sec) is needed if nc won't close the connection.

    edit:

    For completeness - the JSON HTTP version of "players".
    Code:
    curl -X POST -d '{"id":0,"params":["",["players"]],"method":"slim.request"}' http://192.168.1.250:9000/jsonrpc.js
    {"params":["",["players"]],"result":{"count":2},"id":0,"method":"slim.request"}
    
    curl -X POST -d '{"id":0,"params":["",["players","0","1","connected"]],"method":"slim.request"}' http://192.168.1.250:9000/jsonrpc.js
    {"method":"slim.request","params":["",["players","0","1","connected"]],"id":0,"result":{"count":2,"players_loop":[{"uuid":null,"firmware":"v1.8-589","name":"SqueezeLite","seq_no":0,"playerid":"7x:dx:3x:ax:3x:7x","connected":1,"ip":"192.168.1.58:32806","modelname":"SqueezeLite","displaytype":"none","model":"squeezelite","isplayer":1,"isplaying":0,"power":1,"playerindex":"0","canpoweroff":1}]}}
    Last edited by bpa; 2019-02-02 at 05:52. Reason: typos

  3. #13
    Senior Member paul-'s Avatar
    Join Date
    Jan 2013
    Posts
    2,284
    There are a lot of LMS JSON calls built into pcp-lms-functions. You can include that in your scripts.....
    piCorePlayer a small player for the Raspberry Pi in RAM.
    Homepage: https://www.picoreplayer.org

    Please donate if you like the piCorePlayer

  4. #14
    Quote Originally Posted by bpa View Post
    The following mnay be too much for you but you might as well have the info.

    Player discover LMS servers using broadcast on UDP on port 383 - iognore this if you see references to this.

    LMS talks to a player(e.g. squeezelite) using a protocol called slimproto on a TCP connection on port 3483 of the LMS server. Slimproto enables player to be told by LMS player to play music from an URL (can be remote but usually LMS) , vol up , vol down etc. Using slimproto Player tell LMS when it needs data, buffer empty etc.

    To talk to an LMS server a player has to open a TCP connecton from the player to the LMS server on port 3483. This means if a player is actively connected to an LMS server there is a TCP connection on the player to destination port 3483.

    The CLI is a totally separate LMS communication. It is supported by LMS server usually on port 9090 (can be changed in settings). It is intended to be used by "remote" applications (i.e. not running on LMS server processor) who want to "talk" to LMS server and get info from the LMS server about the LMS system, libraries etc.

    I don't know what available on pcp. but if LMS is on a server with IP address 192.168.1.250 then this would be (LMS inserts <LF> betweens lines of the response which is encoded as %3A). BLue is the user entry, red is LMS response - use your own IP address and MAC address of player has been altered.
    Code:
    telnet 192.168.1.250 9090
    Trying 192.168.1.250...
    Connected to 192.168.1.250.
    Escape character is '^]'
    players
    players   count%3A2
    players 0 1 connected
    players 0 1 connected count%3A2 playerindex%3A0 playerid%3A7x%3Adx%3A3x%3Aax%3A3x%3A7x uuid%3A ip%3A192.168.1.58%3A32806 name%3ASqueezeLite seq_no%3A0 model%3Asqueezelite modelname%3ASqueezeLite power%3A1 isplaying%3A0 displaytype%3Anone isplayer%3A1 canpoweroff%3A1 connected%3A1 firmware%3Av1.8-589
    7x:dx:3x:ax:3x:7x connected ?
    7x%3Adx%3A3x%3Aax%3A3x%3A7x connected 1
    I don't know what is available on pcp but once you understand the CLI commands then for an application you might find it easier to use "curl" on port 9000 and using POST request JSON encoded commands instead of telnet - the CLI command is in the "params"
    example command
    Code:
    curl -X POST -d '{"id":0,"params":["00:04:20:ab:cd:ef",["playlist","index","+1"]],"method":"slim.request"}' http://yourserver:9000/jsonrpc.js
    thank you very much.
    Thanks to other people for contributing to this discussion
    I completely understand what you said. there are totally 2 ways.
    1- checking tcp 3483 port to understand by netstate command in sh file scripting.
    if it is connected GPIO pin number is going to be high and LED will be on.

    2- using CLI command via telnet from linux command. I guess it is accessible in picoreplayer. I have to test it. I do not know about Curl. but I guess it is not too complex.
    I studied software engineering and have some experiences about networks and security. I can handle it.

    today I run squeezelite emulator on my windows 10 as a client and logitech media server and I run that command you write with termux on my android phone.
    it is worked and responded : " xx%3Axx%3Axx%3Axx%3Axx%3Axx connected 1" .
    when it is not connected responded :
    "xx%3Axx%3Axx%3Axx%3Axx%3Axx connected %3F " or "xx%3Axx%3Axx%3Axx%3Axx%3Axx connected ?"

    "%3F" is mean "?". not responded 0 in result for not connected.

    however right not I don't know Linux command to cut "1" from result. I should work on it.

    all in all I must write a script in this form :

    every 15 20 seconds while true :
    do
    //check connection
    //if connected turn on led
    end

    it must run from startup until turn off. what method do you think is more reliable to run every 15 or 30 seconds. I don't know telnet(curl) method is Affected
    in bandwidth or not. I always use at least 10 zero w picoreplayer on my network. this checking script must be run on every zero w every 15 20 seconds for checking connection.you think is there a problem about telnet from many zero w to lms server ? in this method , i'm just worried about bandwidth and this script maybe Disrupt while listening to music and audio syncing lms.

    what you think about this ?
    Last edited by nimaazx; 2019-02-02 at 13:22.

  5. #15
    Senior Member Greg Erskine's Avatar
    Join Date
    Sep 2006
    Location
    Sydney, Australia
    Posts
    1,719
    hi nimaazx,

    We have done a lot of your work already. As Paul said, look at /home/tc/www/cgi-bin/pcp-lms-functions.

    In your script add ./home/tc/www/cgi-bin/pcp-lms-functions, then call function.

    Here is the test page for this functions, [Main Page] in [Beta] Mode > [Extras] > [LMS CLI].

    The "netstat" code is in /home/tc/www/cgi-bin/pcp-functions, look for routine pcp_lmsip.

    regards
    Greg

  6. #16
    OK, thank you guys.

  7. #17

    Telnet dynamic ip address

    Hello again.
    I wrote a sh script file that telnet to server every 5 seconds in picoreplayer. if its mac address connected and lms server responds "1" , my led from gpio is on.

    there is a question for me.
    I use a static ip address in my telnet command to connect to lms server cli.
    is there a way to find out a lms ip server from linux automatically?
    as i read it before picoreplayer uses autodiscovery for findind lms. if it is connected to lms server , the ip of lms should be store somewhere.
    and in this way if it can be implemented , if the lms server ip address is changed or not static in my network or modem router, sh telnet can work with this way.
    works independently.
    but right now it can work with my static ip address. 192.168.1.17 (it is lms server addres)

    if changed not work. because i use this address for conecting to my lms cli.

    what is your idea?
    thanks again.

  8. #18
    Senior Member Greg Erskine's Avatar
    Join Date
    Sep 2006
    Location
    Sydney, Australia
    Posts
    1,719
    Quote Originally Posted by Greg Erskine View Post
    hi nimaazx,

    We have done a lot of your work already. As Paul said, look at /home/tc/www/cgi-bin/pcp-lms-functions.

    In your script add ./home/tc/www/cgi-bin/pcp-lms-functions, then call function.

    Here is the test page for this functions, [Main Page] in [Beta] Mode > [Extras] > [LMS CLI].

    The "netstat" code is in /home/tc/www/cgi-bin/pcp-functions, look for routine pcp_lmsip.

    regards
    Greg
    hi nimaazx,

    Did you miss this post?


    Code:
    #!/bin/sh
    
    . /home/tc/www/cgi-bin/pcp-functions
    
    echo $(pcp_lmsip)

    regards
    Greg
    Last edited by Greg Erskine; 2019-02-20 at 01:26.

  9. #19
    Senior Member Greg Erskine's Avatar
    Join Date
    Sep 2006
    Location
    Sydney, Australia
    Posts
    1,719
    hi again nimaazx,

    Have you had a look at the basic piCorePlayer Command Line Interface (CLI)

    https://www.picoreplayer.org/pcp_cli.shtml

    regards
    Greg

  10. #20
    Quote Originally Posted by Greg Erskine View Post
    hi nimaazx,

    Did you miss this post?


    Code:
    #!/bin/sh
    
    . /home/tc/www/cgi-bin/pcp-functions
    
    echo $(pcp_lmsip)

    regards
    Greg
    Hey Greg, I had seen your post before, but I did not test it. I'm inspired by "telnet" method. I use cli lms. maybe there is a simple way for doing this. right now I don't have pcp and raspberry pi until tomorrow.
    but I really like share my code with you.


    Code:
    sudo echo "17" > /sys/class/gpio/export
    sudo chown -R tc /sys/class/gpio/gpio17/
    sudo echo "out" > /sys/class/gpio/gpio17/direction
    mac=$(sudo cat /sys/class/net/wlan0/address)
    command=$mac' connected ?'
    host='192.168.1.17 9090'
    #///////////////////////////
    program(){
    result=$(
    (
    echo "$command"
    sleep 1
    echo "exit"
    ) | timeout -t 5 telnet $host )
    
    if [ "$result" != "Terminated" ]
    then
    	data=$( (echo "$result") | cut -d ' ' -f3)
    	if [ $data -eq 1 ]
    	then
    		return 1
    	else
    		return 0
    	fi
    else
    	return 0
    fi
    } #end of program
    #////////////////////////////////
    
    while true;
    do
    	program
    	dd=$?
    	if [ $dd -eq 1 ]
    	then
    		echo "Connected"
    		sudo echo "1" > /sys/class/gpio/gpio17/value		
    	else
    		echo "Not Connected"
    		sudo echo "0" > /sys/class/gpio/gpio17/value
    		
    	fi
    sleep 2s
    done
    yeah, "$(pcp_lmsip)" this is exactly what I want .instead of writing this code I could just check "$(pcp_lmsip)" this variable. if it is filled turn on led.
    I don't know if possible 20 30 pcp telnet to one lms server at one time and lms windows app can handle their requests every 5 sec to check their connection, it works or not. but just checking "$(pcp_lmsip)" , is not dependable to network and telnet.

Tags for this Thread

Posting Permissions

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