Fix Pzem004T checksum error

6.0.0a
* Fix Pzem004T checksum error
This commit is contained in:
Theo Arends 2018-06-03 14:43:17 +02:00
parent d4e414a6d5
commit cec701fb33
3 changed files with 19 additions and 10 deletions

View File

@ -2,6 +2,7 @@
* Add CRC to Settings making future upgrades more fail-safe
* Remove version 3, 4 and pre 5.2 settings auto-upgrade. See https://github.com/arendst/Sonoff-Tasmota/wiki/Upgrade#migration-path
* Change default CFG_HOLDER from 0x20161209 to 4617 (=0x1209) - no impact on default upgrades
* Fix Pzem004T checksum error
*
* 5.14.0b
* Add Console Commands to send KNX Commands

View File

@ -942,15 +942,6 @@ void HandleBackupConfiguration()
WebServer->send(200, FPSTR(HDR_CTYPE_STREAM), "");
memcpy(settings_buffer, &Settings, sizeof(Settings));
/*
settings_buffer[0] = CONFIG_FILE_SIGN;
settings_buffer[1] = (!config_xor_on_set) ? 0 : 1;
if (settings_buffer[1]) {
for (uint16_t i = 2; i < sizeof(Settings); i++) {
settings_buffer[i] ^= (config_xor_on_set +i);
}
}
*/
if (config_xor_on_set) {
for (uint16_t i = 2; i < sizeof(Settings); i++) {
settings_buffer[i] ^= (config_xor_on_set +i);

View File

@ -281,6 +281,9 @@ long cf_pulses_last_time = CSE_PULSES_NOT_INITIALIZED;
void CseReceived()
{
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
// 55 5A 02 F7 60 00 03 AB 00 40 10 02 60 5D 51 A6 58 03 E9 EF 71 0B 7A 36
// Hd Id VCal---- Voltage- ICal---- Current- PCal---- Power--- Ad CF--- Ck
AddLogSerial(LOG_LEVEL_DEBUG_MORE);
uint8_t header = serial_in_buffer[0];
@ -481,7 +484,17 @@ bool PzemReceiveReady()
bool PzemRecieve(uint8_t resp, float *data)
{
uint8_t buffer[sizeof(PZEMCommand)];
// 0 1 2 3 4 5 6
// A4 00 00 00 00 00 A4 - Set address
// A0 00 D4 07 00 00 7B - Voltage (212.7V)
// A1 00 00 0A 00 00 AB - Current (0.1A)
// A1 00 00 00 00 00 A1 - No current
// A2 00 16 00 00 00 B8 - Power (22W)
// A2 00 00 00 00 00 A2 - No power
// A3 00 08 A4 00 00 4F - Energy (2.212kWh)
// A3 01 86 9F 00 00 C9 - Energy (99.999kWh)
uint8_t buffer[sizeof(PZEMCommand)] = { 0 };
unsigned long start = millis();
uint8_t len = 0;
@ -491,6 +504,10 @@ bool PzemRecieve(uint8_t resp, float *data)
if (!c && !len) {
continue; // skip 0 at startup
}
if ((1 == len) && (buffer[0] == c)) {
len--;
continue; // fix skewed data
}
buffer[len++] = c;
}
}