Skip to content

Commit

Permalink
(Try to) fix EnergyReset (again)
Browse files Browse the repository at this point in the history
(Try to) fix EnergyReset (again) (#6561)
  • Loading branch information
arendst committed Oct 20, 2019
1 parent ad73a51 commit 37c2239
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 6 additions & 2 deletions sonoff/xnrg_03_pzem004t.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#define XNRG_03 3

const uint32_t PZEM_STABILIZE = 30; // Number of seconds to stabilize configuration

#include <TasmotaSerial.h>

TasmotaSerial *PzemSerial = nullptr;
Expand Down Expand Up @@ -192,7 +194,9 @@ void PzemEvery250ms(void)
Pzem.energy += value;
if (Pzem.phase == Energy.phase_count -1) {
if (Pzem.energy > Pzem.last_energy) { // Handle missed phase
EnergyUpdateTotal(Pzem.energy, false);
if (uptime > PZEM_STABILIZE) {
EnergyUpdateTotal(Pzem.energy, false);
}
Pzem.last_energy = Pzem.energy;
}
Pzem.energy = 0;
Expand Down Expand Up @@ -228,7 +232,7 @@ void PzemEvery250ms(void)
}
else {
Pzem.send_retry--;
if ((Energy.phase_count > 1) && (0 == Pzem.send_retry) && (uptime < 30)) {
if ((Energy.phase_count > 1) && (0 == Pzem.send_retry) && (uptime < PZEM_STABILIZE)) {
Energy.phase_count--; // Decrement phases if no response after retry within 30 seconds after restart
}
}
Expand Down
9 changes: 6 additions & 3 deletions sonoff/xnrg_05_pzem_ac.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

#define XNRG_05 5

#define PZEM_AC_DEVICE_ADDRESS 0x01 // PZEM default address
const uint8_t PZEM_AC_DEVICE_ADDRESS = 0x01; // PZEM default address
const uint32_t PZEM_AC_STABILIZE = 30; // Number of seconds to stabilize configuration

#include <TasmotaModbus.h>
TasmotaModbus *PzemAcModbus;
Expand Down Expand Up @@ -79,7 +80,9 @@ void PzemAcEverySecond(void)
PzemAc.energy += (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[13] << 8) + buffer[14]); // 4294967295 Wh
if (PzemAc.phase == Energy.phase_count -1) {
if (PzemAc.energy > PzemAc.last_energy) { // Handle missed phase
EnergyUpdateTotal(PzemAc.energy, false);
if (uptime > PZEM_AC_STABILIZE) {
EnergyUpdateTotal(PzemAc.energy, false);
}
PzemAc.last_energy = PzemAc.energy;
}
PzemAc.energy = 0;
Expand All @@ -105,7 +108,7 @@ void PzemAcEverySecond(void)
}
else {
PzemAc.send_retry--;
if ((Energy.phase_count > 1) && (0 == PzemAc.send_retry) && (uptime < 30)) {
if ((Energy.phase_count > 1) && (0 == PzemAc.send_retry) && (uptime < PZEM_AC_STABILIZE)) {
Energy.phase_count--; // Decrement phases if no response after retry within 30 seconds after restart
}
}
Expand Down
9 changes: 6 additions & 3 deletions sonoff/xnrg_06_pzem_dc.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@

#define XNRG_06 6

#define PZEM_DC_DEVICE_ADDRESS 0x01 // PZEM default address
const uint8_t PZEM_DC_DEVICE_ADDRESS = 0x01; // PZEM default address
const uint32_t PZEM_DC_STABILIZE = 30; // Number of seconds to stabilize configuration

#include <TasmotaModbus.h>
TasmotaModbus *PzemDcModbus;
Expand Down Expand Up @@ -77,7 +78,9 @@ void PzemDcEverySecond(void)
PzemDc.energy += (float)((buffer[13] << 24) + (buffer[14] << 16) + (buffer[11] << 8) + buffer[12]); // 4294967295 Wh
if (PzemDc.channel == Energy.phase_count -1) {
if (PzemDc.energy > PzemDc.last_energy) { // Handle missed channel
EnergyUpdateTotal(PzemDc.energy, false);
if (uptime > PZEM_DC_STABILIZE) {
EnergyUpdateTotal(PzemDc.energy, false);
}
PzemDc.last_energy = PzemDc.energy;
}
PzemDc.energy = 0;
Expand All @@ -102,7 +105,7 @@ void PzemDcEverySecond(void)
}
else {
PzemDc.send_retry--;
if ((Energy.phase_count > 1) && (0 == PzemDc.send_retry) && (uptime < 30)) {
if ((Energy.phase_count > 1) && (0 == PzemDc.send_retry) && (uptime < PZEM_DC_STABILIZE)) {
Energy.phase_count--; // Decrement channels if no response after retry within 30 seconds after restart
}
}
Expand Down

0 comments on commit 37c2239

Please sign in to comment.