Skip to content

Commit 69f509f

Browse files
committed
Combined all phases into one MQTT message
Also fixed a bug to clear peak values at midnight
1 parent 02ecae5 commit 69f509f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

3phase_meter.ino

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ void runAtMidnight(void)
582582
yesterdayPower += (unsigned long)kilos[c];
583583
kilos[c] = 0.0;
584584
peakPower[c] = 0;
585+
peakCurrent[c] = 0;
585586
}
586587
}
587588

@@ -660,12 +661,15 @@ void read3Phase(void)
660661
#endif
661662

662663
if( upd ) { // Have updates to send ...
663-
for ( int c = 0; c < NR_OF_PHASES; c++) {
664+
/* for ( int c = 0; c < NR_OF_PHASES; c++) {
664665
if( upd & (1<<c) ) {
665666
sprintf(topic, "phase_%d", c+1);
666667
sendMsgF(topic, irms[c]);
667668
}
668-
}
669+
}*/
670+
char fBuf[64];
671+
sprintf(fBuf, "{\"l1\":%.2f,\"l2\":%.2f,\"l3\":%.2f}", irms[0], irms[1], irms[2]);
672+
sendMsg("current",fBuf);
669673
}
670674

671675
digitalWrite(LED_BUILTIN, HIGH);

3phase_utils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ void sendStatus(void)
164164
par[cnt++] = p;
165165
p = strchr(p, ';');
166166
}
167+
// Get rid of last ';' ... !
168+
if( p && *p == ';' )
169+
*p = 0;
167170

168171
// Fill in report
169172
String json;
@@ -194,7 +197,7 @@ void sendStatus(void)
194197
})";
195198

196199
local = getNTPtime(); //timeClient.getEpochTime(); //now();
197-
sprintf(dateBuf, "%d.%02d.%02d %02d:%02d:%02d", year(local), month(local), day(local), hour(local), minute(local), second(local));
200+
sprintf(dateBuf, "\"%d.%02d.%02d %02d:%02d:%02d\"", year(local), month(local), day(local), hour(local), minute(local), second(local));
198201

199202
json.replace("$TIME", dateBuf);
200203
json.replace("$TOTAL", par[0]);

0 commit comments

Comments
 (0)