remove stuff from blonk

master
Bryan 2021-01-01 23:16:46 -06:00
parent 270299ca8b
commit 4f2996c7e2
1 changed files with 5 additions and 172 deletions

177
blonk.sh
View File

@ -32,13 +32,6 @@ TEMPERATURE_PRINT=
UPTIME_VALUE= UPTIME_VALUE=
IP_CURRENT=
IP_LAST=
IP_DOMAIN=
RESET_PRESSED=
RESET_GPIO_PRESSED=
BLINK_GPIO_STATE=0 BLINK_GPIO_STATE=0
@ -52,10 +45,6 @@ REPORT_TXT=
read_config(){ read_config(){
RESET_ENABLED=
RESET_GPIO=
RESET_GPIO_VALUE=0
BATTERY_SHUT_VALUE= BATTERY_SHUT_VALUE=
BATTERY_WARN_VALUE= BATTERY_WARN_VALUE=
BATTERY_WARN_GPIO= BATTERY_WARN_GPIO=
@ -66,16 +55,7 @@ read_config(){
TEMPERATURE_WARN_GPIO= TEMPERATURE_WARN_GPIO=
TEMPERATURE_WARN_GPIO_VALUE=0 TEMPERATURE_WARN_GPIO_VALUE=0
BLINK_ENABLED= BLINK_ENABLED=
BLINK_GPIO=
IP_CHANGE_CHECK= # Monitor the external ip of the chip. Might be slow on some connections
IP_CHANGE_WARN= # Warn if ip changes.
IP_COMPARE_DOMAIN= # Use a domain directing to your ip. Will use machine's recorded last ip if commented.
IP_UPDATE_DDNS= # Path to a program to update your domain if your ip is changed
if [ -f /usr/local/etc/blonk.cfg ]; then : if [ -f /usr/local/etc/blonk.cfg ]; then :
source /usr/local/etc/blonk.cfg source /usr/local/etc/blonk.cfg
@ -94,18 +74,8 @@ check_i2c_installed(){
fi fi
} }
check_gpio_installed(){ blonk_cleanup(){
if [ ! -f /usr/local/bin/gpio.sh ]; then : return 0
blonk_error "need /usr/local/bin/gpio.sh for GPIO feature" "See https://github.com/fordsfords/gpio_sh/tree/gh-pages"
fi
}
blonk_cleanup(){ #unexports used gpio
# Only un-export ports that we actually exported.
if [ -n "$RESET_GPIO" ]; then gpio_unexport $RESET_GPIO; fi
if [ -n "$BLINK_GPIO" ]; then gpio_unexport $BLINK_GPIO; fi
if [ -n "$BATTERY_WARN_GPIO" ]; then gpio_unexport $BATTERY_WARN_GPIO; fi
if [ -n "$TEMPERATURE_WARN_GPIO" ]; then gpio_unexport $TEMPERATURE_WARN_GPIO; fi
} }
blonk_stop(){ blonk_stop(){
@ -123,46 +93,6 @@ blonk_error(){
exit 1 exit 1
} }
setup_gpio(){
if [ -n "$RESET_GPIO" ]; then :
gpio_export $RESET_GPIO; ST=$?
if [ $ST -ne 0 ]; then :
blonk_error "cannot export $RESET_GPIO for monitoring"
fi
gpio_direction $RESET_GPIO in
fi
if [ -n "$BLINK_GPIO" ]; then :
gpio_export $BLINK_GPIO; ST=$?
if [ $ST -ne 0 ]; then :
blonk_error "cannot export $BLINK_GPIO for blinking (in use?)"
fi
gpio_direction $BLINK_GPIO out
GPIO_LED=1
gpio_output $BLINK_GPIO 0
fi
if [ -n "$BATTERY_WARN_GPIO" ]; then :
gpio_export $BATTERY_WARN_GPIO; ST=$?
if [ $ST -ne 0 ]; then :
blonk_error "cannot export $BATTERY_WARN_GPIO for blinking (in use?)"
fi
gpio_direction $BATTERY_WARN_GPIO out
gpio_output $BATTERY_WARN_GPIO 0
fi
if [ -n "$TEMPERATURE_WARN_GPIO" ]; then :
gpio_export $TEMPERATURE_WARN_GPIO; ST=$?
if [ $ST -ne 0 ]; then :
blonk_error "cannot export $TEMPERATURE_WARN_GPIO for blinking (in use?)"
fi
gpio_direction $TEMPERATURE_WARN_GPIO out
gpio_output $TEMPERATURE_WARN_GPIO 0
fi
}
read_AXP(){ #reads values from the power ic read_AXP(){ #reads values from the power ic
@ -282,17 +212,6 @@ read_AXP(){ #reads values from the power ic
} }
read_reset(){ #reads the reset button
if [ -n "$RESET_ENABLED" ]; then :
REG=$(i2cget -y -f 0 0x34 0x4a) # Read AXP209 register 4AH
BUTTON=$(( $REG & 0x02 )) # mask off the short press bit
if [ $BUTTON -eq 0 ]; then :
RESET_PRESSED=0
else :
RESET_PRESSED=1
fi
fi
}
read_stats(){ #reads cpu stats read_stats(){ #reads cpu stats
CPU='-' CPU='-'
@ -306,21 +225,6 @@ read_stats(){ #reads cpu stats
} }
read_gpio(){
echo
}
read_ip(){
IP_CURRENT=`host myip.opendns.com resolver1.opendns.com | awk '/has address/ { print $4 }'`
#echo $IP_CURRENT
if [ -n "$IP_COMPARE_DOMAIN" ]; then :
IP_DOMAIN=`host $IP_COMPARE_DOMAIN resolver1.opendns.com | awk '/has address/ { print $4 }'`
IP_LAST=$IP_DOMAIN
#echo $IP_DOMAIN
fi
}
compile_report(){ compile_report(){
txt_PWR="Not Connected" txt_PWR="Not Connected"
@ -345,7 +249,6 @@ compile_report(){
read -r -d '' REPORT_TXT << EOM read -r -d '' REPORT_TXT << EOM
$UPTIME_VALUE $UPTIME_VALUE
ip: $IP_CURRENT
Temp: $TEMPERATURE_PRINT°C Temp: $TEMPERATURE_PRINT°C
Batt: $BATTERY_VALUE% $BATTERY_STATE Batt: $BATTERY_VALUE% $BATTERY_STATE
@ -358,15 +261,6 @@ EOM
} }
ext_update_ddns(){
if [ -n "$IP_UPDATE_DDNS" ]; then :
echo "update dns"
update_ddns
fi
}
WARN_TEMP=0 WARN_TEMP=0
WARN_BATT=0 WARN_BATT=0
WARN_POWR=0 WARN_POWR=0
@ -420,21 +314,6 @@ compile_warnings(){
} }
manage_ip(){
#changed ip
WARN_IP=0
if [[ "$IP_CURRENT" != "$IP_LAST" ]]; then
WARN_IP=1
IP_LAST=$IP_CURRENT
echo "changed ip"
echo "last ip "$IP_LAST
echo $IP_CURRENT
ext_update_ddns
fi
#echo $WARN_IP
#ext_update_ddns
}
handle_warnings(){ handle_warnings(){
echo echo
@ -445,43 +324,12 @@ gpio_output $BLINK_GPIO $BLINK_GPIO_STATE
BLINK_GPIO_STATE=$((1-BLINK_GPIO_STATE)) BLINK_GPIO_STATE=$((1-BLINK_GPIO_STATE))
} }
##############--------------------------------------------------------------------------------##############
echo "blonk: starting"
echo
if [ "$1" == "" ]; then
SERVICE=true
elif [ "$1" == "-tg" ]; then
TELEGRAM=true
elif [ "$1" == "-tgW" ]; then
#TELEGRAM=true
WARNINGS=true
elif [ "$1" == "-p" ]; then
PRINT=true
elif [ "$1" == "-r" ]; then
REBOOT=true
elif [ "$1" == "-h" ]; then
cat << EOF
Usage: blonk.sh runs as service or [OPTION]
-p Prints information once
-b Show only battery percentage
-v Version
-h Help (This help)
EOF
elif [ "$1" == "-v" ]; then
echo "Version 1.2 (Feb 28th, 2020)"
exit 0
fi
check_i2c_installed check_i2c_installed
######################################### #########################################
read_config read_config
read_AXP read_AXP
read_stats read_stats
#read_gpio
#read_ip
compile_report compile_report
compile_warnings compile_warnings
@ -496,14 +344,6 @@ fi
exit 0 exit 0
fi fi
#########################################
#check_gpio_installed
#if [ -f /usr/local/bin/gpio.sh ]; then :
# source /usr/local/bin/gpio.sh
#fi
#setup_gpio
trap "blonk_stop" 1 2 3 15 trap "blonk_stop" 1 2 3 15
######################################### #########################################
@ -511,7 +351,7 @@ fi
LAST_TIME_SENSORS=`date +%s` LAST_TIME_SENSORS=`date +%s`
#LAST_TIME_IP=`date +%s` #LAST_TIME_IP=`date +%s`
if [ $SERVICE ]; then # if [ $SERVICE ]; then
while true; do : while true; do :
TIME=`date +%s` TIME=`date +%s`
@ -532,17 +372,10 @@ fi
sleep 0.1 sleep 0.1
fi fi
#if (( $TIME > $LAST_TIME_IP )); then #read and handle ip change
# #echo "reading IP"
# read_ip
# manage_ip
# LAST_TIME_IP=$((TIME+IP_READ_FREQUENCY))
# #echo $LAST_TIME_IP
#fi
blink blink
sleep $BLINK_FREQUENCY_HALF sleep $BLINK_FREQUENCY_HALF
blink blink
sleep $BLINK_FREQUENCY_HALF sleep $BLINK_FREQUENCY_HALF
done done
fi # fi