From 37fc7d22592058b5793de83fa7e096306b4de735 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 2 Oct 2019 11:24:51 +0200 Subject: [PATCH] Add command SetOption71 for DDS238-2 Add command SetOption71 0/1 to switch between different Modbus Active Energy registers on DDS238-2 energy meters (#6531) --- sonoff/_changelog.ino | 1 + sonoff/settings.h | 2 +- sonoff/xnrg_09_dds2382.ino | 15 ++++++++++----- tools/decode-status.py | 3 ++- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 7739e9a0b..9139cb622 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -7,6 +7,7 @@ * Add initial support for shutters by Stefan Bode (#288) * Add command to MCP230xx: sensor29 pin,0/1/2 for OFF/ON/TOGGLE * Add initial support for PCF8574 I2C I/O Expander (currently output only) by Stefan Bode + * Add command SetOption71 0/1 to switch between different Modbus Active Energy registers on DDS238-2 energy meters (#6531) * * 6.6.0.13 20190922 * Add command EnergyReset4 x,x to initialize total usage for two tarrifs diff --git a/sonoff/settings.h b/sonoff/settings.h index 4f808586d..c2be9d6e3 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -84,7 +84,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t pwm_multi_channels : 1; // bit 18 (v6.6.0.3) - SetOption68 - Enable multi-channels PWM instead of Color PWM uint32_t tuya_dimmer_min_limit : 1; // bit 19 (v6.6.0.5) - SetOption69 - Limits Tuya dimmers to minimum of 10% (25) when enabled. uint32_t energy_weekend : 1; // bit 20 (v6.6.0.8) - CMND_TARIFF - uint32_t spare21 : 1; + uint32_t dds2382_model : 1; // bit 21 (v6.6.0.14) - SetOption71 - Select different Modbus registers for Active Energy (#6531) uint32_t spare22 : 1; uint32_t spare23 : 1; uint32_t spare24 : 1; diff --git a/sonoff/xnrg_09_dds2382.ino b/sonoff/xnrg_09_dds2382.ino index b36a12d8f..590a60186 100644 --- a/sonoff/xnrg_09_dds2382.ino +++ b/sonoff/xnrg_09_dds2382.ino @@ -54,8 +54,10 @@ void Dds2382EverySecond(void) } else { Energy.data_valid[0] = 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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 - // SA FC BC EnergyTotal ExportActiv ImportActiv Volta Curre APowe RPowe PFact Frequ Crc-- + // 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 = ModBus register + // 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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 = Buffer index + // SA FC BC EnergyTotal ExportActiv ImportActiv Volta Curre APowe RPowe PFact Frequ Crc-- = DDS238-2 ZN/S version 1 (#6384) + // SA FC BC EnergyTotal ExportActiv ImportActiv Volta Curre APowe RPowe PFact Frequ Crc-- = DDS238-2 ZN/S version 2 (#6531) Energy.voltage[0] = (float)((buffer[27] << 8) + buffer[28]) / 10.0; Energy.current[0] = (float)((buffer[29] << 8) + buffer[30]) / 100.0; @@ -63,9 +65,12 @@ void Dds2382EverySecond(void) Energy.reactive_power[0] = (float)((buffer[33] << 8) + buffer[34]); Energy.power_factor[0] = (float)((buffer[35] << 8) + buffer[36]) / 1000.0; // 1.00 Energy.frequency[0] = (float)((buffer[37] << 8) + buffer[38]) / 100.0; // 50.0 Hz - Energy.export_active = (float)((buffer[11] << 24) + (buffer[12] << 16) + (buffer[13] << 8) + buffer[14]) / 100.0; // 429496729.0 W -// float energy_total = (float)((buffer[3] << 24) + (buffer[4] << 16) + (buffer[5] << 8) + buffer[6]) / 100.0; // 429496729.0 W - float import_active = (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[17] << 8) + buffer[18]) / 100.0; // 429496729.0 W + uint8_t offset = 11; + if (Settings.flag3.dds2382_model) { + offset = 19; + } + Energy.export_active = (float)((buffer[offset] << 24) + (buffer[offset +1] << 16) + (buffer[offset +2] << 8) + buffer[offset +3]) / 100.0; // 429496729.0 W + float import_active = (float)((buffer[offset +4] << 24) + (buffer[offset +5] << 16) + (buffer[offset +6] << 8) + buffer[offset +7]) / 100.0; // 429496729.0 W EnergyUpdateTotal(import_active, false); // 484.708 kWh } diff --git a/tools/decode-status.py b/tools/decode-status.py index 8682373ec..a08689306 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -124,7 +124,8 @@ a_setoption = [[ "Enable multi-channels PWM instead of Color PWM", "Limits Tuya MCU dimmers to minimum of 10% (25) when enabled", "Enable Weekend Energy Tariff", - "","","", + "Select different Modbus registers for Active Energy", + "","", "","","","", "","", "Enable shutter support",