Merge pull request #8890 from mbezuidenhout/iem3000-feature

Schneider iEM3xxx Modbus feature
This commit is contained in:
Theo Arends 2020-07-14 11:43:52 +02:00 committed by GitHub
commit fde82d8bdb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 280 additions and 5 deletions

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP - TX" #define D_SENSOR_TCP_TXD "TCP - TX"
#define D_SENSOR_TCP_RXD "TCP - RX" #define D_SENSOR_TCP_RXD "TCP - RX"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "А" #define D_UNIT_AMPERE "А"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "A" #define D_UNIT_AMPERE "A"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "А" #define D_UNIT_AMPERE "А"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "安" #define D_UNIT_AMPERE "安"

View File

@ -703,6 +703,8 @@
#define D_SENSOR_ETH_PHY_MDIO "ETH MDIO" #define D_SENSOR_ETH_PHY_MDIO "ETH MDIO"
#define D_SENSOR_TCP_TXD "TCP Tx" #define D_SENSOR_TCP_TXD "TCP Tx"
#define D_SENSOR_TCP_RXD "TCP Rx" #define D_SENSOR_TCP_RXD "TCP Rx"
#define D_SENSOR_IEM3000_TX "iEM3000 TX"
#define D_SENSOR_IEM3000_RX "iEM3000 RX"
// Units // Units
#define D_UNIT_AMPERE "安" #define D_UNIT_AMPERE "安"

View File

@ -640,6 +640,9 @@
#define USE_BL0940 // Add support for BL0940 Energy monitor as used in Blitzwolf SHP-10 (+1k6 code) #define USE_BL0940 // Add support for BL0940 Energy monitor as used in Blitzwolf SHP-10 (+1k6 code)
//#define USE_TELEINFO // Add support for Teleinfo via serial RX interface (+5k2 code, +168 RAM + SmartMeter LinkedList Values RAM) //#define USE_TELEINFO // Add support for Teleinfo via serial RX interface (+5k2 code, +168 RAM + SmartMeter LinkedList Values RAM)
// #define USE_TELEINFO_STANDARD // Use standard mode (9600 bps) else it's historical mode (1200 bps) // #define USE_TELEINFO_STANDARD // Use standard mode (9600 bps) else it's historical mode (1200 bps)
//#define USE_IEM3000 // Add support for Schneider Electric iEM3000-Modbus series energy monitor (+0k8 code)
#define IEM3000_SPEED 19200 // iEM3000-Modbus RS485 serial speed (default: 19200 baud)
#define IEM3000_ADDR 1 // iEM3000-Modbus modbus address (default: 0x01)
// -- Low level interface devices ----------------- // -- Low level interface devices -----------------
#define USE_DHT // Add support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor (1k6 code) #define USE_DHT // Add support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor (1k6 code)

View File

@ -323,7 +323,6 @@ void GetFeatures(void)
#ifdef USE_TM1638 #ifdef USE_TM1638
feature_sns1 |= 0x80000000; // xsns_28_tm1638.ino feature_sns1 |= 0x80000000; // xsns_28_tm1638.ino
#endif #endif
/*********************************************************************************************/ /*********************************************************************************************/
feature_sns2 = 0x00000000; feature_sns2 = 0x00000000;
@ -593,7 +592,9 @@ void GetFeatures(void)
#ifdef USE_PROMETHEUS #ifdef USE_PROMETHEUS
feature6 |= 0x00100000; // xsns_75_prometheus.ino feature6 |= 0x00100000; // xsns_75_prometheus.ino
#endif #endif
// feature6 |= 0x00200000; #if defined(USE_ENERGY_SENSOR) && defined(USE_IEM3000)
feature6 |= 0x00200000; // xnrg_16_iem3000.ino
#endif
// feature6 |= 0x00400000; // feature6 |= 0x00400000;
// feature6 |= 0x00800000; // feature6 |= 0x00800000;

View File

@ -239,6 +239,8 @@ enum UserSelectablePins {
GPIO_TELEINFO_RX, // TELEINFO serial interface GPIO_TELEINFO_RX, // TELEINFO serial interface
GPIO_TELEINFO_ENABLE,// TELEINFO Enable PIN GPIO_TELEINFO_ENABLE,// TELEINFO Enable PIN
GPIO_LMT01, // LMT01 input counting pin GPIO_LMT01, // LMT01 input counting pin
GPIO_IEM3000_TX, // IEM3000 Serial interface
GPIO_IEM3000_RX, // IEM3000 Serial interface
GPIO_SENSOR_END }; GPIO_SENSOR_END };
// Programmer selectable GPIO functionality // Programmer selectable GPIO functionality
@ -332,7 +334,8 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_BL0940_RX "|" D_SENSOR_BL0940_RX "|"
D_SENSOR_TCP_TXD "|" D_SENSOR_TCP_RXD "|" D_SENSOR_TCP_TXD "|" D_SENSOR_TCP_RXD "|"
D_SENSOR_TELEINFO_RX "|" D_SENSOR_TELEINFO_ENABLE "|" D_SENSOR_TELEINFO_RX "|" D_SENSOR_TELEINFO_ENABLE "|"
D_SENSOR_LMT01_PULSE D_SENSOR_LMT01_PULSE "|"
D_SENSOR_IEM3000_TX "|" D_SENSOR_IEM3000_RX
; ;
const char kSensorNamesFixed[] PROGMEM = const char kSensorNamesFixed[] PROGMEM =
@ -584,6 +587,10 @@ const uint8_t kGpioNiceList[] PROGMEM = {
#ifdef USE_BL0940 #ifdef USE_BL0940
GPIO_BL0940_RX, // BL0940 Serial interface GPIO_BL0940_RX, // BL0940 Serial interface
#endif #endif
#ifdef USE_IEM3000
GPIO_IEM3000_TX, // IEM3000 Serial interface
GPIO_IEM3000_RX, // IEM3000 Serial interface
#endif
#endif // USE_ENERGY_SENSOR #endif // USE_ENERGY_SENSOR
// Serial // Serial

View File

@ -137,6 +137,7 @@ enum UserSelectablePins {
GPIO_TELEINFO_RX, // Teleinfo telemetry data receive pin GPIO_TELEINFO_RX, // Teleinfo telemetry data receive pin
GPIO_TELEINFO_ENABLE, // Teleinfo Enable Receive Pin GPIO_TELEINFO_ENABLE, // Teleinfo Enable Receive Pin
GPIO_LMT01, // LMT01 input counting pin GPIO_LMT01, // LMT01 input counting pin
GPIO_IEM3000_TX, GPIO_IEM3000_RX, // IEM3000 Serial interface
GPIO_SENSOR_END }; GPIO_SENSOR_END };
enum ProgramSelectablePins { enum ProgramSelectablePins {
@ -233,7 +234,8 @@ const char kSensorNames[] PROGMEM =
D_SENSOR_TCP_TXD "|" D_SENSOR_TCP_RXD "|" D_SENSOR_TCP_TXD "|" D_SENSOR_TCP_RXD "|"
D_SENSOR_ETH_PHY_POWER "|" D_SENSOR_ETH_PHY_MDC "|" D_SENSOR_ETH_PHY_MDIO "|" D_SENSOR_ETH_PHY_POWER "|" D_SENSOR_ETH_PHY_MDC "|" D_SENSOR_ETH_PHY_MDIO "|"
D_SENSOR_TELEINFO_RX "|" D_SENSOR_TELEINFO_ENABLE "|" D_SENSOR_TELEINFO_RX "|" D_SENSOR_TELEINFO_ENABLE "|"
D_SENSOR_LMT01_PULSE D_SENSOR_LMT01_PULSE "|"
D_SENSOR_IEM3000_TX "|" D_SENSOR_IEM3000_RX
; ;
const char kSensorNamesFixed[] PROGMEM = const char kSensorNamesFixed[] PROGMEM =
@ -431,6 +433,10 @@ const uint16_t kGpioNiceList[] PROGMEM = {
#ifdef USE_BL0940 #ifdef USE_BL0940
AGPIO(GPIO_BL0940_RX), // BL0940 Serial interface AGPIO(GPIO_BL0940_RX), // BL0940 Serial interface
#endif #endif
#ifdef USE_IEM3000
AGPIO(GPIO_IEM3000_TX), // IEM3000 Serial interface
AGPIO(GPIO_IEM3000_RX), // IEM3000 Serial interface
#endif
#endif // USE_ENERGY_SENSOR #endif // USE_ENERGY_SENSOR
// Serial // Serial

208
tasmota/xnrg_17_iem3000.ino Normal file
View File

@ -0,0 +1,208 @@
/*
xnrg_17_iem3000.ino - Schneider Electric iEM3000 series Modbus energy meter support for Tasmota
Copyright (C) 2020 Marius Bezuidenhout
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef USE_ENERGY_SENSOR
#ifdef USE_IEM3000
/*********************************************************************************************\
* Schneider Electric iEM3000 series Modbus energy meter
* iEM3150 / iEM3155 / iEM3250 / iEM3255 / iEM3350 / iEM3355 / iEM3455 / iEM3555
* Important! Set meter Commnication -> Parity to None
\*********************************************************************************************/
#define XNRG_17 17
// can be user defined in my_user_config.h
#ifndef IEM3000_SPEED
#define IEM3000_SPEED 19200 // default IEM3000 Modbus address
#endif
// can be user defined in my_user_config.h
#ifndef IEM3000_ADDR
#define IEM3000_ADDR 1 // default IEM3000 Modbus address
#endif
#include <TasmotaModbus.h>
TasmotaModbus *Iem3000Modbus;
const uint16_t Iem3000_start_addresses[] {
// ID (reg count/datatype) [unit] Description
0x0bb7, // 0 . IEM3000_I1_CURRENT (2/Float32) [A] I1: phase 1 current
0x0bb9, // 1 . IEM3000_I2_CURRENT (2/Float32) [A] I2: phase 2 current
0x0bbb, // 2 . IEM3000_I3_CURRENT (2/Float32) [A] I3: phase 3 current
0x0bd3, // 3 . IEM3000_L1_VOLTAGE (2/Float32) [V] Voltage L1N
0x0bd5, // 4 . IEM3000_L2_VOLTAGE (2/Float32) [V] Voltage L2N
0x0bd7, // 5 . IEM3000_L3_VOLTAGE (2/Float32) [V] Voltage L3N
0x0bed, // 6 . IEM3000_P1_POWER (2/Float32) [KW] Active Power Phase 1
0x0bef, // 7 . IEM3000_P2_POWER (2/Float32) [KW] Active Power Phase 2
0x0bf1, // 8 . IEM3000_P3_POWER (2/Float32) [KW] Active Power Phase 3
0x0c25, // 9 . IEM3000_FREQUENCY (2/Float32) [Hz] Frequency
0xb02b, // 10 . IEM3000_TOTAL_ACTIVE (4/Int64) [Wh] Total Active Energy Import
};
struct IEM3000 {
uint8_t read_state = 0;
uint8_t send_retry = 0;
} Iem3000;
/*********************************************************************************************/
void IEM3000Every250ms(void)
{
bool data_ready = Iem3000Modbus->ReceiveReady();
uint8_t reg_count = 4;
if (Iem3000.read_state < 10) {
reg_count = 2;
}
if (data_ready) {
uint8_t buffer[14]; // At least 5 + sizeof(int64_t) = 13
uint32_t error = Iem3000Modbus->ReceiveBuffer(buffer, reg_count);
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, Iem3000Modbus->ReceiveCount());
if (error) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SDM: Iem3000 error %d"), error);
} else {
Energy.data_valid[0] = 0;
// 0 1 2 3 4 5 6 7 8
// SA FC BC Fh Fl Sh Sl Cl Ch
// 01 04 04 43 66 33 34 1B 38 = 230.2 Volt
float value;
int64_t value64;
if(Iem3000.read_state >= 0 && Iem3000.read_state < 10) {
((uint8_t*)&value)[3] = buffer[3]; // Get float values
((uint8_t*)&value)[2] = buffer[4];
((uint8_t*)&value)[1] = buffer[5];
((uint8_t*)&value)[0] = buffer[6];
} else {
((uint8_t*)&value64)[7] = buffer[3]; // Get int values
((uint8_t*)&value64)[6] = buffer[4];
((uint8_t*)&value64)[5] = buffer[5];
((uint8_t*)&value64)[4] = buffer[6];
((uint8_t*)&value64)[3] = buffer[7];
((uint8_t*)&value64)[2] = buffer[8];
((uint8_t*)&value64)[1] = buffer[9];
((uint8_t*)&value64)[0] = buffer[10];
}
switch(Iem3000.read_state) {
case 0:
Energy.current[0] = value;
break;
case 1:
Energy.current[1] = value;
break;
case 2:
Energy.current[2] = value;
break;
case 3:
Energy.voltage[0] = value;
break;
case 4:
Energy.voltage[1] = value;
break;
case 5:
Energy.voltage[2] = value;
break;
case 6:
Energy.active_power[0] = value;
break;
case 7:
Energy.active_power[1] = value;
break;
case 8:
Energy.active_power[2] = value;
break;
case 9:
Energy.frequency[0] = value;
break;
case 10:
EnergyUpdateTotal(value64 * 0.001f, true); // 1125 => 1.125
break;
}
Iem3000.read_state++;
if (sizeof(Iem3000_start_addresses)/2 == Iem3000.read_state) {
Iem3000.read_state = 0;
}
}
} // end data ready
if (0 == Iem3000.send_retry || data_ready) {
Iem3000.send_retry = 5;
Iem3000Modbus->Send(IEM3000_ADDR, 0x03, Iem3000_start_addresses[Iem3000.read_state], reg_count);
} else {
Iem3000.send_retry--;
}
}
void Iem3000SnsInit(void)
{
Iem3000Modbus = new TasmotaModbus(Pin(GPIO_IEM3000_RX), Pin(GPIO_IEM3000_TX));
uint8_t result = Iem3000Modbus->Begin(IEM3000_SPEED);
if (result) {
if (2 == result) { ClaimSerial(); }
Energy.phase_count = 3;
Energy.frequency_common = true; // Use common frequency
} else {
energy_flg = ENERGY_NONE;
}
}
void Iem3000DrvInit(void)
{
if (PinUsed(GPIO_IEM3000_RX) && PinUsed(GPIO_IEM3000_TX)) {
energy_flg = XNRG_17;
}
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
bool Xnrg17(uint8_t function)
{
bool result = false;
switch (function) {
case FUNC_EVERY_250_MSECOND:
if (uptime > 4) { IEM3000Every250ms(); }
break;
case FUNC_INIT:
Iem3000SnsInit();
break;
case FUNC_PRE_INIT:
Iem3000DrvInit();
break;
}
return result;
}
#endif // USE_IEM3000
#endif // USE_ENERGY_SENSOR

View File

@ -86,7 +86,11 @@ bool (* const xnrg_func_ptr[])(uint8_t) = { // Energy driver Function Pointers
#endif #endif
#ifdef XNRG_16 #ifdef XNRG_16
&Xnrg16 &Xnrg16,
#endif
#ifdef XNRG_17
&Xnrg17
#endif #endif
}; };