diff --git a/tasmota/xnrg_15_teleinfo.ino b/tasmota/xnrg_15_teleinfo.ino index 37b16084f..33a9f35d7 100755 --- a/tasmota/xnrg_15_teleinfo.ino +++ b/tasmota/xnrg_15_teleinfo.ino @@ -333,56 +333,55 @@ void DataCallback(struct _ValueList * me, uint8_t flags) // 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); - } + uint32_t 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