Feature request picoreplayer: Play state to GPIO

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aki7
    Member
    • Dec 2017
    • 59

    Feature request picoreplayer: Play state to GPIO

    Hi,

    maybe i have overseen some threat here, otherwise maybe a new useful feature:

    "When PiCorePlayer is playing a GPIO Port ist pulled up or down"

    My use case: Swithing the Amp with the already configurable "Power GPIO" i would like to use a second GPIO to switch a two way relay for toggling the line input of the amp to external source, when picoreplayer is paused.

    Thanks and
    best Regards
    Axel
  • Greg Erskine
    Senior Member
    • Sep 2006
    • 2807

    #2
    hi Aki7,

    This should be possible with a simple shell script. People have been doing similar things to a drive LEDs etc.

    Use wiringPi to set GPIO (or shell commands).

    Use $pcp mode to determine if squeezelite is play/stop.

    I assume you know about the hardware for a relay. A GPIO can not drive a relay directly.

    In the home directory there are a couple of scripts that should give you some ideas.




    regards
    Greg

    Comment

    • Aki7
      Member
      • Dec 2017
      • 59

      #3
      Hi Greg,

      thanks for the fast response. Relays used already, no problem with this.

      Need some help with:

      On play -> GPIO high
      On pause -> GPIO low

      Event driven. So i think in my small knowledge, squeezelite code has to be changed. I am not a linux freak, but lot of programming in former days.

      Axel

      Comment

      • Greg Erskine
        Senior Member
        • Sep 2006
        • 2807

        #4
        hi Axel,

        Although not a good as an interrupt solution a simple loop inquiry of LMS may be OK.

        The command "pcp mode" returns "play" or "stop". Do the inquiry every second and set relay appropriate. This only create a 1% load on CPU and little network traffic, not enough to cause problems.

        regards
        Greg

        Comment

        • paul-
          Senior Member
          • Jan 2013
          • 5675

          #5
          The code used to be almost that way, but it was causing more problems than anything. So it was changed to what it is now.

          I would recommend installing the powersave plugin to LMS and that will power down your player if it is paused for a period of time.

          *Edit* read the OP, we are not doing two GPIO's, so you need to use the script method Greg mentioned, or build your own version of squeezelite. Source code is here



          Take a look at gpio.c and then also look at all sections of the code flagged with #if GPIO

          You can also have a look at the commit https://github.com/ralph-irving/sque...c6dff0283a05a1 that removed the gpio trigger on a pause event.
          Last edited by paul-; 2019-03-06, 00:59.
          piCorePlayer a small player for the Raspberry Pi in RAM.
          Homepage: https://www.picoreplayer.org

          Please donate if you like the piCorePlayer

          Comment

          • Aki7
            Member
            • Dec 2017
            • 59

            #6
            Hi Greg, hi Paul,

            thanks for your input.

            @Greg: Polling from the LMS ... feels not so elegant for me ;-) and will result in delayed sound on play start in my use case. There seems to be some code, discussed on this forum. Not shure if it has worked finally.
            @Paul: Have taken a look at your 2nd link. Maybe my misunderstanding, but i would like to set a GPIO according to play state, not reading a GPIO and doing something afterwards.
            I have neither linux nor c knowledge, so creating my own fork seems not so realistic for me :-) Anyway, do you have a hint, in which module squeezelite is receiving commands from the LMS? My idea would be first stage, writing or deleting a file (or some flag variable) according to play state. So polling this file or "global environment variable" could be done asynchron by other modules, local on the "machine". Maybe every 1/10 s.

            Setting the GPIO synchron from squeezelite may have introduced some timing problems? On the other hand, there should be time enough, when squeezelite changes his play state.

            regards
            Axel

            Comment

            • paul-
              Senior Member
              • Jan 2013
              • 5675

              #7
              All you would need to do is initialize a second GPIO and then track the pause state. But if you don't know C programming, then your going to have to be at the mercy of someone wanting to do this for you.
              piCorePlayer a small player for the Raspberry Pi in RAM.
              Homepage: https://www.picoreplayer.org

              Please donate if you like the piCorePlayer

              Comment

              • Aki7
                Member
                • Dec 2017
                • 59

                #8
                Paul,

                yes. Therefore the "feature request". I can only hope and pray to the c lords :-)

                Axel

                Comment

                • Greg Erskine
                  Senior Member
                  • Sep 2006
                  • 2807

                  #9
                  hi Aki7,

                  FYI: Although we use squeezelite, it is used by lots of other "players" and is really maintained separately from piCorePlayer. We have been very lucky to have Ralphy as part of the pCP Team, but his squeezelite work covers all the other platforms.

                  regards
                  Greg

                  Comment

                  • Aki7
                    Member
                    • Dec 2017
                    • 59

                    #10
                    Greg: Ok, so i understand: Little hope for this feature, only useable with GPIO devices.

                    Paul: Thanks for the hints, sounds easy. Do you know if the „play state“ is published by squeezelite in any form for usage from other modules? Or: Can a script „request“ the play state from squeezelite?

                    Can i support the experts on the solution for this problem, f.e. with some bottles of good wine? :-)

                    Axel

                    Comment

                    • mgraves
                      Senior Member
                      • Feb 2006
                      • 155

                      #11
                      Play state to IFTTT (or similar)

                      I like the idea of tracking play state. I have several pi core players using HiFi Berry Pro XLR. These are connected to powered monitors around my home. The Pi is powered over Ethernet, so always powered on.

                      I'd like to use the play state of the Pi to trigger a remote controlled outlet to turn on the speakers. I already have the Amazon outlets that works with Alexa. So, an IFTTT action should be able to do this.

                      Sadly, I am not a developer. I'll need some help.
                      Michael Graves

                      House: RPi3 + HifiBerry Pro XLR, M-Audio BX5As
                      Home Office: RPi3 + HifiBerry Pro XLR, M-Audio BX5A D2, Berhringer B2092A subwoofer
                      Workshop: RPi3 + HifiBerry Pro XLR, Alesis M520 Active
                      Back Yard: RPi3 + HifiBerry DAC2, Dayton Amp, Definitive Tech AW6500s
                      Front Yard: RPi3 + HiFiBerry Amp2, Definitive Tech AW5500s
                      LMS via PiCorePlayer on Pi400

                      email: mgraves <at> mstvp.com
                      blog: http://www.mgraves.org

                      Comment

                      • DJanGo
                        Senior Member
                        • Sep 2005
                        • 2856

                        #12
                        Originally posted by mgraves
                        Sadly, I am not a developer. I'll need some help.
                        Make some script like amp_power.sh with something that powers the wifi-plug.

                        eg: (made for a Tasmota driven device without using mqtt "for this example" -in real life its using mqtt instead of curl)
                        Code:
                        #!/bin/bash
                        port=9090
                        server=lms.server.ip.address
                        muzzigbox=ma:ca:dd:re:ss from the used player
                        amp=IP.of.your.wifiswitch
                        now=$(date +%H:%M)
                        up=$(ps aux |grep squeezelite |grep -v grep|awk '{print $9}')
                        if [ ! "$now" == "$up"  ]
                           then
                           sleep 2
                           status=$(printf "$muzzigbox mode ?\nexit\n" | nc $server $port | cut -d ' ' -
                           if [ $status = play ]
                                 then
                                 curl http://$amp/cm?cmnd=Power%20ON
                           else
                                 curl http://$amp/cm?cmnd=Power%20OFF
                           fi
                        else
                                echo detect startup
                                printf "$muzzigbox power 0 \nexit\n"|nc $server $port
                                curl http://$amp/cm?cmnd=Power%20OFF
                        fi
                        Use this script or similar for your -S option in squeezelite

                        Take a look at this Thread

                        The first script poweres the amp on / off if you press the powerbutton on the lms gui/ power the squeezelite player in any way.
                        The 2.nd script that should run each xx minutes as a cronjob "unpowers the squeezeliteplayer if its not playing anymore" and that power cycle starts the poweroff for your Amp.

                        Comment

                        • mgraves
                          Senior Member
                          • Feb 2006
                          • 155

                          #13
                          Originally posted by DJanGo
                          Take a look at this Thread

                          The first script poweres the amp on / off if you press the powerbutton on the lms gui/ power the squeezelite player in any way.
                          The 2.nd script that should run each xx minutes as a cronjob "unpowers the squeezeliteplayer if its not playing anymore" and that power cycle starts the poweroff for your Amp.
                          Thanks for the info!

                          I'm not concerned about powering off the plugin. That can be set up occur automatically on a scheduled basis. That is, turn it off every night at 11pm.
                          Michael Graves

                          House: RPi3 + HifiBerry Pro XLR, M-Audio BX5As
                          Home Office: RPi3 + HifiBerry Pro XLR, M-Audio BX5A D2, Berhringer B2092A subwoofer
                          Workshop: RPi3 + HifiBerry Pro XLR, Alesis M520 Active
                          Back Yard: RPi3 + HifiBerry DAC2, Dayton Amp, Definitive Tech AW6500s
                          Front Yard: RPi3 + HiFiBerry Amp2, Definitive Tech AW5500s
                          LMS via PiCorePlayer on Pi400

                          email: mgraves <at> mstvp.com
                          blog: http://www.mgraves.org

                          Comment

                          • sakos
                            Member
                            • Jul 2020
                            • 31

                            #14
                            Originally posted by Greg Erskine
                            hi Axel,

                            Although not a good as an interrupt solution a simple loop inquiry of LMS may be OK.

                            The command "pcp mode" returns "play" or "stop". Do the inquiry every second and set relay appropriate. This only create a 1% load on CPU and little network traffic, not enough to cause problems.

                            regards
                            Greg
                            Do you happen to know why "pcp mode" does not distinguish "stop" and "power off" state? It returns "stop" in either state.

                            Code:
                            tc@Konyha:~$ pcp play
                            tc@Konyha:~$ pcp mode
                            play
                            tc@Konyha:~$ pcp pause
                            tc@Konyha:~$ pcp mode
                            pause
                            tc@Konyha:~$ pcp stop
                            tc@Konyha:~$ pcp mode
                            stop
                            tc@Konyha:~$ pcp play
                            tc@Konyha:~$ pcp mode
                            play
                            tc@Konyha:~$ pcp power off
                            tc@Konyha:~$ pcp mode
                            stop
                            tc@Konyha:~$
                            Last edited by sakos; 2020-08-07, 17:47. Reason: add output

                            Comment

                            • Greg Erskine
                              Senior Member
                              • Sep 2006
                              • 2807

                              #15
                              hi sakos,

                              Generally speaking the "pcp commands" are only a simple interface into LMS commands. They can only respond as LMS responds.

                              Having said that, reading the documentation we should get an "undefined" value. Maybe we have coded a default value of stop.

                              Code:
                              <playerid> mode ?
                              
                              The "mode" command allows to query the player state and returns one of "play", "stop" or "pause". If the player is off, "mode ?" returned value is undefined.
                              
                              Example:
                              
                              Request: "04:20:00:12:23:45 mode ?<LF>"
                              Response: "04:20:00:12:23:45 mode stop<LF>"
                              I have added your post to the list of things todo.

                              regards
                              Greg

                              Comment

                              Working...