mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-27 12:46:34 +00:00
Add debugging info to modbus.ino
This commit is contained in:
parent
22803e3e3d
commit
587e8299d6
@ -319,6 +319,7 @@ void EnergyUpdateTotal(void) {
|
|||||||
|
|
||||||
if ((Energy.total[i] < (Energy.import_active[i] - 0.01f)) && // We subtract a little offset to avoid continuous updates
|
if ((Energy.total[i] < (Energy.import_active[i] - 0.01f)) && // We subtract a little offset to avoid continuous updates
|
||||||
Settings->flag3.hardware_energy_total) { // SetOption72 - Enable hardware energy total counter as reference (#6561)
|
Settings->flag3.hardware_energy_total) { // SetOption72 - Enable hardware energy total counter as reference (#6561)
|
||||||
|
// The following calculation allows total usage (Energy.import_active[i]) up to +/-21474 kWh
|
||||||
RtcSettings.energy_kWhtotal_ph[i] = (int32_t)((Energy.import_active[i] * 100000) - Energy.kWhtoday_offset[i] - Energy.kWhtoday[i]);
|
RtcSettings.energy_kWhtotal_ph[i] = (int32_t)((Energy.import_active[i] * 100000) - Energy.kWhtoday_offset[i] - Energy.kWhtoday[i]);
|
||||||
Settings->energy_kWhtotal_ph[i] = RtcSettings.energy_kWhtotal_ph[i];
|
Settings->energy_kWhtotal_ph[i] = RtcSettings.energy_kWhtotal_ph[i];
|
||||||
Energy.total[i] = (float)(RtcSettings.energy_kWhtotal_ph[i] + Energy.kWhtoday_offset[i] + Energy.kWhtoday[i]) / 100000;
|
Energy.total[i] = (float)(RtcSettings.energy_kWhtotal_ph[i] + Energy.kWhtoday_offset[i] + Energy.kWhtoday[i]) / 100000;
|
||||||
|
@ -280,10 +280,6 @@ void EnergyModbusLoop(void) {
|
|||||||
// Even data type is single register, Odd data type is double registers
|
// Even data type is single register, Odd data type is double registers
|
||||||
register_count = 2 - (NrgMbsReg[NrgMbsParam.state].datatype & 1);
|
register_count = 2 - (NrgMbsReg[NrgMbsParam.state].datatype & 1);
|
||||||
uint32_t error = EnergyModbus->ReceiveBuffer(buffer, register_count);
|
uint32_t error = EnergyModbus->ReceiveBuffer(buffer, register_count);
|
||||||
|
|
||||||
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("NRG: Modbus register %d, phase %d, rcvd %*_H"),
|
|
||||||
NrgMbsParam.state, NrgMbsParam.phase, EnergyModbus->ReceiveCount(), buffer);
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
/* Return codes from TasmotaModbus.h:
|
/* Return codes from TasmotaModbus.h:
|
||||||
* 0 = No error
|
* 0 = No error
|
||||||
@ -302,6 +298,10 @@ void EnergyModbusLoop(void) {
|
|||||||
* 13 = Register data not specified
|
* 13 = Register data not specified
|
||||||
* 14 = To many registers
|
* 14 = To many registers
|
||||||
*/
|
*/
|
||||||
|
#ifdef ENERGY_MODBUS_DEBUG
|
||||||
|
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("NRG: Modbus register %d, phase %d, rcvd %*_H"),
|
||||||
|
NrgMbsParam.state, NrgMbsParam.phase, EnergyModbus->ReceiveCount(), buffer);
|
||||||
|
#endif
|
||||||
AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: Modbus error %d"), error);
|
AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: Modbus error %d"), error);
|
||||||
} else {
|
} else {
|
||||||
/* Modbus protocol format:
|
/* Modbus protocol format:
|
||||||
@ -386,6 +386,10 @@ void EnergyModbusLoop(void) {
|
|||||||
value *= factor;
|
value *= factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("NRG: Modbus register %d, phase %d, rcvd %*_H, T %d, F %d, value %4_f"),
|
||||||
|
NrgMbsParam.state, NrgMbsParam.phase, EnergyModbus->ReceiveCount(), buffer,
|
||||||
|
NrgMbsReg[NrgMbsParam.state].datatype, NrgMbsReg[NrgMbsParam.state].factor, &value);
|
||||||
|
|
||||||
switch (NrgMbsParam.state) {
|
switch (NrgMbsParam.state) {
|
||||||
case NRG_MBS_VOLTAGE:
|
case NRG_MBS_VOLTAGE:
|
||||||
Energy.voltage[NrgMbsParam.phase] = value; // 230.2 V
|
Energy.voltage[NrgMbsParam.phase] = value; // 230.2 V
|
||||||
|
Loading…
x
Reference in New Issue
Block a user