Fix PZem startup issue

Fix PZem startup issue (#5875)
This commit is contained in:
Theo Arends 2019-06-02 18:07:54 +02:00
parent ffd36e0b2d
commit d0502c1af8
3 changed files with 39 additions and 18 deletions

View File

@ -1,6 +1,7 @@
/* 6.5.0.14 20190602
* Change webserver HTML input, button, textarea, and select name based on id
* Fix webserver multiple Javascript window.onload functionality
* Fix PZem startup issue (#5875)
*
* 6.5.0.13 20190527
* Add command SetOption38 6..255 to set IRReceive protocol detection sensitivity mimizing UNKNOWN protocols (#5853)

View File

@ -36,6 +36,24 @@
#include <TasmotaModbus.h>
TasmotaModbus *PzemAcModbus;
/*
uint16_t PzemCalculateCRC(uint8_t *buffer, uint8_t num)
{
uint16_t crc = 0xFFFF;
for (uint8_t i = 0; i < num; i++) {
crc ^= buffer[i];
for (uint8_t j = 8; j; j--) {
if ((crc & 0x0001) != 0) { // If the LSB is set
crc >>= 1; // Shift right and XOR 0xA001
crc ^= 0xA001;
} else { // Else LSB is not set
crc >>= 1; // Just shift right
}
}
}
return crc;
}
*/
void PzemAcEverySecond(void)
{
static uint8_t send_retry = 0;
@ -51,6 +69,7 @@ void PzemAcEverySecond(void)
if (error) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "PzemAc response error %d"), error);
} else {
// if ((PzemCalculateCRC(buffer, 23)) == ((buffer[24] << 8) | buffer[23])) {
energy_data_valid = 0;
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
@ -69,6 +88,7 @@ void PzemAcEverySecond(void)
energy_start = energy;
}
EnergyUpdateToday();
// }
}
}
@ -118,7 +138,7 @@ int Xnrg05(uint8_t function)
PzemAcSnsInit();
break;
case FUNC_ENERGY_EVERY_SECOND:
PzemAcEverySecond();
if (uptime > 4) { PzemAcEverySecond(); } // Fix start up issue #5875
break;
}
}

View File

@ -117,7 +117,7 @@ int Xnrg06(uint8_t function)
PzemDcSnsInit();
break;
case FUNC_ENERGY_EVERY_SECOND:
PzemDcEverySecond();
if (uptime > 4) { PzemDcEverySecond(); } // Fix start up issue #5875
break;
}
}