way to detect Picoreplayer connected to LMS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nimaazx
    Member
    • Jan 2019
    • 41

    way to detect Picoreplayer connected to LMS

    Hello everybody.
    I think about add a feature to Picoreplayer and raspberry.
    sometimes when I turn on my zero w to connect picoreplayer to Logitech media server , I always don't have Hdmi output to understand what status it is in,
    recently I wrote a sh script to turn on led when it is connected to wifi with bash scripting gpio.

    I want to ask you a solution ,
    is there a way or parameter i can check when it is connected to LMS server?
    for example after connecting a variable or flag is set and I can check it in loop.
    the wifi led method I used is good but as I said connecting to lms server or for example finding out this zero w is detected by server and synced and after that turn the led on is more reliable.
  • Greg Erskine
    Senior Member
    • Sep 2006
    • 2808

    #2
    hi nimaazx,

    I am not 100% sure what you are after.

    From my experience if LMS is up, then squeezelite *always* connects, well 99.99% of the time.

    The command netstat shows you the connection between squeezelite and LMS.

    Code:
    tc@piCorePlayerSCREEN:~$ netstat -t
    Active Internet connections (w/o servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State
    tcp        0      0 192.168.1.15:48962      192.168.1.6:3483        ESTABLISHED
    tcp        0    160 192.168.1.15:ssh        192.168.1.16:54966      ESTABLISHED
    tcp        0      0 192.168.1.15:46816      192.168.1.6:9000        ESTABLISHED
    netstat: /proc/net/tcp6: No such file or directory
    tc@piCorePlayerSCREEN:~$
    regards
    Greg

    Comment

    • nimaazx
      Member
      • Jan 2019
      • 41

      #3
      ]
      Originally posted by Greg Erskine
      hi nimaazx,

      I am not 100% sure what you are after.

      From my experience if LMS is up, then squeezelite *always* connects, well 99.99% of the time.

      The command netstat shows you the connection between squeezelite and LMS.

      Code:
      tc@piCorePlayerSCREEN:~$ netstat -t
      Active Internet connections (w/o servers)
      Proto Recv-Q Send-Q Local Address           Foreign Address         State
      tcp        0      0 192.168.1.15:48962      192.168.1.6:3483        ESTABLISHED
      tcp        0    160 192.168.1.15:ssh        192.168.1.16:54966      ESTABLISHED
      tcp        0      0 192.168.1.15:46816      192.168.1.6:9000        ESTABLISHED
      netstat: /proc/net/tcp6: No such file or directory
      tc@piCorePlayerSCREEN:~$
      regards
      Greg
      ok greg, thank you very much.
      I describe what I want to run.
      I have many zero w work with windows lms server.
      yesterday I tested 4 synced zero w.
      at first I took #1 to master in settings.
      after that I disconnected each other during playing music to find out what is the action of the others about syncing. Everythings looked good.
      but at first when I brought back #2 zero w again during playing, it was not detected in lms and list.I restarted many times. not shown in lms.
      I went to setting menu and change a setting something like this of each player:
      "pause at power off, resume at power on"

      i dont know it is related or not but after doing this when each other brought back and turned on worked good.

      as i described my idea, I wanted to sure when each on is connected to lms when they turned off and turned on again, after that my led connected to gpio is going to be on to show zero w connected to server.
      (with sh bash scripting)
      I did it and turned on my led with by just checking wifi connection not checking zero w connected to lms server. I'm finding a way for this.

      maybe netstat is similar to ping command , good idea , I can check it by pinging lms ip address from zero w. but it needs to define static ip address for our logitech media server in network.
      main question is , is pinging trusty for my goal?
      I mean when it can ping lms server,
      lms server can show the player name and detected in its player list?
      maybe pinging is not related to detection process.
      I searched in squeezelite command line or parameters for a flag or Special characteristic is set when it connects to lms server.

      Comment

      • bpa
        Senior Member
        • Oct 2005
        • 22872

        #4
        You may need to start looking at using CLI and possibly JSON - it can ge complicated.

        Look at this thread for ideas. https://forums.slimdevices.com/showt...active-players

        Possible command are in the LMS technical information (webGUI Help / Technical Information / The Logitech Meda Server Command line interface or http://htmlpreview.github.io/?https:...s/cli-api.html )
        Last edited by bpa; 2019-02-01, 09:26.

        Comment

        • nimaazx
          Member
          • Jan 2019
          • 41

          #5
          Originally posted by bpa
          You may need to start looking at using CLI and possibly JSON - it can ge complicated.

          Look at this thread for ideas. https://forums.slimdevices.com/showt...active-players

          Possible command are in the LMS technical information (webGUI Help / Technical Information / The Logitech Meda Server Command line interface or http://htmlpreview.github.io/?https:...s/cli-api.html )

          thank you but I think it is for server side. for example this command for using to detect players state.

          <playerid> connected ?

          Returns the connected state of the player, 1 or 0 depending on the state of the TCP connection to the player. SLIMP3 players, since they use UDP, always return 1.

          Examples:

          Request: "04:20:00:12:23:45 connected ?<LF>"
          Response: "04:20:00:12:23:45 connected 1<LF>"

          i need something else, vice versa...
          detecting server status from client side (zero w)
          or detecting my zero w is connected to server.
          if connected led is going to be on.
          disconncted or lms server not found/led off.

          Comment

          • DJanGo
            Senior Member
            • Sep 2005
            • 2856

            #6
            hi,

            Originally posted by nimaazx
            ]
            maybe netstat is similar to ping command , good idea , I can check it by pinging lms ip address from zero w. but it needs to define static ip address for our logitech media server in network.
            main question is , is pinging trusty for my goal?
            no ping is nothing other than icmp works that doesnt help nobody
            A Server wihout a static ip is .... not a server
            Code:
            netstat -a|grep 3483|rev|cut -d ':' -f2-|cut -d ' ' -f1|rev
            Originally posted by nimaazx
            thank you but I think it is for server side. for example this command for using to detect players state.

            <playerid> connected ?

            Returns the connected state of the player, 1 or 0 depending on the state of the TCP connection to the player. SLIMP3 players, since they use UDP, always return 1.
            ???????
            slimp3 <> picoreplayer
            WHAT is your goal?

            Comment

            • bpa
              Senior Member
              • Oct 2005
              • 22872

              #7
              Originally posted by nimaazx
              thank you but I think it is for server side. for example this command for using to detect players state.

              <playerid> connected ?

              Returns the connected state of the player, 1 or 0 depending on the state of the TCP connection to the player. SLIMP3 players, since they use UDP, always return 1.

              Examples:

              Request: "04:20:00:12:23:45 connected ?<LF>"
              Response: "04:20:00:12:23:45 connected 1<LF>"

              i need something else, vice versa...
              detecting server status from client side (zero w)
              or detecting my zero w is connected to server.
              if connected led is going to be on.
              disconncted or lms server not found/led off.
              The CLI command will be sent to the LMS server by the pie Zero w. This means there is a network connection between player Pi and LMS server Pi. The reponse to the command "connected" tells you the LMS Server can "see" the player and the TCP connection on port 3483 is OK and working. If player is not connected to LMS as seen by LMS then connected state will be zero - you can only get this result from a Pi zero W when the TCP connection to server Pi is OK - so you can be sure the network connection is OK but the player connection on port 3483 is not OK. You can use the "players" command to get a list of all known players and their connected status (i.e. whether a TCP port 3483 connection is active).

              The ability to make a telnet connection to CLI port on LMS - means the LMS server is OK - what more do you need ?
              Last edited by bpa; 2019-02-01, 20:30.

              Comment

              • nimaazx
                Member
                • Jan 2019
                • 41

                #8
                Originally posted by DJanGo
                hi,



                no ping is nothing other than icmp works that doesnt help nobody
                A Server wihout a static ip is .... not a server
                Code:
                netstat -a|grep 3483|rev|cut -d ':' -f2-|cut -d ' ' -f1|rev

                ???????
                slimp3 <> picoreplayer
                WHAT is your goal?
                I have not been much familiar with linux bash command.I must search before use them. I have to test this command tomorrow.
                but about slimp3 , that commands are on logitech media server document page. I think the client is not the matter what it is. Overall, I doubted how and where to use these commands.
                what commands in server side on my windows lms / or what commands must be written in zero w client sh bash.

                Comment

                • nimaazx
                  Member
                  • Jan 2019
                  • 41

                  #9
                  Originally posted by bpa
                  The CLI command will be sent to the LMS server by the pie Zero w. This means there is a network connection between player Pi and LMS server Pi. The reponse to the command "connected" tells you the LMS Server can "see" the player and the TCP connection on port 3483 is OK and working. If player is not connected to LMS as seen by LMS then connected state will be zero - you can only get this result from a Pi zero W when the TCP connection to server Pi is OK - so you can be sure the network connection is OK but the player connection on port 3483 is not OK. You can use the "players" command to get a list of all known players and their connected status (i.e. whether a TCP port 3483 connection is active).

                  The ability to make a telnet connection to CLI port on LMS - means the LMS server is OK - what more do you need ?

                  Ok, thank you very much.
                  I understood what you said. I'm really interested in details.
                  if I understand correclty , you tell that command can be run on zero w with sh scripting language.
                  i'm too confused about commands in a document page.

                  in easy solution i can just check wifi connection and turn on led. but as I tell you and you know that is maybe not reliable.

                  if you know , please tell me what commands are in a client side and what commands are in lms side.
                  how much I read documents i'm more confused.

                  as well as the telnet method you said is related to "<playerid>" command or is a separate method?

                  if i understand from you and another person in this topic said, we can just check tcp port "3483". it is used for connecting to lms. when it is connected , We are sure 100% it is known by lms server.

                  I'm really sorry about my english. it is not my native language.

                  Comment

                  • bpa
                    Senior Member
                    • Oct 2005
                    • 22872

                    #10
                    Originally posted by nimaazx
                    if i understand from you and another person in this topic said, we can just check tcp port "3483". it is used for connecting to lms. when it is connected , We are sure 100% it is known by lms server.
                    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:
                    [color=blue]telnet 192.168.1.250 9090[/color]
                    [color=red]Trying 192.168.1.250...
                    Connected to 192.168.1.250.
                    Escape character is '^]'[/color]
                    [color=blue]players[/color]
                    [color=red]players   count%3A2[/color]
                    [color=blue]players 0 1 connected[/color]
                    [color=red]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[/color]
                    [color=blue]7x:dx:3x:ax:3x:7x connected ?[/color]
                    [color=red]7x%3Adx%3A3x%3Aax%3A3x%3A7x connected 1[/color]
                    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

                    Comment

                    • DJanGo
                      Senior Member
                      • Sep 2005
                      • 2856

                      #11
                      Originally posted by bpa
                      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.

                      Comment

                      • bpa
                        Senior Member
                        • Oct 2005
                        • 22872

                        #12
                        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:
                        [color=blue]curl -X POST -d '{"id":0,"params":["",["players"]],"method":"slim.request"}' http://192.168.1.250:9000/jsonrpc.js[/color]
                        [color=red]{"params":["",["players"]],"result":{"count":2},"id":0,"method":"slim.request"}[/color]
                        
                        [color=blue]curl -X POST -d '{"id":0,"params":["",["players","0","1","connected"]],"method":"slim.request"}' http://192.168.1.250:9000/jsonrpc.js[/color]
                        [color=red]{"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}]}}[/color]
                        Last edited by bpa; 2019-02-02, 12:52. Reason: typos

                        Comment

                        • paul-
                          Senior Member
                          • Jan 2013
                          • 5777

                          #13
                          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

                          Comment

                          • nimaazx
                            Member
                            • Jan 2019
                            • 41

                            #14
                            Originally posted by bpa
                            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:
                            [color=blue]telnet 192.168.1.250 9090[/color]
                            [color=red]Trying 192.168.1.250...
                            Connected to 192.168.1.250.
                            Escape character is '^]'[/color]
                            [color=blue]players[/color]
                            [color=red]players   count%3A2[/color]
                            [color=blue]players 0 1 connected[/color]
                            [color=red]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[/color]
                            [color=blue]7x:dx:3x:ax:3x:7x connected ?[/color]
                            [color=red]7x%3Adx%3A3x%3Aax%3A3x%3A7x connected 1[/color]
                            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, 20:22.

                            Comment

                            • Greg Erskine
                              Senior Member
                              • Sep 2006
                              • 2808

                              #15
                              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

                              Comment

                              Working...