Fix SDM120 modbus dump and Domoticz Energy Consumed or Produced

Fix SDM120 modbus dump exception and Domoticz Energy Consumed or Produced (#6282)
This commit is contained in:
Theo Arends 2019-09-05 18:02:36 +02:00
parent ab89bb53a9
commit a1e9c2d2ac
5 changed files with 15 additions and 7 deletions

View File

@ -824,7 +824,7 @@ void EnergyShow(bool json)
char energy_total1_chr[FLOATSZ];
dtostrfd(Energy.total1 * 1000, 1, energy_total1_chr); // Tariff1
char energy_non[2] = "0";
DomoticzSensorP1SmartMeter(energy_total1_chr, energy_total_chr, energy_non, energy_non, (int)Energy.active_power, 0);
DomoticzSensorP1SmartMeter(energy_total1_chr, energy_total_chr, energy_non, energy_non, (int)Energy.active_power);
if (Energy.voltage_available) {
DomoticzSensor(DZ_VOLTAGE, voltage_chr); // Voltage

View File

@ -383,14 +383,19 @@ void DomoticzSensorPowerEnergy(int power, char *energy)
DomoticzSensor(DZ_POWER_ENERGY, data);
}
void DomoticzSensorP1SmartMeter(char *usage1, char *usage2, char *return1, char *return2, int consumed, int produced)
void DomoticzSensorP1SmartMeter(char *usage1, char *usage2, char *return1, char *return2, int power)
{
//usage1 = energy usage meter tariff 1, This is an incrementing counter
//usage2 = energy usage meter tariff 2, This is an incrementing counter
//return1 = energy return meter tariff 1, This is an incrementing counter
//return2 = energy return meter tariff 2, This is an incrementing counter
//consumed = actual usage power (Watt)
//produced = actual return power (Watt)
//power = if >= 0 actual usage power. if < 0 actual return power (Watt)
int consumed = power;
int produced = 0;
if (power < 0) {
consumed = 0;
produced = -power;
}
char data[64];
snprintf_P(data, sizeof(data), PSTR("%s;%s;%s;%s;%d;%d"), usage1, usage2, return1, return2, consumed, produced);
DomoticzSensor(DZ_P1_SMART_METER, data);

View File

@ -64,7 +64,7 @@ void PzemAcEverySecond(void)
uint8_t buffer[26];
uint8_t error = PzemAcModbus->ReceiveBuffer(buffer, 10);
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer));
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, sizeof(buffer));
if (error) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "PzemAc response error %d"), error);

View File

@ -46,7 +46,7 @@ void PzemDcEverySecond(void)
uint8_t buffer[22];
uint8_t error = PzemDcModbus->ReceiveBuffer(buffer, 8);
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer));
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, sizeof(buffer));
if (error) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "PzemDc response error %d"), error);

View File

@ -86,13 +86,16 @@ void SDM120Every200ms(void)
uint8_t buffer[9];
uint32_t error = Sdm120Modbus->ReceiveBuffer(buffer, 2);
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, (uint8_t*)buffer, (buffer[2]) ? buffer[2] +5 : sizeof(buffer));
AddLogBuffer(LOG_LEVEL_DEBUG_MORE, buffer, sizeof(buffer));
if (error) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "SDM120 response error %d"), error);
} else {
Energy.data_valid = 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;
((uint8_t*)&value)[3] = buffer[3]; // Get float values
((uint8_t*)&value)[2] = buffer[4];