Some code cleanup and add comments & info

This commit is contained in:
saper-2 2020-01-23 16:13:25 +01:00
parent f145d22e90
commit ad083d1675
2 changed files with 13 additions and 7 deletions

View File

@ -499,7 +499,7 @@
#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_SPEED 2400 // LE-01MR modbus baudrate (9600 default) (+2k code, +36 RAM)
#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

@ -23,7 +23,7 @@
* (and bidirectional energy counting - enabled by RS485).
* It measure: Active energy imported AE+ [kWh] , Reactive energy imported RE+ [kvarh],
* Voltage V [V], Current I [A], Frequency F [Hz], power factor (aka "cos-phi"),
* Active power P [kW], Reactive power Q [kvar], Apparent power S [kVA],
* Active power P [kW], Reactive power Q [kVAr], Apparent power S [kVA],
* *Active energy exported AE- [kWh] (when meter is switched to bi-directional counting then
* reactive energy imported register contains value of Active energy exported).
*
@ -31,6 +31,12 @@
* EN: https://www.fif.com.pl/en/usage-electric-power-meters/517-electricity-consumption-meter-le-01mr.html
* PL: https://www.fif.com.pl/pl/liczniki-zuzycia-energii-elektrycznej/517-licznik-zuzycia-energii-le-01mr.html
*
* Note about communication settings: The meter must be reconfigured to use baudrate 2400 (or 9600) *without*
* parity bit - by default the meter is configured to 9600 8E1
* (Frame format: "EVEN 1") . To make those changes, use LE-Config
* software (can be found in download tab in product page - link above)
* and USB-RS485 dongle (those cheap ~2$ from ali works fine)
*
* Register descriptions (not all, only those that are being read):
*
* /----------------------------------- Register address
@ -54,6 +60,11 @@
* second register contains lower word of 32bit dword:
* value_32bit = (register+0)<<16 | (register+1);
* /or/ val32bit = (reg+0)*65536 + (reg+1);
*
* Note about MQTT/JSON: In fields "ENERGY.TotalActive" and "ENERGY.TotalReactive" there are
* counters values directly from the meter (without Tasmota calculation,
* energy used calculated by Tasmota is in Total/Today fields ).
* Filed "ENERGY.Period" is always zero.
\*********************************************************************************************/
#define XNRG_13 13
@ -113,7 +124,6 @@ void FifLEEvery250ms(void)
if (error) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("FiF-LE: LE01MR Modbus error %d"), error);
} else {
//if (Le01mr.read_state == 0)
Energy.data_valid[0] = 0;
// SA=Slave Address, FC=Function Code, BC=Byte Count, B3..B0=Data byte, Ch Cl = crc16 checksum
@ -140,9 +150,6 @@ void FifLEEvery250ms(void)
value_buff = ((uint32_t)buffer[3])<<24 | ((uint32_t)buffer[4])<<16 | ((uint32_t)buffer[5])<<8 | buffer[6];
}
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("FiF-LE: LE01MR buff[3..6]: %2x %2x %2x %2x"), buffer[3], buffer[4], buffer[5], buffer[6]);
//AddLog_P2(LOG_LEVEL_DEBUG, PSTR("FiF-LE: LE01MR reg_count/value_buff: %d / %d"), reg_count,value_buff);
switch(Le01mr.read_state) {
case 0:
Energy.frequency[0] = value_buff * 0.01f; // 5000 => 50.00
@ -197,7 +204,6 @@ 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);
FifLEModbus->Send(LE01MR_ADDR, 0x03, le01mr_register_addresses[Le01mr.read_state], reg_count);
} else {
Le01mr.send_retry--;