Added totalActive from le01, more code tunning

This commit is contained in:
saper-2 2020-01-05 19:51:12 +01:00
parent 179a1c549d
commit f2ca1f3e47
4 changed files with 26 additions and 15 deletions

View File

@ -183,6 +183,7 @@
#define D_JSON_SOLAR_POWER "SolarPower"
#define D_JSON_USAGE "Usage"
#define D_JSON_EXPORT "Export"
#define D_JSON_TOTAL_ACTIVE "TotalActive"
#define D_RSLT_ENERGY "ENERGY"
#define D_RSLT_HASS_STATE "HASS_STATE"

View File

@ -671,7 +671,7 @@
#define D_UNIT_WATTHOUR "Wh"
#define D_UNIT_WATT_METER_QUADRAT "W/m²"
//SDM220
//SDM220, SDM120, LE01MR
#define D_PHASE_ANGLE "Phase Angle"
#define D_IMPORT_ACTIVE "Import Active"
#define D_EXPORT_ACTIVE "Export Active"
@ -680,6 +680,7 @@
#define D_TOTAL_REACTIVE "Total Reactive"
#define D_UNIT_KWARH "kVArh"
#define D_UNIT_ANGLE "Deg"
#define D_TOTAL_ACTIVE "Total Active"
//SOLAXX1
#define D_PV1_VOLTAGE "PV1 Voltage"

View File

@ -498,9 +498,9 @@
//#define USE_SOLAX_X1 // Add support for Solax X1 series Modbus log info (+3k1 code)
#define SOLAXX1_SPEED 9600 // Solax X1 Modbus RS485 serial speed (default: 9600 baud)
#define SOLAXX1_PV2 // Solax X1 using second PV
//#define USE_LE01MR // Add support for F&F LE-01MR modbus energy meter
//#define LE01MR_SPEED 2400 // LE-01MR modbus baudrate (2400 default)
//#define LE01MR_ADDR 0x01 // LE-01MR modbus address (0x01 default)
//#define USE_LE01MR // Add support for F&F LE-01MR modbus energy meter
#define LE01MR_SPEED 2400 // LE-01MR modbus baudrate (2400 default)
#define LE01MR_ADDR 1 // LE-01MR modbus address (0x01 default)
// -- Low level interface devices -----------------
#define USE_DHT // Add support for DHT11, AM2301 (DHT21, DHT22, AM2302, AM2321) and SI7021 Temperature and Humidity sensor (1k6 code)

View File

@ -198,7 +198,7 @@ void FifLEEvery250ms(void)
// some registers are 1reg in size
if (Le01mr.read_state < 3) reg_count=1;
// send request
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("FiF-LE: LE01MR Modbus req reg %X, count %d"), le01mr_register_addresses[Le01mr.read_state], reg_count);
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("FiF-LE: LE01MR Modbus req reg %X, count %d"), le01mr_register_addresses[Le01mr.read_state], reg_count);
FifLEModbus->Send(LE01MR_ADDR, 0x03, le01mr_register_addresses[Le01mr.read_state], reg_count);
} else {
Le01mr.send_retry--;
@ -226,24 +226,30 @@ void FifLEDrvInit(void)
void FifLEReset(void)
{
Le01mr.total_active = 0;
Le01mr.total_reactive = 0;
}
#ifdef USE_WEBSERVER
const char HTTP_ENERGY_LE01MR[] PROGMEM =
"{s}" D_IMPORT_REACTIVE "{m}%s " D_UNIT_KWARH "{e}";
"{s}" D_TOTAL_ACTIVE "{m}%s " D_UNIT_KILOWATTHOUR "{e}"
"{s}" D_TOTAL_REACTIVE "{m}%s " D_UNIT_KWARH "{e}"
;
#endif // USE_WEBSERVER
void FifLEShow(bool json)
{
char total_reactive_chr[FLOATSZ];
dtostrfd(Le01mr.total_reactive, Settings.flag2.energy_resolution, total_reactive_chr);
char total_active_chr[FLOATSZ];
dtostrfd(Le01mr.total_active, Settings.flag2.energy_resolution, total_active_chr);
if (json) {
ResponseAppend_P(PSTR(",\"" D_JSON_IMPORT_REACTIVE "\":%s"),
total_reactive_chr);
ResponseAppend_P(PSTR(",\"" D_JSON_TOTAL_ACTIVE "\":%s,\"" D_JSON_TOTAL_REACTIVE "\":%s"),
total_active_chr, total_reactive_chr);
#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(HTTP_ENERGY_LE01MR, total_reactive_chr);
WSContentSend_PD(HTTP_ENERGY_LE01MR, total_active_chr, total_reactive_chr);
#endif // USE_WEBSERVER
}
}
@ -253,20 +259,23 @@ void FifLEShow(bool json)
\*********************************************************************************************/
// just to slow down tramitter (for deug purpouses)
#define SLOW_DOWN_X250MS 1
uint8_t slowdown = SLOW_DOWN_X250MS;
//#define SLOW_DOWN_X250MS 1
//uint8_t slowdown = SLOW_DOWN_X250MS;
bool Xnrg13(uint8_t function)
{
bool result = false;
switch (function) {
// TODO: Verify if there is corrleaction with 250ms scan time,
// and MQTT breaking connection and causing exception in ESP8266 after few minutes
// test with "FUNC_EVERY_SECOND"
case FUNC_EVERY_250_MSECOND:
if (uptime > 4) {
if (--slowdown == 0) {
if (uptime > 4) {
//if (--slowdown == 0) {
FifLEEvery250ms();
slowdown=SLOW_DOWN_X250MS;
}
// slowdown=SLOW_DOWN_X250MS;
//}
}
break;
case FUNC_JSON_APPEND: