From 637f456e00c7d06b1d15c130868729bebf7352dc Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 13 Dec 2021 12:18:47 +0100 Subject: [PATCH 1/2] Fix some calculation --- tasmota/xnrg_15_teleinfo.ino | 55 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/tasmota/xnrg_15_teleinfo.ino b/tasmota/xnrg_15_teleinfo.ino index 37b16084f..4c19a1f16 100755 --- a/tasmota/xnrg_15_teleinfo.ino +++ b/tasmota/xnrg_15_teleinfo.ino @@ -327,62 +327,61 @@ void DataCallback(struct _ValueList * me, uint8_t flags) else if ( ilabel == LABEL_HCHC || ilabel == LABEL_HCHP || ilabel == LABEL_BASE) { char value[32]; - uint32_t hc = 0; - uint32_t hp = 0; - uint32_t total = 0; + long hc = 0; + long hp = 0; + long total = 0; // Base, un seul index if (ilabel == LABEL_BASE) { - total = atoi(me->value); - AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Base:%u"), total); + total = atol(me->value); + AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Base:%ld"), total); // Heures creuses/pleines calculer total } else { // Heures creuses get heures pleines if (ilabel == LABEL_HCHC) { - hc = atoi(me->value); + hc = atol(me->value); if ( getValueFromLabelIndex(LABEL_HCHP, value) ) { - hp = atoi(value); + hp = atol(value) ; } // Heures pleines, get heures creuses } else if (ilabel == LABEL_HCHP) { - hp = atoi(me->value); + hp = atol(me->value); if ( getValueFromLabelIndex(LABEL_HCHC, value) ) { - hc = atoi(value); + hc = atol(value) ; } } - total = hc + hp; - AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%u HP:%u Total:%u"), hc, hp, total); + if (hc>0 && hp>0) { + total = hc + hp; + } + AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%ld HP:%ld Total:%ld"), hc, hp, total); } - Energy.import_active[0] = total/1000.0f; - EnergyUpdateTotal(); - AddLog (LOG_LEVEL_INFO, PSTR ("TIC: Total counter updated to %u Wh"), total); + AddLog (LOG_LEVEL_INFO, PSTR ("TIC: Total counter updated to %ld Wh"), total); + if (total>0) { + Energy.import_active[0] = (float)total/1000.0f; + EnergyUpdateTotal(); + AddLog (LOG_LEVEL_DEBUG_MORE, PSTR ("TIC: import_active[0]=%.3fKWh"), Energy.import_active[0] ); + } } - // Wh total index (standard) + // Wh total index (all contract) else if ( ilabel == LABEL_EAST) { - uint32_t total = atoi(me->value); - if (contrat != CONTRAT_BAS) { - Energy.import_active[0] = total/1000.0f; - EnergyUpdateTotal(); - AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Total:%uWh"), total); - } + long total = atol(me->value); + Energy.import_active[0] = (float)total/1000.0f; + EnergyUpdateTotal(); + AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Total:%ldWh"), total); } // Wh indexes (standard) else if ( ilabel == LABEL_EASF01) { - if (contrat == CONTRAT_BAS) { - Energy.import_active[0] = atoi(me->value)/1000.0f; - EnergyUpdateTotal(); - } - AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%u"), atoi(me->value)); + AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HC:%ld"), atol(me->value)); } else if ( ilabel == LABEL_EASF02) { - AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HP:%u"), atoi(me->value)); + AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: HP:%ld"), atol(me->value)); } // Contract subscribed (legacy) @@ -504,7 +503,7 @@ bool ResponseAppendTInfo(char sep, bool all) if (!isNumber) { ResponseAppend_P( PSTR("\"%s\""), me->value ); } else { - ResponseAppend_P( PSTR("%d"), atoi(me->value)); + ResponseAppend_P( PSTR("%ld"), atol(me->value)); } // Now JSON separator is needed From b631270b624a4ecd7b7cb4b0311a09f2b2275b1e Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 9 Jan 2022 20:51:05 +0100 Subject: [PATCH 2/2] revert long to uint32_t --- tasmota/xnrg_15_teleinfo.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tasmota/xnrg_15_teleinfo.ino b/tasmota/xnrg_15_teleinfo.ino index 4c19a1f16..33a9f35d7 100755 --- a/tasmota/xnrg_15_teleinfo.ino +++ b/tasmota/xnrg_15_teleinfo.ino @@ -327,9 +327,9 @@ void DataCallback(struct _ValueList * me, uint8_t flags) else if ( ilabel == LABEL_HCHC || ilabel == LABEL_HCHP || ilabel == LABEL_BASE) { char value[32]; - long hc = 0; - long hp = 0; - long total = 0; + uint32_t hc = 0; + uint32_t hp = 0; + uint32_t total = 0; // Base, un seul index if (ilabel == LABEL_BASE) { @@ -368,7 +368,7 @@ void DataCallback(struct _ValueList * me, uint8_t flags) // Wh total index (all contract) else if ( ilabel == LABEL_EAST) { - long total = atol(me->value); + uint32_t total = atol(me->value); Energy.import_active[0] = (float)total/1000.0f; EnergyUpdateTotal(); AddLog(LOG_LEVEL_DEBUG, PSTR("TIC: Total:%ldWh"), total);