Merge pull request #11742 from Jason2866/patch-3

Fix for #11680
This commit is contained in:
Theo Arends 2021-04-15 22:39:51 +02:00 committed by GitHub
commit 82c7ac37e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 12 deletions

View File

@ -1915,14 +1915,14 @@ void SML_Immediate_MQTT(const char *mp,uint8_t index,uint8_t mindex) {
// web + json interface
void SML_Show(boolean json) {
int8_t count,mindex,cindex=0;
int8_t count, mindex, cindex = 0;
char tpowstr[32];
char name[24];
char unit[8];
char jname[24];
int8_t index=0,mid=0;
char *mp=(char*)meter_p;
char *cp,nojson=0;
char *cp, nojson = 0;
//char b_mqtt_data[MESSZ];
//b_mqtt_data[0]=0;
@ -1937,9 +1937,9 @@ void SML_Show(boolean json) {
if (mindex<0 || mindex>=meters_used) mindex=0;
if (meter_desc_p[mindex].prefix[0]=='*' && meter_desc_p[mindex].prefix[1]==0) {
nojson=1;
nojson = 1;
} else {
nojson=0;
nojson = 0;
}
mp+=2;
if (*mp=='=' && *(mp+1)=='h') {
@ -2032,27 +2032,35 @@ void SML_Show(boolean json) {
}
if (json) {
if (!dvalid[index]) {
nojson = 1;
//if (dvalid[index]) {
//AddLog(LOG_LEVEL_INFO, PSTR("not yet valid line %d"), index);
}
//}
// json export
if (index==0) {
//snprintf_P(b_mqtt_data, sizeof(b_mqtt_data), "%s,\"%s\":{\"%s\":%s", b_mqtt_data,meter_desc_p[mindex].prefix,jname,tpowstr);
if (!nojson) ResponseAppend_P(PSTR(",\"%s\":{\"%s\":%s"),meter_desc_p[mindex].prefix,jname,tpowstr);
if (!nojson) {
ResponseAppend_P(PSTR(",\"%s\":{\"%s\":%s"),meter_desc_p[mindex].prefix,jname,tpowstr);
}
}
else {
if (lastmind!=mindex) {
// meter changed, close mqtt
//snprintf_P(b_mqtt_data, sizeof(b_mqtt_data), "%s}", b_mqtt_data);
if (!nojson) ResponseAppend_P(PSTR("}"));
if (!nojson) {
ResponseAppend_P(PSTR("}"));
}
// and open new
//snprintf_P(b_mqtt_data, sizeof(b_mqtt_data), "%s,\"%s\":{\"%s\":%s", b_mqtt_data,meter_desc_p[mindex].prefix,jname,tpowstr);
if (!nojson) ResponseAppend_P(PSTR(",\"%s\":{\"%s\":%s"),meter_desc_p[mindex].prefix,jname,tpowstr);
if (!nojson) {
ResponseAppend_P(PSTR(",\"%s\":{\"%s\":%s"),meter_desc_p[mindex].prefix,jname,tpowstr);
}
lastmind=mindex;
} else {
//snprintf_P(b_mqtt_data, sizeof(b_mqtt_data), "%s,\"%s\":%s", b_mqtt_data,jname,tpowstr);
if (!nojson) ResponseAppend_P(PSTR(",\"%s\":%s"),jname,tpowstr);
if (!nojson) {
ResponseAppend_P(PSTR(",\"%s\":%s"),jname,tpowstr);
}
}
}
@ -2073,7 +2081,9 @@ void SML_Show(boolean json) {
if (json) {
//snprintf_P(b_mqtt_data, sizeof(b_mqtt_data), "%s}", b_mqtt_data);
//ResponseAppend_P(PSTR("%s"),b_mqtt_data);
if (!nojson) ResponseAppend_P(PSTR("}"));
if (!nojson) {
ResponseAppend_P(PSTR("}"));
}
} else {
//WSContentSend_PD(PSTR("%s"),b_mqtt_data);
}