Fix PZEM stabilize period on larger configs

Fix PZEM stabilize period on larger configs (#18103)
This commit is contained in:
Theo Arends 2023-03-04 11:56:54 +01:00
parent 71e14d62fe
commit 6f44003cb5
6 changed files with 13 additions and 11 deletions

View File

@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
### Fixed
- TuyaMcu v1 sequence fix (#17625)
- TuyaMcu v1 timer integer overflow (#18048)
- PZEM energy monitor stabilize period on larger configs (#18103)
### Removed

View File

@ -134,3 +134,4 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
- IR panasonic protocol regression from v12.0.2.4 [#18013](https://github.com/arendst/Tasmota/issues/18013)
- EnergyTotal divided twice during minimal upgrade step regression from v12.3.1.3 [#18024](https://github.com/arendst/Tasmota/issues/18024)
- TuyaMcu v1 timer integer overflow [#18048](https://github.com/arendst/Tasmota/issues/18048)
- PZEM energy monitor stabilize period on larger configs [#18103](https://github.com/arendst/Tasmota/issues/18103)

View File

@ -30,7 +30,7 @@
#define XNRG_03 3
const uint32_t PZEM_STABILIZE = 30; // Number of seconds to stabilize configuration
const uint32_t PZEM_STABILIZE = 10; // Number of seconds to stabilize 1 pzem
const uint32_t PZEM_RETRY = 5; // Number of 250 ms retries
#include <TasmotaSerial.h>
@ -194,7 +194,7 @@ void PzemEvery250ms(void)
case 4: // Total energy as 99999Wh
Energy->import_active[Pzem.phase] = value / 1000.0f; // 99.999kWh
if (Pzem.phase == Energy->phase_count -1) {
if (TasmotaGlobal.uptime > PZEM_STABILIZE) {
if (TasmotaGlobal.uptime > (PZEM_STABILIZE * ENERGY_MAX_PHASES)) {
EnergyUpdateTotal();
}
}
@ -229,7 +229,7 @@ void PzemEvery250ms(void)
}
else {
Pzem.send_retry--;
if ((Energy->phase_count > 1) && (0 == Pzem.send_retry) && (TasmotaGlobal.uptime < PZEM_STABILIZE)) {
if ((Energy->phase_count > 1) && (0 == Pzem.send_retry) && (TasmotaGlobal.uptime < (PZEM_STABILIZE * ENERGY_MAX_PHASES))) {
Energy->phase_count--; // Decrement phases if no response after retry within 30 seconds after restart
if (TasmotaGlobal.discovery_counter) {
TasmotaGlobal.discovery_counter += (PZEM_RETRY / 4) + 1; // Don't send Discovery yet, delay by 5 * 250ms + 1s

View File

@ -33,7 +33,7 @@
#define XNRG_05 5
const uint8_t PZEM_AC_DEVICE_ADDRESS = 0x01; // PZEM default address
const uint32_t PZEM_AC_STABILIZE = 30; // Number of seconds to stabilize configuration
const uint32_t PZEM_AC_STABILIZE = 10; // Number of seconds to stabilize 1 pzem
#include <TasmotaModbus.h>
TasmotaModbus *PzemAcModbus;
@ -79,7 +79,7 @@ void PzemAcEverySecond(void)
Energy->power_factor[PzemAc.phase] = (float)((buffer[19] << 8) + buffer[20]) / 100.0f; // 1.00
Energy->import_active[PzemAc.phase] = (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[13] << 8) + buffer[14]) / 1000.0f; // 4294967.295 kWh
if (PzemAc.phase == Energy->phase_count -1) {
if (TasmotaGlobal.uptime > PZEM_AC_STABILIZE) {
if (TasmotaGlobal.uptime > (PZEM_AC_STABILIZE * ENERGY_MAX_PHASES)) {
EnergyUpdateTotal();
}
}
@ -103,7 +103,7 @@ void PzemAcEverySecond(void)
}
else {
PzemAc.send_retry--;
if ((Energy->phase_count > 1) && (0 == PzemAc.send_retry) && (TasmotaGlobal.uptime < PZEM_AC_STABILIZE)) {
if ((Energy->phase_count > 1) && (0 == PzemAc.send_retry) && (TasmotaGlobal.uptime < (PZEM_AC_STABILIZE * ENERGY_MAX_PHASES))) {
Energy->phase_count--; // Decrement phases if no response after retry within 30 seconds after restart
if (TasmotaGlobal.discovery_counter) {
TasmotaGlobal.discovery_counter += ENERGY_WATCHDOG + 1; // Don't send Discovery yet, delay by 4s + 1s

View File

@ -32,7 +32,7 @@
#define XNRG_06 6
const uint8_t PZEM_DC_DEVICE_ADDRESS = 0x01; // PZEM default address
const uint32_t PZEM_DC_STABILIZE = 30; // Number of seconds to stabilize configuration
const uint32_t PZEM_DC_STABILIZE = 10; // Number of seconds to stabilize 1 pzem
#include <TasmotaModbus.h>
TasmotaModbus *PzemDcModbus;
@ -76,7 +76,7 @@ void PzemDcEverySecond(void)
Energy->active_power[PzemDc.channel] = (float)((buffer[9] << 24) + (buffer[10] << 16) + (buffer[7] << 8) + buffer[8]) / 10.0f; // 429496729.0 W
Energy->import_active[PzemDc.channel] = (float)((buffer[13] << 24) + (buffer[14] << 16) + (buffer[11] << 8) + buffer[12]) / 1000.0f; // 4294967.295 kWh
if (PzemDc.channel == Energy->phase_count -1) {
if (TasmotaGlobal.uptime > PZEM_DC_STABILIZE) {
if (TasmotaGlobal.uptime > (PZEM_DC_STABILIZE * ENERGY_MAX_PHASES)) {
EnergyUpdateTotal();
}
}
@ -100,7 +100,7 @@ void PzemDcEverySecond(void)
}
else {
PzemDc.send_retry--;
if ((Energy->phase_count > 1) && (0 == PzemDc.send_retry) && (TasmotaGlobal.uptime < PZEM_DC_STABILIZE)) {
if ((Energy->phase_count > 1) && (0 == PzemDc.send_retry) && (TasmotaGlobal.uptime < (PZEM_DC_STABILIZE * ENERGY_MAX_PHASES))) {
Energy->phase_count--; // Decrement channels if no response after retry within 30 seconds after restart
if (TasmotaGlobal.discovery_counter) {
TasmotaGlobal.discovery_counter += ENERGY_WATCHDOG + 1; // Don't send Discovery yet, delay by 4s + 1s

View File

@ -69,7 +69,7 @@
#define BIOPDU_MAX_PHASES 6 // BioPDU support max six phases/channels
const uint8_t BIOPDU_DEVICE_ADDRESS = 0x01; // PZEM default address
const uint32_t BIOPDU_STABILIZE = 30; // Number of seconds to stabilize configuration
const uint32_t BIOPDU_STABILIZE = 10; // Number of seconds to stabilize 1 device
#include <TasmotaModbus.h>
TasmotaModbus *BioPduModbus;
@ -273,7 +273,7 @@ bool Xnrg24(uint32_t function)
} // Fix start up issue #5875
break;
case FUNC_ENERGY_EVERY_SECOND:
if (TasmotaGlobal.uptime > BIOPDU_STABILIZE)
if (TasmotaGlobal.uptime > (BIOPDU_STABILIZE * BIOPDU_MAX_PHASES))
{
BioPduEverySecond();
}