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

    receiving actual state of PicorePlayer if playing or stopped

    Hello,
    I have a problem recognizing the playing or stopped state in order to set a GPIO.

    I studied this http://brianlawes.com/multi-zone-audio-system/

    And here is a script used for receiving player status.
    At the beginning of this script there a following lines:

    #!/bin/sh
    . /home/tc/www/cgi-bin/pcp-functions
    pcp_variables

    ##############################################
    # Set the following according to your setup
    ##############################################
    MAC_ADDR=ab:cd:ef:12:34:63 # Raspberry Pi MAC address Bad
    LMS_IP=192.168.0.229 # LMS IP address
    INTERVAL=0.5 # Set Poll interval
    GPIO=12 # Set GPIO for relay
    COMMAND="status 0 0" # LMS player status command
    DELAYOFF=20 # Delay in no. of intervals
    COUNT=0
    DEBUG=0
    TURNED_ON=0
    ##############################################

    After
    . /home/tc/www/cgi-bin/pcp-functions
    pcp_variables

    I become an
    sh: 3: unknown operand
    sh: 3: unknown operand
    which is coming from:

    pcp_config_file
    . $CONFIGCFG
    pcp_debug_log "$0 - Running pcp-functions..."
    pcp_variables

    ---->

    Always executing a function (I think) I become errors.
    I think, I have forgotten something in setup or so.

    Can anybody help me please?

  2. #2
    Senior Member DJanGo's Avatar
    Join Date
    Sep 2005
    Location
    Germany
    Posts
    2,483
    Quote Originally Posted by papa_arrugada View Post
    Hello,
    I have a problem recognizing the playing or stopped state in order to set a GPIO.
    Hi i have no idea about pcp...

    but the space between . and /home/tc/www/cgi-bin/pcp-functions looks very ....
    where is "pcp_variables" located? I would try to use the whole path to that script.

    But squeezelite supports -G and -S iam using these two parameters for my Rasbian not pcp running squeezeplayers and they do work.

  3. #3
    thank you for answering.

    eliminating blank is not working.

    I have a script calles "muteBack.sh" which
    activates the script pcp-functions
    and then the function "pcp_variables()" is called

    muteBack.sh
    tc@piCorePlayer:~$ ./muteBack.sh
    ./muteBack.sh: line 2: ./home/tc/www/cgi-bin/pcp-functions: not found
    ./muteBack.sh: line 3: pcp_variables: not found
    or with blank:

    #!/bin/sh
    . /home/tc/www/cgi-bin/pcp-functions
    pcp_variables

    ##############################################
    # Set the following according to your setup
    ##############################################
    MAC_ADDR=ab:cd:ef:12:34:63 # Raspberry Pi MAC address Bad
    LMS_IP=192.168.0.229 # LMS IP address
    INTERVAL=0.5 # Set Poll interval
    GPIO=12 # Set GPIO for relay
    COMMAND="status 0 0" # LMS player status command
    DELAYOFF=20 # Delay in no. of intervals
    COUNT=0
    DEBUG=0
    TURNED_ON=0
    ##############################################

    if [ $DEBUG = 1 ]; then
    echo
    echo "MAC_ADDR : "$MAC_ADDR
    echo "LMS_IP : "$LMS_IP
    echo "INTERVAL : "$INTERVAL
    echo "GPIO : "$GPIO
    echo "COMMAND : "$COMMAND
    echo "DELAYOFF : "$DELAYOFF
    echo
    fi

    get_mode() {
    RESULT=`( echo "$MAC_ADDR $COMMAND"; echo exit ) | nc $LMS_IP 9090`
    echo $RESULT | grep "mode%3Aplay" > /dev/null 2>&1
    if [ $? == 0 ]; then
    echo "Playing. Count: $COUNT"
    COUNT=0
    if [ $TURNED_ON == 0 ]; then
    turn_on
    fi
    else
    if [ $COUNT -ge $DELAYOFF ]; then
    if [ $TURNED_ON == 1 ]; then
    turn_off
    fi
    COUNT=0
    else
    COUNT=$(($COUNT + 1))
    echo "Stopped. Count: $COUNT"
    fi
    fi
    }

    turn_on() {
    sudo echo "0" > /sys/class/gpio/gpio$GPIO/value
    sleep .5
    sudo echo "1" > /sys/class/gpio/gpio$GPIO/value
    TURNED_ON=1
    }

    turn_off() {
    sudo echo "1" > /sys/class/gpio/gpio$GPIO/value
    sleep .5
    sudo echo "0" > /sys/class/gpio/gpio$GPIO/value
    TURNED_ON=0
    }
    ##############################################
    # Initial GPIO setup
    ##############################################

    #sudo chown tc /sys/class/gpio/export
    #sudo echo "24" > /sys/class/gpio/export
    #sudo chown -R tc /sys/class/gpio/gpio24/
    #sudo echo "1" > /sys/class/gpio/gpio24/value
    #sudo echo "out" > /sys/class/gpio/gpio24/direction
    #sudo echo "0" > /sys/class/gpio/gpio24/value

    sudo chown tc /sys/class/gpio/export
    sudo echo $GPIO > /sys/class/gpio/export
    sudo chown -R tc /sys/class/gpio/gpio$GPIO/
    # muting is active low
    #sudo echo "1" > /sys/class/gpio/gpio$GPIO/active_low
    sudo echo "0" > /sys/class/gpio/gpio$GPIO/value
    sudo echo "out" > /sys/class/gpio/gpio$GPIO/direction
    sudo echo "0" > /sys/class/gpio/gpio$GPIO/value


    ##############################################
    # Loop forever. This uses less than 1% CPU, so it should be OK.
    ##############################################
    while true
    do
    get_mode
    sleep $INTERVAL
    done

    pcp_variables() is located in /home/tc/www/cgi-bin/pcp-functions

    #!/bin/sh
    ....
    pcp_variables() {
    pcp_debug_log "$0 - Setting pcp_variables..."
    #================================================= ===================================
    .....

  4. #4
    and if I source n terminal I get the same error:

    [QUOTE]
    tc@piCorePlayer:~$ . /home/tc/www/cgi-bin/pcp-functions
    sh: 3: unknown operand
    tc@piCorePlayer:~$ ./home/tc/www/cgi-bin/pcp-functions
    -sh: ./home/tc/www/cgi-bin/pcp-functions: not found
    tc@piCorePlayer:~$ . www/cgi-bin/pcp-functions
    sh: 3: unknown operand
    tc@piCorePlayer:~$
    /QUOTE]

    this error comes from the call "pcp_variables" and "pcp_variables()" is located in the script "pcp-functions"

    at the beginning of "pcp-functions"
    there is

    #!/bin/sh

  5. #5
    Senior Member
    Join Date
    Apr 2008
    Location
    Paris, France
    Posts
    2,138
    Your script works under pcp 3.20.2, on a Pi 3
    I am logged in as user tc.
    I copy-pasted the code to a file and changed "#!/bin/sh" to "#!/bin/sh -x"
    Then I did "chmod +x foo.sh" to make it executable, I get this kind of stuff
    Code:
    $ ./foo.sh 
    + . /home/tc/www/cgi-bin/pcp-functions
    + DEBUGLOG=/var/log/pcp_debug.log
    + pcp_config_file
    + CONFIGCFG=/usr/local/sbin/config.cfg
    + . /usr/local/sbin/config.cfg
    + WIFI=off
    + SSID=wireless
    + PASSWORD=password
    + ENCRYPTION=WPA
    + DEBUG=0
    + MODE=40
    + TEST=0
    + NAME=Berlin-Boombox
    + OUTPUT=equal
    + ALSA_PARAMS=160:::1:
    + BUFFER_SIZE=
    ...
    + MAC_ADDR=ab:cd:ef:12:34:63
    + LMS_IP=192.168.0.229
    + INTERVAL=0.5
    + GPIO=12
    + COMMAND=status 0 0
    + DELAYOFF=20
    + COUNT=0
    + DEBUG=0
    + TURNED_ON=0
    If you run command "env" you can see all the variables pcp-variables has created for your script to use.
    The funny ". /home/tc/www/cgi-bin/pcp-functions" is more legibly written as "source /home/tc/www/cgi-bin/pcp-functions", that "merges" a script into another one. This is how your script can call "pcp-variables" right after that.

    BTW, do you need to poll player status via a script? In the GUI under Squeezelite Settings, bottom of page, there is provision to define a script or GPIO pins that SL will activate when player status transitions to power on or to power off.
    Last edited by epoch1970; 2017-12-05 at 16:31.
    3 SB 3 • Libratone Loop, Zipp Mini • iPeng (iPhone + iPad) • LMS 7.9 (linux) with plugins: CD Player, WaveInput, Triode's BBC iPlayer by bpa • IRBlaster by Gwendesign (Felix) • Server Power Control by Gordon Harris • Smart Mix, Music Walk With Me, What Was That Tune? by Michael Herger • PowerSave by Jason Holtzapple • Song Info, Song Lyrics by Erland Isaksson • AirPlay Bridge by philippe_44 • WeatherTime by Martin Rehfeld • Auto Dim Display, SaverSwitcher, ContextMenu by Peter Watkins.

  6. #6
    many thanks for your help.
    Yes, now I can run a script with "./foo.sh" from local directory or with "/home/tc/www/cgi-bin/pcp-functions" in that location.
    In the area of debug outputs I get a further "unknown command":

    + MODE_NORMAL=20
    + MODE_ADVANCED=30
    + MODE_BETA=40
    + MODE_DEVELOPER=100
    + INSITU_DOWNLOAD=http://picoreplayer.sourceforge.net/insitu
    + PCP_REPO=http://picoreplayer.sourceforge.net/tcz_repo
    + PICORE_REPO_1=http://repo.tinycorelinux.net/
    + PICORE_REPO_2=http://distro.ibiblio.org/tinycore/
    + [ -eq 3 ]
    sh: 3: unknown operand
    + [ -f /etc/sysconfig/tcedir/squeezelite ]
    + SQLT_BIN=/usr/local/bin/squeezelite
    + echo -e \r\033[K

    + echo -e \033[1;31m
    + RED=
    + echo -e \033[1;32m
    + GREEN=
    + echo -e \033[1;33m
    + YELLOW=
    How can I solve this?
    Is it necessary to change all used scripts from "#!/bin/sh" to "#!/bin/sh -x"?

    And to your proposal power on/off:
    Yes I know, thank you, this works.
    But I have 4 instances of player running (with 4 different mac addresses) and I want to read the actual state of special player to set a special GPIO pin for muting an external amplifier independently. I have 8 mono amps with mute inputs.

  7. #7
    Senior Member
    Join Date
    Apr 2008
    Location
    Paris, France
    Posts
    2,138
    "-x" is only there to make the script verbose. You should remove it when it works ok.
    I'm seeing "+ [ 0 -eq 3 ]", some variable is not set in your case, the script is a little careless and it goes into syntax error because it compares <nothing> with 3.
    My install is clean. I'll see what goes on in the script, or the log around the moment that test is performed.

    EDIT: After a short chase, I do have a line reading TEST="0" in file /usr/local/sbin/config.cfg.
    It looks like you're missing that line in your config.cfg file. Due to previous mods I suppose?
    3 SB 3 • Libratone Loop, Zipp Mini • iPeng (iPhone + iPad) • LMS 7.9 (linux) with plugins: CD Player, WaveInput, Triode's BBC iPlayer by bpa • IRBlaster by Gwendesign (Felix) • Server Power Control by Gordon Harris • Smart Mix, Music Walk With Me, What Was That Tune? by Michael Herger • PowerSave by Jason Holtzapple • Song Info, Song Lyrics by Erland Isaksson • AirPlay Bridge by philippe_44 • WeatherTime by Martin Rehfeld • Auto Dim Display, SaverSwitcher, ContextMenu by Peter Watkins.

  8. #8
    in /usr/local/sbin/config.cfg I have
    TEST=""

    I have changed to TEST="0" and the error is gone.
    Here my output:

    + /home/tc/www/cgi-bin/pcp-functions
    + DEBUGLOG=/var/log/pcp_debug.log
    + pcp_config_file
    + CONFIGCFG=/usr/local/sbin/config.cfg
    + . /usr/local/sbin/config.cfg
    + WIFI=off
    + SSID=wireless
    + PASSWORD=password
    + ENCRYPTION=WPA
    + DEBUG=0
    + MODE=40
    + TEST=0
    + NAME=Wohnzimmer
    + OUTPUT=equal
    + ALSA_PARAMS=80:::0:
    + BUFFER_SIZE=
    + _CODEC=
    + XCODEC=
    + PRIORITY=
    + MAX_RATE=
    + UPSAMPLE=
    + MAC_ADDRESS=ab:cd:ef:12:34:60
    + SERVER_IP=
    + LOGLEVEL=
    + LOGFILE=
    + DSDOUT=
    + VISUALISER=yes
    + CLOSEOUT=
    + UNMUTE=
    + ALSAVOLUME=
    + OTHER=
    + AUDIO=Analog
    + HOST=piCorePlayer
    + TIMEZONE=CET-1CEST,M3.5.0,M10.5.0/3
    + OVERCLOCK=NONE
    + ADVOVERCLOCK=None
    + CMD=Default
    + FIQ=0xF
    + ALSAlevelout=Default
    + ALSAeq=yes
    + REBOOT=Disabled
    + RB_H=0
    + RB_WD=*
    + RB_DMONTH=*
    + RESTART=Disabled
    + RS_H=0
    + RS_WD=*
    + RS_DMONTH=*
    + CRON_COMMAND=
    + AUTOSTARTLMS=
    + A_S_LMS=Disabled
    + AUTOSTARTFAV=
    + A_S_FAV=Disabled
    + USER_COMMAND_1=%2Fusr%2Flocal%2Fbin%2Fsqueezelite+-n+%27K%C3%BCche%27+-o+surround+-a+80%3A%3A%3A0%3A+-m+ab%3Acd%3Aef%3A12%3A34%3A61+-z
    + USER_COMMAND_2=%2Fusr%2Flocal%2Fbin%2Fsqueezelite+-n+%27Esszimmer%27+-o+center+-a+80%3A%3A%3A0%3A+-m+ab%3Acd%3Aef%3A12%3A34%3A62+-z
    + USER_COMMAND_3=%2Fusr%2Flocal%2Fbin%2Fsqueezelite+-n+%27Bad%27+-o+back+-a+80%3A%3A%3A0%3A+-m+ab%3Acd%3Aef%3A12%3A34%3A63+-z
    + JIVELITE=yes
    + SCREENROTATE=180
    + JL_SCREEN_WIDTH=0
    + JL_SCREEN_HEIGHT=0
    + SHAIRPORT=no
    + LMSERVER=no
    + LMSDATA=default
    + MOUNTPOINT=
    + MOUNTUUID=no
    + NETMOUNT1POINT=
    + NETMOUNT1=no
    + NETMOUNT1IP=
    + NETMOUNT1SHARE=
    + NETMOUNT1FSTYPE=
    + NETMOUNT1USER=
    + NETMOUNT1PASS=
    + NETMOUNT1OPTIONS=
    + SQLT_VERSION=basic
    + SQUEEZELITE=yes
    + POWER_GPIO=
    + POWER_OUTPUT=H
    + POWER_SCRIPT=
    + IR_LIRC=no
    + IR_GPIO_IN=25
    + IR_GPIO_OUT=
    + IR_DEVICE=lirc0
    + IR_CONFIG=
    + LMSWEBPORT=
    + FSM=Default
    + LMSCONTROLS=yes
    + PLAYERTABS=yes
    + HDMIPOWER=on
    + RPI3INTWIFI=on
    + SAMBA=disabled
    + WOL=no
    + WOL_NIC=
    + WOL_LMSMACADDRESS=
    + SPARAMS1=
    + SPARAMS2=
    + SPARAMS3=
    + SPARAMS4=
    + SPARAMS5=
    + INTERNET_CHECK_IP=
    + ROTDASH=no
    + pcp_debug_log /home/tc/www/cgi-bin/pcp-functions - Running pcp-functions...
    + [ 0 -ne 0 ]
    + pcp_variables
    + pcp_debug_log /home/tc/www/cgi-bin/pcp-functions - Setting pcp_variables...
    + [ 0 -ne 0 ]
    + cut -d /+ -f3readlink
    /etc/sysconfig/tcedir
    + TCEDEV=/dev/mmcblk0p2
    + readlink /etc/sysconfig/tcedir
    + cut -d / -f3
    + TCEMNT=/mnt/mmcblk0p2
    + BOOTDEV=/dev/mmcblk0p1
    + BOOTMNT=/mnt/mmcblk0p1
    + CONFIGTXT=/mnt/mmcblk0p1/config.txt
    + CMDLINETXT=/mnt/mmcblk0p1/cmdline.txt
    + BOOTLOCAL=/opt/bootlocal.sh
    + BOOTSYNC=/opt/bootsync.sh
    + SHUTDOWN=/opt/shutdown.sh
    + PB100=/home/tc/.local/bin/.pbtemp
    + HTTPDCONF=/home/tc/httpd.conf
    + HTTPD=/usr/local/sbin/busybox-httpd
    + ASOUNDCONF=/etc/asound.conf
    + WIFIDB=/home/tc/wifi.db
    + ONBOOTLST=/etc/sysconfig/tcedir/onboot.lst
    + VOLUME=/mnt/mmcblk0p1
    + DEVICE=/dev/mmcblk0p1
    + UPD_PCP=/tmp/upd_picoreplayer
    + PCPHOME=/home/tc/www/cgi-bin
    + LOGDIR=/var/log
    + PACKAGEDIR=/etc/sysconfig/tcedir/optional
    + SAMBACONF=/usr/local/etc/samba/smb.conf
    + USBMOUNTCONF=/usr/local/etc/pcp/usbmounts.conf
    + NETMOUNTCONF=/usr/local/etc/pcp/netmounts.conf
    + MODE_INITIAL=0
    + MODE_BASIC=10
    + MODE_NORMAL=20
    + MODE_ADVANCED=30
    + MODE_BETA=40
    + MODE_DEVELOPER=100
    + INSITU_DOWNLOAD=http://picoreplayer.sourceforge.net/insitu
    + PCP_REPO=http://picoreplayer.sourceforge.net/tcz_repo
    + PICORE_REPO_1=http://repo.tinycorelinux.net/
    + PICORE_REPO_2=http://distro.ibiblio.org/tinycore/
    + [ 0 -eq 3 ]
    + [ -f /etc/sysconfig/tcedir/squeezelite ]
    + SQLT_BIN=/usr/local/bin/squeezelite
    + echo -e \r\033[K

    + echo -e \033[1;31m
    + RED=
    + echo -e \033[1;32m
    + GREEN=
    + echo -e \033[1;33m
    + YELLOW=
    + echo -e \033[1;34m
    + BLUE=
    + echo -e \033[1;35m
    + MAGENTA=
    + echo -e \033[1;36m
    + CYAN=
    + echo -e \033[1;37m
    + WHITE=
    + echo -e \033[0;39m
    + NORMAL=
    + BLACKTRIANGLE=▲
    + BLACKTRIANGLEDOWN=▼
    + BLACKTRIANGLELEFT=◄
    + BLACKTRIANGLERIGHT=►
    + DEGREE_SIGN=&deg;
    + EXTERNALLINK=↗
    + FILLEDSAMLLSQUARE=◼
    + HEAVY_CHECK_MARK=✔
    + HEAVY_BALLOT_X=✘
    now I only have the problem of getting the actual mode/state of a special player.
    Any further ideas?

    my script "muteBack.sh" looks like

    tc@piCorePlayer:~$ cat muteBack.sh
    #!/bin/sh -x
    /home/tc/www/cgi-bin/pcp-functions
    #pcp_variables

    ##############################################
    # Set the following according to your setup
    ##############################################
    MAC_ADDR=ab:cd:ef:12:34:63 # Raspberry Pi MAC address Bad
    LMS_IP=192.168.0.229 # LMS IP address
    INTERVAL=0.5 # Set Poll interval
    GPIO=12 # Set GPIO for relay
    COMMAND="status 0 0" # LMS player status command
    DELAYOFF=20 # Delay in no. of intervals
    COUNT=0
    DEBUG=0
    TURNED_ON=0
    ##############################################

    if [ $DEBUG = 1 ]; then
    echo
    echo "MAC_ADDR : "$MAC_ADDR
    echo "LMS_IP : "$LMS_IP
    echo "INTERVAL : "$INTERVAL
    echo "GPIO : "$GPIO
    echo "COMMAND : "$COMMAND
    echo "DELAYOFF : "$DELAYOFF
    echo
    fi

    get_mode() {
    RESULT=`( echo "$MAC_ADDR $COMMAND"; echo exit ) | nc $LMS_IP 9002`
    echo $RESULT | grep "mode%3Aplay" > /dev/null 2>&1
    if [ $? == 0 ]; then
    echo "Playing. Count: $COUNT"
    COUNT=0
    if [ $TURNED_ON == 0 ]; then
    turn_on
    fi
    else
    if [ $COUNT -ge $DELAYOFF ]; then
    if [ $TURNED_ON == 1 ]; then
    turn_off
    fi
    COUNT=0
    else
    COUNT=$(($COUNT + 1))
    echo "Stopped. Count: $COUNT"
    fi
    fi
    }

    turn_on() {
    sudo echo "0" > /sys/class/gpio/gpio$GPIO/value
    sleep .5
    sudo echo "1" > /sys/class/gpio/gpio$GPIO/value
    TURNED_ON=1
    }

    turn_off() {
    sudo echo "1" > /sys/class/gpio/gpio$GPIO/value
    sleep .5
    sudo echo "0" > /sys/class/gpio/gpio$GPIO/value
    TURNED_ON=0
    }
    ##############################################
    # Initial GPIO setup
    ##############################################

    #sudo chown tc /sys/class/gpio/export
    #sudo echo "24" > /sys/class/gpio/export
    #sudo chown -R tc /sys/class/gpio/gpio24/
    #sudo echo "1" > /sys/class/gpio/gpio24/value
    #sudo echo "out" > /sys/class/gpio/gpio24/direction
    #sudo echo "0" > /sys/class/gpio/gpio24/value

    sudo chown tc /sys/class/gpio/export
    sudo echo $GPIO > /sys/class/gpio/export
    sudo chown -R tc /sys/class/gpio/gpio$GPIO/
    # muting is active low
    #sudo echo "1" > /sys/class/gpio/gpio$GPIO/active_low
    sudo echo "0" > /sys/class/gpio/gpio$GPIO/value
    sudo echo "out" > /sys/class/gpio/gpio$GPIO/direction
    sudo echo "0" > /sys/class/gpio/gpio$GPIO/value


    ##############################################
    # Loop forever. This uses less than 1% CPU, so it should be OK.
    ##############################################
    while true
    do
    get_mode
    sleep $INTERVAL
    done

    tc@piCorePlayer:~$

  9. #9
    Senior Member
    Join Date
    Apr 2008
    Location
    Paris, France
    Posts
    2,138
    This "RESULT=`( echo "$MAC_ADDR $COMMAND"; echo exit ) | nc $LMS_IP 9002`" could be your problem.
    "nc" doesn't work the same on every platform.
    Is the CLI listening on port 9002 ? (why?)

    In the console on the pi try
    Code:
    echo "<PLAYER_MAC> status 0 0" | nc <LMS_IP> <LMS_CLI_PORT>
    and see if you get anything back.

    Good luck.
    3 SB 3 • Libratone Loop, Zipp Mini • iPeng (iPhone + iPad) • LMS 7.9 (linux) with plugins: CD Player, WaveInput, Triode's BBC iPlayer by bpa • IRBlaster by Gwendesign (Felix) • Server Power Control by Gordon Harris • Smart Mix, Music Walk With Me, What Was That Tune? by Michael Herger • PowerSave by Jason Holtzapple • Song Info, Song Lyrics by Erland Isaksson • AirPlay Bridge by philippe_44 • WeatherTime by Martin Rehfeld • Auto Dim Display, SaverSwitcher, ContextMenu by Peter Watkins.

  10. #10
    Senior Member paul-'s Avatar
    Join Date
    Jan 2013
    Posts
    969
    Quote Originally Posted by epoch1970 View Post
    EDIT: After a short chase, I do have a line reading TEST="0" in file /usr/local/sbin/config.cfg.
    It looks like you're missing that line in your config.cfg file. Due to previous mods I suppose?
    No, we are aware of the issue, just ignore it if it comes back, that wont cause any other problems, other than a nuisance message.

    I glanced at the script, I don't know why you need to load anything from pcp-functions. Also, you do know that squeezelite can manage the GPIO toggle for you.
    Last edited by paul-; 2017-12-06 at 09:44.

Posting Permissions

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