Skip to content

Commit

Permalink
Add cfgPvMinTime for a minimum charging time
Browse files Browse the repository at this point in the history
  • Loading branch information
steff393 committed May 20, 2023
1 parent 4403a32 commit 7b40650
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
8 changes: 5 additions & 3 deletions src/globalConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ uint8_t cfgPvLimStart; // PV charging: Target current needed for
uint8_t cfgPvLimStop; // PV charging: Target current to stop charging when below (in 0.1A)
uint8_t cfgPvPhFactor; // PV charging: Power/Current factor, e.g. 69: 1A equals 690W at 3phases, 23: 1A equals 230W at 1phase
uint16_t cfgPvOffset; // PV charging: Offset for the available power calculation (in W); can be used to assure that no/less current is consumed from net
uint8_t cfgPvInvert; // Invert the watt value (pos./neg.)
uint16_t cfgTotalCurrMax; // <don't use - still beta> Total current limit for load management (in 0.1A)
uint8_t cfgPvInvert; // PV charging: Invert the watt value (pos./neg.)
uint8_t cfgPvMinTime; // PV charging: Minimum activation time (in minutes), 0 to disable
uint16_t cfgTotalCurrMax; // Total current limit for load management (in 0.1A) - !! Additional fuse mandatory !!
uint8_t cfgHwVersion; // Selection of the used HW
uint8_t cfgWifiSleepMode; // Set sleep type for power saving, recomendation is 255 (=no influence) or 0 (=WIFI_NONE_SLEEP)
uint8_t cfgLoopDelay; // Delay [ms] at end of main loop, might have an impact on web server reactivitiy, default: 255 = inactive
Expand Down Expand Up @@ -146,7 +147,8 @@ void loadConfig() {
cfgPvLimStop = doc["cfgPvLimStop"] | 50;
cfgPvPhFactor = doc["cfgPvPhFactor"] | 69;
cfgPvOffset = doc["cfgPvOffset"] | 0UL;
cfgPvInvert = doc["cfgPvInvert"] | 0UL;
cfgPvInvert = doc["cfgPvInvert"] | 0L;
cfgPvMinTime = doc["cfgPvMinTime"] | 0L;
cfgTotalCurrMax = doc["cfgTotalCurrMax"] | 0UL;
cfgHwVersion = doc["cfgHwVersion"] | 15;
cfgWifiSleepMode = doc["cfgWifiSleepMode"] | 0;
Expand Down
5 changes: 3 additions & 2 deletions src/globalConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ extern uint8_t cfgPvLimStart; // PV charging: Target current need
extern uint8_t cfgPvLimStop; // PV charging: Target current to stop charging when below (in 0.1A)
extern uint8_t cfgPvPhFactor; // PV charging: Power/Current factor, e.g. 69: 1A equals 690W at 3phases, 23: 1A equals 230W at 1phase
extern uint16_t cfgPvOffset; // PV charging: Offset for the available power calculation (in W); can be used to assure that no/less current is consumed from net
extern uint8_t cfgPvInvert; // Invert the watt value (pos./neg.)
extern uint16_t cfgTotalCurrMax; // <don't use - still beta> Total current limit for load management (in 0.1A)
extern uint8_t cfgPvInvert; // PV charging: Invert the watt value (pos./neg.)
extern uint8_t cfgPvMinTime; // PV charging: Minimum activation time (in minutes), 0 to disable
extern uint16_t cfgTotalCurrMax; // Total current limit for load management (in 0.1A) - !! Additional fuse mandatory !!
extern uint8_t cfgHwVersion; // Selection of the used HW
extern uint8_t cfgWifiSleepMode; // Set sleep type for power saving, recomendation is 255 (=no influence) or 0 (=WIFI_NONE_SLEEP)
extern uint8_t cfgLoopDelay; // Delay [ms] at end of main loop, might have an impact on web server reactivitiy, default: 255 = inactive
Expand Down
18 changes: 13 additions & 5 deletions src/pvAlgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ const uint8_t m = 11;
#define BOXID 0 // only 1 box supported

RTCVars rtc; // used to memorize a few global variables over reset (not for cold boot / power on reset)
static uint32_t lastHandleCall = 0;

static uint32_t lastCall = 0;
static uint32_t lastActivation = 0; // timestamp of the recent switch-on (#71), to avoid to frequent on/off
static int32_t watt = 0; // power from powerfox API (neg. = 'Einspeisung', pos. = 'Bezug')
static int32_t availPowerPrev = 0; // availPower from previous cycle
static pvMode_t pvMode = PV_OFF;
Expand Down Expand Up @@ -51,7 +53,8 @@ void pvAlgo() {
targetCurr = 0;

// MIN+PV, don't switch off, but ...
if (pvMode == PV_MIN_PV) {
if ((pvMode == PV_MIN_PV) ||
(cfgPvMinTime != 0 && lastActivation != 0 && (millis() - lastActivation < ((uint32_t)cfgPvMinTime) * 60 * 1000))) { // also if MinTime not elapsed (#71)
targetCurr = content[BOXID][16]; // ... set minimal current configured in box
}
}
Expand All @@ -64,6 +67,11 @@ void pvAlgo() {
targetCurr = CURR_ABS_MAX;
}
}

if (actualCurr == 0 && targetCurr >= CURR_ABS_MIN) {
// switch on => remember timestamp for cfgPvMinTime (#71)
lastActivation = millis();
}
} else {
// no car connected
targetCurr = 0;
Expand Down Expand Up @@ -109,11 +117,11 @@ void pv_setup() {


void pv_loop() {
if ((millis() - lastHandleCall < (uint16_t)cfgPvCycleTime * 1000) || // avoid unnecessary frequent calls
if ((millis() - lastCall < (uint16_t)cfgPvCycleTime * 1000) || // avoid unnecessary frequent calls
(pvMode == PV_DISABLED)) {
return;
}
lastHandleCall = millis();
lastCall = millis();

// Call algo
if (pvMode > PV_OFF) { // PV algo active
Expand Down Expand Up @@ -149,5 +157,5 @@ pvMode_t pv_getMode() {
void pv_setMode(pvMode_t val) {
pvMode = val;
rtc.saveToRTC(); // memorize over reset
lastHandleCall = 0; // make sure to call pv_Algo() in the next pv_loop() call
lastCall = 0; // make sure to call pv_Algo() in the next pv_loop() call
}

0 comments on commit 7b40650

Please sign in to comment.