From 8d5e8a947531357a741b5285addf616ee71c594b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Lindstr=C3=B6m?= Date: Wed, 10 Jan 2018 14:23:13 +0100 Subject: [PATCH 1/4] Update sparsnas_decode.cpp added PULSES_PER_KWH instead of 1000 as a variable for the sprint. This is to support people who has other imp/kwh than 1000. --- sparsnas_decode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sparsnas_decode.cpp b/sparsnas_decode.cpp index c222831..e6127ac 100644 --- a/sparsnas_decode.cpp +++ b/sparsnas_decode.cpp @@ -186,7 +186,7 @@ class SignalDetector { int pulse = (dec[13] << 24 | dec[14] << 16 | dec[15] << 8 | dec[16]); int battery = dec[17]; float watt = (float)((3600000 / PULSES_PER_KWH) * 1024) / (effect); - m += sprintf(m, "%5d: %7.1f W. %d.%.3d kWh. Batt %d%%. FreqErr: %.2f", seq, watt, pulse/1000, pulse%1000, battery, freq); + m += sprintf(m, "%5d: %7.1f W. %d.%.3d kWh. Batt %d%%. FreqErr: %.2f", seq, watt, pulse/PULSES_PER_KWH, pulse%PULSES_PER_KWH, battery, freq); if (testing && crc == packet_crc) { error_sum += fabs(freq); From 15c1d7d60fe47236cd210ddf50ddacbf5ad9a336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Lindstr=C3=B6m?= Date: Wed, 10 Jan 2018 22:45:03 +0100 Subject: [PATCH 2/4] Update sparsnas_decode.cpp Added fix for watt calculation depending on data_[4]^0x0f --- sparsnas_decode.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sparsnas_decode.cpp b/sparsnas_decode.cpp index e6127ac..9848543 100644 --- a/sparsnas_decode.cpp +++ b/sparsnas_decode.cpp @@ -185,7 +185,13 @@ class SignalDetector { int effect = (dec[11] << 8 | dec[12]); int pulse = (dec[13] << 24 | dec[14] << 16 | dec[15] << 8 | dec[16]); int battery = dec[17]; - float watt = (float)((3600000 / PULSES_PER_KWH) * 1024) / (effect); + float watt; +// Note that data_[4] cycles between 0-3 when you first put in the batterys in the sender. So please wait atleast 1 hour before trusting this next bit to work correct. + if(data_[4]^0x0f == 1){ + watt = (float)((3600000 / PULSES_PER_KWH) * 1024) / (effect); + } else if(data_[4]^0x0f == 2){ + watt = effect * 24; + } m += sprintf(m, "%5d: %7.1f W. %d.%.3d kWh. Batt %d%%. FreqErr: %.2f", seq, watt, pulse/PULSES_PER_KWH, pulse%PULSES_PER_KWH, battery, freq); if (testing && crc == packet_crc) { From ff7ec7654802d3d9d93ba335787c23eebaf60b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Lindstr=C3=B6m?= Date: Sun, 14 Jan 2018 11:58:22 +0100 Subject: [PATCH 3/4] Update sparsnas_decode.cpp Removed data_[4] from if statement when checking for bad packages. --- sparsnas_decode.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sparsnas_decode.cpp b/sparsnas_decode.cpp index 9848543..f185558 100644 --- a/sparsnas_decode.cpp +++ b/sparsnas_decode.cpp @@ -176,7 +176,7 @@ class SignalDetector { uint32_t rcv_sensor_id = dec[5] << 24 | dec[6] << 16 | dec[7] << 8 | dec[8]; - if (data_[0] != 0x11 || data_[1] != (SENSOR_ID & 0xFF) || data_[3] != 0x07 || data_[4] != 0x0E || rcv_sensor_id != SENSOR_ID) { + if (data_[0] != 0x11 || data_[1] != (SENSOR_ID & 0xFF) || data_[3] != 0x07 || rcv_sensor_id != SENSOR_ID) { m += sprintf(m, "Bad: "); for (int i = 0; i < 18; i++) m += sprintf(m, "%.2X ", data_[i]); From 63be42753e48cd2ba59bf537a0e944b7ce8223a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Lindstr=C3=B6m?= Date: Sun, 14 Jan 2018 13:26:03 +0100 Subject: [PATCH 4/4] Update sparsnas_decode.cpp little bit more editing. --- sparsnas_decode.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/sparsnas_decode.cpp b/sparsnas_decode.cpp index f185558..df9dcba 100644 --- a/sparsnas_decode.cpp +++ b/sparsnas_decode.cpp @@ -185,12 +185,11 @@ class SignalDetector { int effect = (dec[11] << 8 | dec[12]); int pulse = (dec[13] << 24 | dec[14] << 16 | dec[15] << 8 | dec[16]); int battery = dec[17]; - float watt; -// Note that data_[4] cycles between 0-3 when you first put in the batterys in the sender. So please wait atleast 1 hour before trusting this next bit to work correct. - if(data_[4]^0x0f == 1){ + float watt = effect * 24; + int data4 = data_[4]^0x0f; +// Note that data_[4] cycles between 0-3 when you first put in the batterys in t$ + if(data4 == 1){ watt = (float)((3600000 / PULSES_PER_KWH) * 1024) / (effect); - } else if(data_[4]^0x0f == 2){ - watt = effect * 24; } m += sprintf(m, "%5d: %7.1f W. %d.%.3d kWh. Batt %d%%. FreqErr: %.2f", seq, watt, pulse/PULSES_PER_KWH, pulse%PULSES_PER_KWH, battery, freq);