mirror of https://github.com/arendst/Tasmota.git
parent
ffd36e0b2d
commit
d0502c1af8
|
@ -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)
|
||||
|
|
|
@ -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,24 +69,26 @@ void PzemAcEverySecond(void)
|
|||
if (error) {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "PzemAc response error %d"), error);
|
||||
} else {
|
||||
energy_data_valid = 0;
|
||||
// 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
|
||||
// 01 04 14 08 D1 00 6C 00 00 00 F4 00 00 00 26 00 00 01 F4 00 64 00 00 51 34
|
||||
// Id Cc Sz Volt- Current---- Power------ Energy----- Frequ PFact Alarm Crc--
|
||||
energy_voltage = (float)((buffer[3] << 8) + buffer[4]) / 10.0; // 6553.0 V
|
||||
energy_current = (float)((buffer[7] << 24) + (buffer[8] << 16) + (buffer[5] << 8) + buffer[6]) / 1000.0; // 4294967.000 A
|
||||
energy_active_power = (float)((buffer[11] << 24) + (buffer[12] << 16) + (buffer[9] << 8) + buffer[10]) / 10.0; // 429496729.0 W
|
||||
energy_frequency = (float)((buffer[17] << 8) + buffer[18]) / 10.0; // 50.0 Hz
|
||||
energy_power_factor = (float)((buffer[19] << 8) + buffer[20]) / 100.0; // 1.00
|
||||
float energy = (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[13] << 8) + buffer[14]); // 4294967295 Wh
|
||||
// 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
|
||||
// 01 04 14 08 D1 00 6C 00 00 00 F4 00 00 00 26 00 00 01 F4 00 64 00 00 51 34
|
||||
// Id Cc Sz Volt- Current---- Power------ Energy----- Frequ PFact Alarm Crc--
|
||||
energy_voltage = (float)((buffer[3] << 8) + buffer[4]) / 10.0; // 6553.0 V
|
||||
energy_current = (float)((buffer[7] << 24) + (buffer[8] << 16) + (buffer[5] << 8) + buffer[6]) / 1000.0; // 4294967.000 A
|
||||
energy_active_power = (float)((buffer[11] << 24) + (buffer[12] << 16) + (buffer[9] << 8) + buffer[10]) / 10.0; // 429496729.0 W
|
||||
energy_frequency = (float)((buffer[17] << 8) + buffer[18]) / 10.0; // 50.0 Hz
|
||||
energy_power_factor = (float)((buffer[19] << 8) + buffer[20]) / 100.0; // 1.00
|
||||
float energy = (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[13] << 8) + buffer[14]); // 4294967295 Wh
|
||||
|
||||
if (!energy_start || (energy < energy_start)) { energy_start = energy; } // Init after restart and handle roll-over if any
|
||||
if (energy != energy_start) {
|
||||
energy_kWhtoday += (unsigned long)((energy - energy_start) * 100);
|
||||
energy_start = energy;
|
||||
}
|
||||
EnergyUpdateToday();
|
||||
if (!energy_start || (energy < energy_start)) { energy_start = energy; } // Init after restart and handle roll-over if any
|
||||
if (energy != energy_start) {
|
||||
energy_kWhtoday += (unsigned long)((energy - energy_start) * 100);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue