Skip to content

Commit

Permalink
moved processautolock from regel.sh to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
MiOrt committed Jan 26, 2020
1 parent 5c80ba8 commit 67a95b7
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 192 deletions.
151 changes: 87 additions & 64 deletions processautolock.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,98 +37,121 @@ powerLp5=$(<ramdisk/llaktuelllp5)
powerLp6=$(<ramdisk/llaktuelllp6)
powerLp7=$(<ramdisk/llaktuelllp7)
powerLp8=$(<ramdisk/llaktuelllp8)
isConfiguredLp1="1"
isConfiguredLp2=$lastmanagement
isConfiguredLp3=$lastmanagements2
isConfiguredLp4=$lastmanagementlp4
isConfiguredLp5=$lastmanagementlp5
isConfiguredLp6=$lastmanagementlp6
isConfiguredLp7=$lastmanagementlp7
isConfiguredLp8=$lastmanagementlp8

# some stuff
time=$(date +%H:%M)
# process current time
timeOfDay=$(date +%H:%M)
dayOfWeek=$(date +%u) # 1 = Montag
now=$(date +'%Y-%m-%d %H:%M:%S'); # timestamp just for logging
second=$(date +%S)

echo "${now} processing regel.sh"

if [ "$second" -lt "20" ]; then
# once a minute at new minute check if (un)lock-time is up
echo "${now} processing if-then once a minute"

for chargePoint in {1..8}
do
variableConfiguredName="isConfiguredLp${chargePoint}" # name of variable for lp configured
if [ "${!variableConfiguredName}" = "1" ]; then
# charge point is configured, so process it
flagFilename="/var/www/html/openWB/ramdisk/waitautolocklp${chargePoint}" # name of variable for lp wait-to-lock
lpFilename="/var/www/html/openWB/ramdisk/lp${chargePoint}enabled" # name of variable for lpenable
locktimeSettingName="lockTimeLp${chargePoint}_${dayOfWeek}" # name of variable of lock time for today

if [ -z "${!locktimeSettingName}" ]; then
# variable is not defined in config file (or empty)
lockTime="" # so set the lock time to empty string
else
lockTime="${!locktimeSettingName}" # get the lock time from config file
fi

# now process the settings...
lpenabled=$(<$lpFilename) # read ramdisk value for lp enabled
now=$(date +'%Y-%m-%d %H:%M:%S'); # timestamp just for logging
if [ "$lpenabled" = "1" ]; then
echo "${now} LP${chargePoint} is enabled"
# if the charge point is enabled, check for auto disabling
if [ $timeOfDay = "$lockTime" ]; then
echo "${now} autolock time for LP${chargePoint} is up"
# auto lock time is now, set flag
echo "1" > $flagFilename
fi
fi
fi
done
fi

function checkDisableLp {
powerVarName="powerLp${chargePoint}"
now=$(date +'%Y-%m-%d %H:%M:%S');
if [ "${!powerVarName}" -lt "200" ]; then
# charge point stopped charging ... less than 200 W
# delete possible wait-to-lock-flag
# charge point still charging
# delete wait-to-lock-flag
echo "0" > $flagFilename
# and disable charge point
mqttTopic="openWB/set/lp$chargePoint/ChargePointEnabled"
mosquitto_pub -r -t $mqttTopic -m 0
echo "${now} auto-disabled charge point #${chargePoint}"
echo "${now} autolock charge point #${chargePoint}"
else
echo "${now} no auto-disable charge point #${chargePoint}, still charging: ${!powerVarName} W"
echo "${now} no autolock charge point #${chargePoint}, still charging: ${!powerVarName} W"
fi
}

for chargePoint in {1..8}
do
lpFilename="/var/www/html/openWB/ramdisk/lp${chargePoint}enabled" # name of variable for lpenable
flagFilename="/var/www/html/openWB/ramdisk/waitautolocklp${chargePoint}" # name of variable for lp wait-to-lock
unlocktimeSettingName="unlockTimeLp${chargePoint}_${dayOfWeek}" # name variable of unlock time for today
locktimeSettingName="lockTimeLp${chargePoint}_${dayOfWeek}" # name of variable of lock time for today
waitUntilFinishedName="waitUntilFinishedBoxLp${chargePoint}" # name variable of checkbox value
# every 10 seconds check if flag is set to disable charge point
# or if unlock time is up
variableConfiguredName="isConfiguredLp${chargePoint}" # name of variable for lp configured
if [ "${!variableConfiguredName}" = "1" ]; then
# charge point is configured, so process it

if [ -z "${!unlocktimeSettingName}" ]; then
# variable is not defined in settings (or empty)
unlockTime="" # so set the unlock time to empty string
else
unlockTime="${!unlocktimeSettingName}" # get the unlock time from setting
fi
flagFilename="/var/www/html/openWB/ramdisk/waitautolocklp${chargePoint}" # name of variable for lp wait-to-lock
unlocktimeSettingName="unlockTimeLp${chargePoint}_${dayOfWeek}" # name variable of unlock time for today
waitUntilFinishedName="waitUntilFinishedBoxLp${chargePoint}" # name variable of checkbox value

if [ -z "${!locktimeSettingName}" ]; then
# variable is not defined in settings (or empty)
lockTime="" # so set the lock time to empty string
else
lockTime="${!locktimeSettingName}" # get the lock time from setting
fi
if [ -z "${!unlocktimeSettingName}" ]; then
# variable is not defined in settings (or empty)
unlockTime="" # so set the unlock time to empty string
else
unlockTime="${!unlocktimeSettingName}" # get the unlock time from setting
fi

if [ -z "${!waitUntilFinishedName}" ]; then
# variable is not defined in settings (or empty)
waitUntilFinished="off" # so set the value to 'dont wait'
else
waitUntilFinished="${!waitUntilFinishedName}" # get the checkbox-value from setting
fi
if [ -z "${!waitUntilFinishedName}" ]; then
# variable is not defined in settings (or empty)
waitUntilFinished="off" # so set the value to 'dont wait'
else
waitUntilFinished="${!waitUntilFinishedName}" # get the checkbox-value from setting
fi

# now process the settings...
lpenabled=$(<$lpFilename) # read ramdisk value for lp enabled
now=$(date +'%Y-%m-%d %H:%M:%S');
if [ "$lpenabled" = "1" ]; then
# if the charge point is enabled, check for auto disabling
waitFlag=$(<$flagFilename) # read ramdisk value for lp autolock wait flag
# now process the settings...
now=$(date +'%Y-%m-%d %H:%M:%S'); # timestamp just for logging
waitFlag=$(<$flagFilename) # read ramdisk value for autolock wait flag
if [ "$waitFlag" = "1" ]; then
echo "${now} wait flag found for charge point #${chargePoint}"
# charge point busy, locktime passed and waiting for end of charge to disable charge point
if [ $time = "$unlockTime" ]; then
# auto unlock time is now, so delete possible wait-to-lock-flag
# charge point waiting for lock
echo "${now} charge point #${chargePoint} waiting for autolock"
if [ $timeOfDay = "$unlockTime" ]; then
# but auto unlock time is now, so delete possible wait-to-lock-flag
echo "${now} unlock time for charge point #${chargePoint}: disable wait for autolock"
echo "0" > $flagFilename
else
# unlock time not reached and waiting for auto lock
# check if charge point still busy to deactivate
# unlock time not now and waiting for auto lock
# check if charge point still busy to lock
checkDisableLp
fi
else
# not waiting for disabling, so check if autolock time arrived
if [ $time = "$lockTime" ]; then
# auto lock time is now
if [ $waitUntilFinished = "on" ]; then
# but if charging is ongoing, wait until finished
# so set flag to wait for charge point ending ongoing charging process
echo "1" > $flagFilename
echo "${now} set wait flag for charge point #${chargePoint}"
# check if charge point still busy to deactivate
checkDisableLp
else
# disable charge point immediately
mqttTopic="openWB/set/lp$chargePoint/ChargePointEnabled"
mosquitto_pub -r -t $mqttTopic -m 0
echo "${now} auto-disabled charge point #${chargePoint} without wait"
fi
fi
fi
else
if [ $time = "$unlockTime" ]; then
# charge point disabled and auto unlock time is now, so enable charge point
if [ $timeOfDay = "$unlockTime" ]; then
# unlock time is now, so enable charge point
mqttTopic="openWB/set/lp$chargePoint/ChargePointEnabled"
mosquitto_pub -r -t $mqttTopic -m 1
echo "${now} auto-enabled charge point #${chargePoint}"
echo "${now} auto unlock charge point #${chargePoint}"
fi
fi
done
130 changes: 2 additions & 128 deletions regel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#
# File: regel.sh
#
# Copyright 2018 Kevin Wieland, David Meder-Marouelli, Michael Ortenstein
# Copyright 2018 Kevin Wieland, David Meder-Marouelli
#
# This file is part of openWB.
#
Expand Down Expand Up @@ -71,133 +71,7 @@ if (( updateinprogress == "1" )); then
fi

# process autolock
# sets variables necessary due to inconsistent naming
powerLp1=$(<ramdisk/llaktuell)
powerLp2=$(<ramdisk/llaktuells1)
powerLp3=$(<ramdisk/llaktuells2)
powerLp4=$(<ramdisk/llaktuelllp4)
powerLp5=$(<ramdisk/llaktuelllp5)
powerLp6=$(<ramdisk/llaktuelllp6)
powerLp7=$(<ramdisk/llaktuelllp7)
powerLp8=$(<ramdisk/llaktuelllp8)
isConfiguredLp1="1"
isConfiguredLp2=$lastmanagement
isConfiguredLp3=$lastmanagements2
isConfiguredLp4=$lastmanagementlp4
isConfiguredLp5=$lastmanagementlp5
isConfiguredLp6=$lastmanagementlp6
isConfiguredLp7=$lastmanagementlp7
isConfiguredLp8=$lastmanagementlp8

# process current time
timeOfDay=$(date +%H:%M)
dayOfWeek=$(date +%u) # 1 = Montag
now=$(date +'%Y-%m-%d %H:%M:%S'); # timestamp just for logging
second=$(date +%S)

echo "${now} processing regel.sh"

if [ "$second" -lt "20" ]; then
# once a minute at new minute check if (un)lock-time is up
echo "${now} processing if-then once a minute"

for chargePoint in {1..8}
do
variableConfiguredName="isConfiguredLp${chargePoint}" # name of variable for lp configured
if [ "${!variableConfiguredName}" = "1" ]; then
# charge point is configured, so process it
flagFilename="/var/www/html/openWB/ramdisk/waitautolocklp${chargePoint}" # name of variable for lp wait-to-lock
lpFilename="/var/www/html/openWB/ramdisk/lp${chargePoint}enabled" # name of variable for lpenable
locktimeSettingName="lockTimeLp${chargePoint}_${dayOfWeek}" # name of variable of lock time for today

if [ -z "${!locktimeSettingName}" ]; then
# variable is not defined in config file (or empty)
lockTime="" # so set the lock time to empty string
else
lockTime="${!locktimeSettingName}" # get the lock time from config file
fi

# now process the settings...
lpenabled=$(<$lpFilename) # read ramdisk value for lp enabled
now=$(date +'%Y-%m-%d %H:%M:%S'); # timestamp just for logging
if [ "$lpenabled" = "1" ]; then
echo "${now} LP${chargePoint} is enabled"
# if the charge point is enabled, check for auto disabling
if [ $timeOfDay = "$lockTime" ]; then
echo "${now} autolock time for LP${chargePoint} is up"
# auto lock time is now, set flag
echo "1" > $flagFilename
fi
fi
fi
done
fi

function checkDisableLp {
powerVarName="powerLp${chargePoint}"
if [ "${!powerVarName}" -lt "200" ]; then
# charge point still charging
# delete wait-to-lock-flag
echo "0" > $flagFilename
# and disable charge point
mqttTopic="openWB/set/lp$chargePoint/ChargePointEnabled"
mosquitto_pub -r -t $mqttTopic -m 0
echo "${now} autolock charge point #${chargePoint}"
else
echo "${now} no autolock charge point #${chargePoint}, still charging: ${!powerVarName} W"
fi
}

for chargePoint in {1..8}
do
# every 10 seconds check if flag is set to disable charge point
# or if unlock time is up
variableConfiguredName="isConfiguredLp${chargePoint}" # name of variable for lp configured
if [ "${!variableConfiguredName}" = "1" ]; then
# charge point is configured, so process it

flagFilename="/var/www/html/openWB/ramdisk/waitautolocklp${chargePoint}" # name of variable for lp wait-to-lock
unlocktimeSettingName="unlockTimeLp${chargePoint}_${dayOfWeek}" # name variable of unlock time for today
waitUntilFinishedName="waitUntilFinishedBoxLp${chargePoint}" # name variable of checkbox value

if [ -z "${!unlocktimeSettingName}" ]; then
# variable is not defined in settings (or empty)
unlockTime="" # so set the unlock time to empty string
else
unlockTime="${!unlocktimeSettingName}" # get the unlock time from setting
fi

if [ -z "${!waitUntilFinishedName}" ]; then
# variable is not defined in settings (or empty)
waitUntilFinished="off" # so set the value to 'dont wait'
else
waitUntilFinished="${!waitUntilFinishedName}" # get the checkbox-value from setting
fi

# now process the settings...
now=$(date +'%Y-%m-%d %H:%M:%S'); # timestamp just for logging
waitFlag=$(<$flagFilename) # read ramdisk value for autolock wait flag
if [ "$waitFlag" = "1" ]; then
# charge point waiting for lock
echo "${now} charge point #${chargePoint} waiting for autolock"
if [ $timeOfDay = "$unlockTime" ]; then
# but auto unlock time is now, so delete possible wait-to-lock-flag
echo "${now} unlock time for charge point #${chargePoint}: disable wait for autolock"
echo "0" > $flagFilename
else
# unlock time not now and waiting for auto lock
# check if charge point still busy to lock
checkDisableLp
fi
fi
if [ $timeOfDay = "$unlockTime" ]; then
# unlock time is now, so enable charge point
mqttTopic="openWB/set/lp$chargePoint/ChargePointEnabled"
mosquitto_pub -r -t $mqttTopic -m 1
echo "${now} auto unlock charge point #${chargePoint}"
fi
fi
done
./processautolock.sh &

#ladelog ausfuehren
./ladelog.sh &
Expand Down

0 comments on commit 67a95b7

Please sign in to comment.