paul- wrote:
> GPIO can be confusing, it seems nobody named them the same, so we are
> using the BCM pin numbers, I guess we could be more clear on that.
>
> so -G 13 will toggle BCM pin13 -> Physical pin 33 on the header
>
> If you are on physcial pin 13 on your rpi header, you will want to use
> "-G 27"
Thanks for that, but no I am on GPIO 13 (Pin 33)
The script that works fine is:-
Code:
--------------------
#!/bin/sh
# Version: 0.01 2014-11-28 GE
# Original.
#===========================================================================
# This script polls LMS at a regular interval to determine the current
# status of the Squeezelite process on piCorePlayer. i.e. play or stop.
#
# A GPIO is then set/reset depending on the result of this status check.
#
# There is an adjustable relay off delay that can be used as an inactivity
# timing.
#---------------------------------------------------------------------------
#===========================================================================
# Possible issues
#---------------------------------------------------------------------------
# 1. Initial relay status during booting. It is probably better to start
# this script before starting Squeezelite. Also, a pull-up or pull-down
# resistor may be needed to ensure initial state of GPIO.
# 2. If setting MAC address manually, pay close attention to the physical,
# wireless and fake MAC addresses.
# 3. This script hasn't been tested on synced players.
#---------------------------------------------------------------------------
#===========================================================================
# Test procedure
#---------------------------------------------------------------------------
# sudo killall relay.sh
# sudo sh -c 'echo "17" > /sys/class/gpio/unexport'
# sudo ./relay.sh > /dev/null &
#---------------------------------------------------------------------------
#Wait 1 minute on initial start for pcp_variables to become available
sleep 60
#set -x
. /home/tc/www/cgi-bin/pcp-functions
pcp_variables
#===========================================================================
# Set the following according to your setup
#---------------------------------------------------------------------------
#MAC_ADDR=xx:xx:xx:xx:xx:xx # Raspberry Pi MAC
address
MAC_ADDR=$(pcp_controls_mac_address) # Set by pCP
#LMS_IP=xxx.xxx.xxx.xxx # LMS IP address
LMS_IP=$(pcp_lmsip) # Set by pCP
INTERVAL=0.5 # Set Poll
interval
GPIO=13
# Set GPIO
COMMAND="status 0 0" # LMS player status
command
DELAYOFF=5 # Delay
in no. of intervals
CONDITION="power%3A1" # Define Condition to
query (Power)
#CONDITION="mode%3Aplay" # Define Condition to
query(Play/Stop)
COUNT=0
DEBUG=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 "$CONDITION" > /dev/null 2>&1
if [ $? == 0 ]; then
echo "Power On. Count: $COUNT"
COUNT=0
echo "1" > /sys/class/gpio/gpio$GPIO/value
else
if [ $COUNT -ge $DELAYOFF ]; then
echo "Stopped. Count: $COUNT"
echo "0" > /sys/class/gpio/gpio$GPIO/value
COUNT=0
else
#COUNT=`expr $COUNT + 1` #or
COUNT=$(($COUNT + 1))
echo "Power Off. Count: $COUNT"
fi
fi
}
#===========================================================================
# Initial GPIO setup
#---------------------------------------------------------------------------
sudo sh -c 'echo '"$GPIO"' > /sys/class/gpio/export'
sudo sh -c 'echo "out" > /sys/class/gpio/gpio'"$GPIO"'/direction'
# My relay is active low, so this reverses the logic
sudo sh -c 'echo "0" > /sys/class/gpio/gpio'"$GPIO"'/active_low'
echo "1" > /sys/class/gpio/gpio$GPIO/value
#---------------------------------------------------------------------------
#===========================================================================
# Loop forever. This uses less the 1% CPU, so it should be OK.
#---------------------------------------------------------------------------
while true
do
get_mode
sleep $INTERVAL
done
#---------------------------------------------------------------------------
--------------------
*Players:* SliMP3,Squeezebox3 x3,Receiver,SqueezePlayer,PiCorePlayer
x3,Wandboard
*Server:* LMS Version: 7.9.0 - 1453293926 on Centos 7 VM on ESXi 6 on HP
N54L
*Plugins:* AutoRescan/BBCiPlayer/PowerSave/PowerSwitchIII/Squeezecloud
*Remotes:* iPeng8/Orangesqueeze/PC/Jivelite
*Music:* 383GB,1269 albums 17756 songs 4381 artists mostly FLACs
*Want a webapp ?* See
http://forums.slimdevices.com/showthread.php?104305-Webapp-for-LMS
------------------------------------------------------------------------
Jeff07971's Profile: http://forums.slimdevices.com/member.php?userid=49290
View this thread: http://forums.slimdevices.com/showthread.php?t=105018
_______________________________________________
unix mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/unix