diff --git a/processautolock.sh b/processautolock.sh index 42c72b622..f23e54df9 100755 --- a/processautolock.sh +++ b/processautolock.sh @@ -37,98 +37,121 @@ powerLp5=$( $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 diff --git a/regel.sh b/regel.sh index c785d0de2..3b1866e01 100755 --- a/regel.sh +++ b/regel.sh @@ -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. # @@ -71,133 +71,7 @@ if (( updateinprogress == "1" )); then fi # process autolock -# sets variables necessary due to inconsistent naming -powerLp1=$( $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 &