Fix JSON bug with setOption108 0

- Fix duplicate code
- Fix serial bug when used GPIO13 as TX in
- Don't display ID on web interface if not found
This commit is contained in:
Charles 2020-08-23 11:17:33 +02:00
parent b3ea5a353c
commit 8777e33457
1 changed files with 13 additions and 23 deletions

View File

@ -240,16 +240,6 @@ void DataCallback(struct _ValueList * me, uint8_t flags)
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: Power %s, now %d"), me->value, (int) Energy.active_power[0]); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: Power %s, now %d"), me->value, (int) Energy.active_power[0]);
} }
// Wh total base index (legacy)
else if ( ilabel == LABEL_BASE)
{
uint32_t total = atoi(me->value);
if (!Settings.flag4.teleinfo_rawdata) {
EnergyUpdateTotal(total/1000.0f, true);
}
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: Base:%uWh"), total);
}
// Wh indexes (legacy) // Wh indexes (legacy)
else if ( ilabel == LABEL_HCHC || ilabel == LABEL_HCHP || ilabel == LABEL_BASE) else if ( ilabel == LABEL_HCHC || ilabel == LABEL_HCHP || ilabel == LABEL_BASE)
{ {
@ -261,7 +251,7 @@ void DataCallback(struct _ValueList * me, uint8_t flags)
// Base, un seul index // Base, un seul index
if (ilabel == LABEL_BASE) { if (ilabel == LABEL_BASE) {
total = atoi(me->value); total = atoi(me->value);
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: Total:%u"), total); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TIC: Base:%u"), total);
// Heures creuses/pleines calculer total // Heures creuses/pleines calculer total
} else { } else {
// Heures creuses get heures pleines // Heures creuses get heures pleines
@ -351,15 +341,14 @@ void DataCallback(struct _ValueList * me, uint8_t flags)
/* ====================================================================== /* ======================================================================
Function: responseDumpTInfo Function: responseDumpTInfo
Purpose : add teleinfo values into JSON response Purpose : add teleinfo values into JSON response
Input : - Input : 1st separator space if begining of JSON, else comma
Output : - Output : -
Comments: - Comments: -
====================================================================== */ ====================================================================== */
void ResponseAppendTInfo() void ResponseAppendTInfo(char sep)
{ {
struct _ValueList * me = tinfo.getList(); struct _ValueList * me = tinfo.getList();
char sep = ' '; // First JSON value separator
char * p ; char * p ;
boolean isNumber ; boolean isNumber ;
@ -416,7 +405,7 @@ void NewFrameCallback(struct _ValueList * me)
// see setOption108 // see setOption108
if (Settings.flag4.teleinfo_rawdata) { if (Settings.flag4.teleinfo_rawdata) {
Response_P(PSTR("{")); Response_P(PSTR("{"));
ResponseAppendTInfo(); ResponseAppendTInfo(' ');
ResponseJsonEnd(); ResponseJsonEnd();
// Publish adding ADCO serial number into the topic // Publish adding ADCO serial number into the topic
// Need setOption4 to be enabled // Need setOption4 to be enabled
@ -449,8 +438,6 @@ void TInfoInit(void)
{ {
int baudrate; int baudrate;
AddLog_P2(LOG_LEVEL_INFO, PSTR("TIC: inferface saved settings %d bps"), Settings.flag4.teleinfo_baudrate );
// SetOption102 - Set Baud rate for Teleinfo serial communication (0 = 1200 or 1 = 9600) // SetOption102 - Set Baud rate for Teleinfo serial communication (0 = 1200 or 1 = 9600)
if (Settings.flag4.teleinfo_baudrate) { if (Settings.flag4.teleinfo_baudrate) {
baudrate = 9600; baudrate = 9600;
@ -496,8 +483,9 @@ void TInfoInit(void)
// This is a hack, looks like begin does not take into account // This is a hack, looks like begin does not take into account
// the TS_SERIAL_7E1 configuration so on ESP8266 this is // the TS_SERIAL_7E1 configuration so on ESP8266 this is
// working only on Serial RX pin (Hardware Serial) for now // working only on Serial RX pin (Hardware Serial) for now
SetSerialConfig(TS_SERIAL_7E1);
TInfoSerial->setTimeout(TINFO_READ_TIMEOUT); //SetSerialConfig(TS_SERIAL_7E1);
//TInfoSerial->setTimeout(TINFO_READ_TIMEOUT);
AddLog_P2(LOG_LEVEL_INFO, PSTR("TIC: using hardware serial")); AddLog_P2(LOG_LEVEL_INFO, PSTR("TIC: using hardware serial"));
} else { } else {
@ -542,7 +530,7 @@ void TInfoEvery250ms(void)
// get char // get char
c = TInfoSerial->read(); c = TInfoSerial->read();
// data processing // data processing
tinfo.process(c); tinfo.process(c & 0x7F);
} }
} }
} }
@ -580,7 +568,7 @@ void TInfoShow(bool json)
// add teleinfo full frame only if no teleinfo raw data setup // add teleinfo full frame only if no teleinfo raw data setup
if (!Settings.flag4.teleinfo_rawdata) { if (!Settings.flag4.teleinfo_rawdata) {
ResponseAppendTInfo(); ResponseAppendTInfo(',');
} }
@ -635,8 +623,10 @@ void TInfoShow(bool json)
} }
} }
// Serial number ADCO or ADSC // Serial number ADCO or ADSC if found
WSContentSend_PD(HTTP_ENERGY_ID_TELEINFO, serialNumber); if (*serialNumber) {
WSContentSend_PD(HTTP_ENERGY_ID_TELEINFO, serialNumber);
}
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
} }