Skip to content

Commit

Permalink
neues Layout, Umstellung auf DarkSky API, Fehlerbehebungen
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoh88 committed Jul 24, 2018
1 parent 75f6d59 commit b1bf441
Show file tree
Hide file tree
Showing 22 changed files with 1,599 additions and 565 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -1,2 +1,7 @@

.DS_Store
_Bugs
_SVGs
_climacons-master
_112082-weather-linear
cron_kindle-wetter_preprocess_defs.txt
Binary file added Kindle/180405/weatherdata-bad.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Kindle/180405/weatherdata-wohnzimmer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Kindle/weatherbattery.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Kindle/weatherdata-bad.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Kindle/weatherdata-wohnzimmer.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Kindle/weatherdata.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Kindle/weathererror.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Kindle/weathererror_image.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Kindle/weathererror_network.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Kindle/weathererror_wlan.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
293 changes: 167 additions & 126 deletions Kindle/weatherscript.sh
Expand Up @@ -5,7 +5,7 @@
#######################################################

###########
### Install
### Install
## mkdir /mnt/us/scripts
## chmod 700 /mnt/us/scripts/weatherscript.sh
## mntroot rw
Expand All @@ -15,39 +15,41 @@
# Variables
NAME=weatherscript
SCRIPTDIR="/mnt/us/scripts"
LOG="$SCRIPTDIR/$NAME.log"
LOG="${SCRIPTDIR}/${NAME}.log"
SUSPENDFOR=900 # Default, flexibel by F5INTWORKDAY and F5INTWEEKEND
NET="wlan0"

LIMG="$SCRIPTDIR/weatherdata.png"
LIMGERR="$SCRIPTDIR/weathererror.png"
LIMGBATT="$SCRIPTDIR/weatherbattery.png"
LIMG="${SCRIPTDIR}/weatherdata.png"
LIMGBATT="${SCRIPTDIR}/weatherbattery.png"
LIMGERR="${SCRIPTDIR}/weathererror_image.png"
LIMGERRWLAN="${SCRIPTDIR}/weathererror_wlan.png"
LIMGERRNET="${SCRIPTDIR}/weathererror_network.png"

RSRV="192.168.1.10"
RIMG="$RSRV/kindle-weather/weatherdata.png"
RSH="$RSRV/kindle-weather/$NAME.sh"
RIMG="${RSRV}/kindle-weather/weatherdata.png"
RSH="${RSRV}/kindle-weather/${NAME}.sh"
RPATH="/var/www/html/kindle-weather"

ROUTERIP="192.168.1.1" # Workaround, forget default gateway after STR
#ROUTERIP="192.168.254.254" # Workaround, forget default gateway after STR


F5INTWORKDAY="\
06,07,08,15,16,17,18,19|900
06,07,08,15,16,17,18,19|900
05,09,10,11,12,13,14,20,21|1800
22,23,00,01,02,03,04|3600" # Refreshintervall for workdays = 57 Refreshes per workday

F5INTWEEKEND="\
06,07,08,15,16,17,18,19|900
06,07,08,15,16,17,18,19|900
05,09,10,11,12,13,14,20,21|1800
22,23,00,01,02,03,04|3600" # Refreshintervall for weekends = 57 Refreshes per weekend day

SMSACTIV=1
PLAYSMSUSER="admin"
PLAYSMSPW="abcdef0123456789abcdef0123456789"
PLAYSMSURL="https://192.168.1.10/playsms/index.php"
PLAYSMSPW="00998877665544332211ffeeddccbbaa"
PLAYSMSURL="http://192.168.1.10/playsms/index.php"

CONTACTPAGERS="\
0049171XXXXXXX|Nico
0049151XXXXXXXX|Michele"
0049123456789|Nico
0049987654321|Michele"


##############
Expand All @@ -71,14 +73,14 @@ wait_wlan() {
}

send_sms () {
for LINE in $CONTACTPAGERS; do
CONTACTPAGER=`echo $LINE | awk -F\| '{print $1}'`
CONTACTPAGERNAME=`echo $LINE | awk -F\| '{print $2}'`
for LINE in ${CONTACTPAGERS}; do
CONTACTPAGER=`echo ${LINE} | awk -F\| '{print $1}'`
CONTACTPAGERNAME=`echo ${LINE} | awk -F\| '{print $2}'`

SMSTEST=`echo ${MESSAGE} | sed 's/ /%20/g'`
#curl -s "${SMSURL_START}&text=${SMSTEST}&${SMSURL_END}&to=${CONTACTPAGER}" > /dev/null
curl -s -k "${PLAYSMSURL}?app=ws&u=${PLAYSMSUSER}&h=${PLAYSMSPW}&op=pv&to=${CONTACTPAGER}&msg=${SMSTEST}" > /dev/null
echo "`date '+%Y-%m-%d_%H:%M:%S'` | SMS an ${CONTACTPAGERNAME} versendet!"
#curl --silent --insecure "${PLAYSMSURL}?app=ws&u=${PLAYSMSUSER}&h=${PLAYSMSPW}&op=pv&to=${CONTACTPAGER}&msg=${SMSTEST}" > /dev/null
curl --silent "${PLAYSMSURL}?app=ws&u=${PLAYSMSUSER}&h=${PLAYSMSPW}&op=pv&to=${CONTACTPAGER}&msg=${SMSTEST}" > /dev/null
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | SMS an ${CONTACTPAGERNAME} versendet!" >> ${LOG} 2>&1
done
}

Expand All @@ -90,151 +92,190 @@ send_sms () {
NOTIFYBATTERY=0
REFRESHCOUNTER=0

IP=`ifconfig ${NET} | grep "inet addr" | cut -d':' -f2 | awk '{print $1}'`
HOSTNAME=`nslookup ${IP} | grep Address | grep ${IP} | awk '{print $4}' | awk -F. '{print $1}'`
if [ -z "${HOSTNAME}" ]; then
HOSTNAME="recently-reboot"
fi

### Kill Kindle processes
kill_kindle

### Loop
while true; do

### Start
echo "================================================" >> $LOG 2>&1

### Check Batterystate
CHECKBATTERY=`gasgauge-info -s`
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Batteriezustand: $CHECKBATTERY%" >> $LOG 2>&1
if [ ${CHECKBATTERY} -le 5 ] && [ ${NOTIFYBATTERY} -eq 0 ]; then
NOTIFYBATTERY=1
if [ ${SMSACTIV} -eq 1 ]; then
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Batteriezustand kritisch, SMS werden verschickt!" >> $LOG 2>&1
MESSAGE="Der Batteriezustand von $HOSTNAME ist kritisch ($CHECKBATTERY) - bitte laden!"
send_sms
else
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Batteriezustand kritisch" >> $LOG 2>&1
fi
fi
if [ ${CHECKBATTERY} -gt 80 ]; then
NOTIFYBATTERY=0
fi
if [ ${CHECKBATTERY} -eq 1 ]; then
eips -f -g "$LIMGBATT"
echo "mem" > /sys/power/state
fi
echo "================================================" >> ${LOG} 2>&1

### Enable CPU Powersave
CHECKCPUMODE=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor | grep -i "powersave"`
CHECKCPUMODE=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor | grep -i "powersave"`
if [ ${CHECKCPUMODE} -eq 0 ]; then
echo powersave > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
echo "`date '+%Y-%m-%d_%H:%M:%S'` | CPU runtergetaktet" >> $LOG 2>&1
fi
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | CPU runtergetaktet." >> ${LOG} 2>&1
fi

### Disable Screensaver, no energysaving by powerd
### Disable Screensaver, no energysaving by powerd
# powerd buggy since 5.4.5 - https://www.mobileread.com/forums/showthread.php?t=235821
CHECKSAVER=`lipc-get-prop com.lab126.powerd status | grep -i "prevent_screen_saver:0"`
if [ ${CHECKSAVER} -eq 0 ]; then
lipc-set-prop com.lab126.powerd preventScreenSaver 1 >> $LOG 2>&1
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Standard Energiesparmodus deaktiviert" >> $LOG 2>&1
fi

### Enable WLAN
lipc-set-prop com.lab126.wifid enable 1 >> $LOG 2>&1

### Wait on WLAN
WLANCOUNTER=0
while wait_wlan; do
if [ ${WLANCOUNTER} -gt 30 ]; then
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Leider kein bekanntes WLAN verfügbar" >> $LOG 2>&1
break
fi
let WLANCOUNTER=WLANCOUNTER+1
sleep 1
done

### Workaround Default Gateway after STR
GATEWAY=`ip route | grep default | grep $NET | awk '{print $3}'`
if [ -z "$GATEWAY" ]; then
route add default gw $ROUTERIP >> $LOG 2>&1
lipc-set-prop com.lab126.powerd preventScreenSaver 1 >> ${LOG} 2>&1
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Standard Energiesparmodus deaktiviert." >> ${LOG} 2>&1
fi

### Check new Script
# wget (-N) can't https
LMTIMESH=`stat -c %Y "$SCRIPTDIR/$NAME.sh"`
curl --silent --time-cond "$SCRIPTDIR/$NAME.sh" --output "$SCRIPTDIR/$NAME.sh" http://$RSH
RMTIMESH=`stat -c %Y "$SCRIPTDIR/$NAME.sh"`
if [ $RMTIMESH -gt $LMTIMESH ]; then
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Skript aktualisiert, Neustart durchführen" >> $LOG 2>&1
chmod 777 "$SCRIPTDIR/$NAME.sh"
reboot
exit
fi

### HOSTNAME & IP
IP=`ifconfig $NET | grep "inet addr" | cut -d':' -f2 | awk '{print $1}'`
HOSTNAME=`nslookup $IP | grep Address | grep $IP | awk '{print $4}' | awk -F. '{print $1}'`

### Get new Weatherdata
# wget can't https
if [ "${HOSTNAME}" = "kindle-kt3-schwarz" ]; then
RIMG="$RSRV/kindle-weather/weatherdata-bad.png"
fi
if [ "${HOSTNAME}" = "kindle-kt3-weiss" ]; then
RIMG="$RSRV/kindle-weather/weatherdata-wohnzimmer.png"
### Check Batterystate
CHECKBATTERY=`gasgauge-info -s`
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Batteriezustand: ${CHECKBATTERY}%" >> ${LOG} 2>&1
if [ ${CHECKBATTERY} -gt 80 ]; then
NOTIFYBATTERY=0
fi

let REFRESHCOUNTER=REFRESHCOUNTER+1
if curl --silent --output "$LIMG" "http://$RIMG"; then
if [ ${REFRESHCOUNTER} -ne 5 ]; then
eips -g "$LIMG"
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Wetterbild aktualisiert" >> $LOG 2>&1
else
eips -f -g "$LIMG"
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Wetterbild und E-Ink aktualisiert" >> $LOG 2>&1
REFRESHCOUNTER=0
fi
else
eips -f -g "$LIMGERR"
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Wetterbild nicht aktualisiert" >> $LOG 2>&1
if [ ${CHECKBATTERY} -le 1 ]; then
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Batteriezustand 1%, statisches Batteriezustandsbild gesetzt, WLAN deaktivert, Ruhezustand!" >> ${LOG} 2>&1
eips -f -g "${LIMGBATT}"
lipc-set-prop com.lab126.wifid enable 0
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo "mem" > /sys/power/state
fi

### Disable WLAN
# No stable "wakealarm" with enabled WLAN
lipc-set-prop com.lab126.wifid enable 0 >> $LOG 2>&1

### Set SUSPENDFOR
# no regex in if with /bin/sh
# no regex in if with /bin/sh
DAYOFWEEK=`date +%u` # 1=Monday
HOURNOW=`date +%H` # Hour
# Workdays
if [ ${DAYOFWEEK} -ge 1 ] && [ ${DAYOFWEEK} -le 5 ]; then
for LINE in $F5INTWORKDAY; do
HOURS=`echo $LINE | awk -F\| '{print $1}'`
for LINE in ${F5INTWORKDAY}; do
HOURS=`echo ${LINE} | awk -F\| '{print $1}'`
echo "${HOURS}" | grep ${HOURNOW} > /dev/null 2>&1
if [ $? -eq 0 ]; then
SUSPENDFOR=`echo $LINE | awk -F\| '{print $2}'`
echo "$SUSPENDFOR"
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Aufwachintervall auf $SUSPENDFOR gesetzt" >> $LOG 2>&1
SUSPENDFOR=`echo ${LINE} | awk -F\| '{print $2}'`
echo "${SUSPENDFOR}"
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Aufwachintervall für den nächsten Ruhezustand auf ${SUSPENDFOR} gesetzt." >> ${LOG} 2>&1
fi
done
fi
# Weekend
if [ ${DAYOFWEEK} -ge 6 ] && [ ${DAYOFWEEK} -le 7 ]; then
for LINE in $F5INTWEEKEND; do
HOURS=`echo $LINE | awk -F\| '{print $1}'`
for LINE in ${F5INTWEEKEND}; do
HOURS=`echo ${LINE} | awk -F\| '{print $1}'`
echo "${HOURS}" | grep ${HOURNOW} > /dev/null 2>&1
if [ $? -eq 0 ]; then
SUSPENDFOR=`echo $LINE | awk -F\| '{print $2}'`
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Aufwachintervall auf $SUSPENDFOR gesetzt" >> $LOG 2>&1
SUSPENDFOR=`echo ${LINE} | awk -F\| '{print $2}'`
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Aufwachintervall für den nächsten Ruhezustand auf ${SUSPENDFOR} gesetzt." >> ${LOG} 2>&1
fi
done
fi

# Set wakealarm
WAKEUPTIMER=$(( `date +%s` + $SUSPENDFOR ))
echo "`date '+%Y-%m-%d_%H:%M:%S'` | Aufwachzeitpunkt `date -d @$WAKEUPTIMER '+%Y-%m-%d_%H:%M:%S'`" >> $LOG 2>&1
### Calculation WAKEUPTIMER
WAKEUPTIMER=$(( `date +%s` + ${SUSPENDFOR} ))
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Aufwachzeitpunkt für den nächsten Ruhezustand `date -d @${WAKEUPTIMER} '+%Y-%m-%d_%H:%M:%S'`." >> ${LOG} 2>&1

### Enable WLAN
lipc-set-prop com.lab126.wifid enable 1 >> ${LOG} 2>&1
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | WLAN aktivieren." >> ${LOG} 2>&1

### Wait on WLAN
WLANNOTCONNECTED=0
WLANCOUNTER=0
while wait_wlan; do
if [ ${WLANCOUNTER} -gt 30 ]; then
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Leider kein bekanntes WLAN verfügbar." >> ${LOG} 2>&1
eips -f -g "${LIMGERRWLAN}"
WLANNOTCONNECTED=1
break
fi
let WLANCOUNTER=WLANCOUNTER+1
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Warte auf WLAN (Versuch ${WLANCOUNTER})." >> ${LOG} 2>&1
sleep 1
done

### Connected with WLAN?
if [ ${WLANNOTCONNECTED} -eq 0 ]; then

### Workaround Default Gateway after STR
GATEWAY=`ip route | grep default | grep ${NET} | awk '{print $3}'`
if [ -z "${GATEWAY}" ]; then
route add default gw ${ROUTERIP} >> ${LOG} 2>&1
fi

### Batterystate critical? SMS!
if [ ${CHECKBATTERY} -le 5 ] && [ ${NOTIFYBATTERY} -eq 0 ]; then
NOTIFYBATTERY=1
if [ ${SMSACTIV} -eq 1 ]; then
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Batteriezustand kritisch, SMS werden verschickt!" >> ${LOG} 2>&1
MESSAGE="Der Batteriezustand von ${HOSTNAME} ist kritisch (${CHECKBATTERY}%) - bitte laden!"
send_sms
else
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Batteriezustand kritisch." >> ${LOG} 2>&1
fi
fi

### Check new Script
# wget (-N) can't https
RSTATUSSH=`curl --silent --head "http://${RSH}" | head -n 1 | cut -d$' ' -f2`
if [ ${RSTATUSSH} -eq 200 ]; then
LMTIMESH=`stat -c %Y "${SCRIPTDIR}/${NAME}.sh"`
curl --silent --time-cond "${SCRIPTDIR}/${NAME}.sh" --output "${SCRIPTDIR}/${NAME}.sh" "http://${RSH}"
RMTIMESH=`stat -c %Y "${SCRIPTDIR}/${NAME}.sh"`
if [ ${RMTIMESH} -gt ${LMTIMESH} ]; then
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Skript aktualisiert, Neustart durchführen." >> ${LOG} 2>&1
chmod 777 "${SCRIPTDIR}/${NAME}.sh"
reboot
exit
fi
else
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Skript nicht gefunden (HTTP-Status ${RSTATUSSH})." >> ${LOG} 2>&1
fi

### Get new Weatherdata
# wget can't https
if [ "${HOSTNAME}" = "kindle-kt3-schwarz" ]; then
RIMG="${RSRV}/kindle-weather/weatherdata-bad.png"
fi
if [ "${HOSTNAME}" = "kindle-kt3-weiss" ]; then
RIMG="${RSRV}/kindle-weather/weatherdata-wohnzimmer.png"
fi

let REFRESHCOUNTER=REFRESHCOUNTER+1
RSTATUSIMG=`curl --silent --head "http://${RIMG}" | head -n 1 | cut -d$' ' -f2`
if [ ${RSTATUSIMG} -eq 200 ]; then
curl --silent --output "$LIMG" "http://${RIMG}"
if [ ${REFRESHCOUNTER} -ne 5 ]; then
eips -g "$LIMG"
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Wetterbild aktualisiert." >> ${LOG} 2>&1
else
eips -f -g "$LIMG"
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Wetterbild und E-Ink aktualisiert." >> ${LOG} 2>&1
REFRESHCOUNTER=0
fi
elif [ -z "${RSTATUSIMG}" ]; then
eips -f -g "$LIMGERRNET"
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Webserver reagiert nicht. Webserver läuft? Server erreichbar? Kindle mit dem WLAN verbunden?" >> ${LOG} 2>&1
else
eips -f -g "$LIMGERR"
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Wetterbild auf Webserver nicht gefunden (HTTP-Status ${RSTATUSSH})." >> ${LOG} 2>&1
fi

### Copy log by ssh
cat ${LOG} | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /mnt/us/scripts/id_rsa_kindle -l kindle ${RSRV} "cat >> ${RPATH}/${NAME}_${HOSTNAME}.log" > /dev/null 2>&1
if [ $? -eq 0 ]; then
rm ${LOG}
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Log per SSH an Remote-Server übergeben und lokal gelöscht." >> ${LOG} 2>&1
else
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Log konnte nicht an den Remote-Server übergeben werden." >> ${LOG} 2>&1
fi

fi

### Disable WLAN
# No stable "wakealarm" with enabled WLAN
lipc-set-prop com.lab126.wifid enable 0
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | WLAN deaktivieren." >> ${LOG} 2>&1

### Set wakealarm
echo 0 > /sys/class/rtc/rtc0/wakealarm
echo $WAKEUPTIMER > /sys/class/rtc/rtc0/wakealarm
echo ${WAKEUPTIMER} > /sys/class/rtc/rtc0/wakealarm

# Go into Suspend to Memory (STR)
### Go into Suspend to Memory (STR)
echo "`date '+%Y-%m-%d_%H:%M:%S'` | ${HOSTNAME} | Ruhezustand starten." >> ${LOG} 2>&1
echo "mem" > /sys/power/state

done
Binary file modified README.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b1bf441

Please sign in to comment.