danadak
December 30, 2024, 10:16pm
1
The output I am getting -
The code
void DispStatus() {
Serial.println(" ");
Serial.println("Status :");
Serial.println(" ");
if (PumpMan1Auto0Mode) {
Serial.println(" Manual Mode");
} else {
Serial.println(" Auto Mode");
}
if (PumpStat == 1) {
Serial.println(" Pump on");
} else {
Serial.println(" Pump off");
}
if (FloatFlg) {
Serial.println(" Float High");
} else {
Serial.println(" Float Low");
}
StringTemp = " Pump Normal Cycles = ";
StringTemp.concat(PumpActiveCycles);
Serial.println(StringTemp);
StringTemp = " Pump Jog Cycles = ";
StringTemp.concat(PumpJogCycles);
Serial.println(StringTemp);
if (FloatStuckHiCntrMins >= FloatStuckMinsHighLimit) {
StringTemp = " Stuck Float Hi cnt (Mins) = ";
StringTemp.concat(FloatStuckHiCntrMins);
StringTemp.concat("____ Limit = ");
StringTemp.concat(FloatStuckMinsHighLimit);
Serial.println(StringTemp);
}
if (FloatStuckLowCntrMins >= FloatStuckMinsLowLimit) {
StringTemp.concat(" Stuck Float Low cnt (Mins) = ");
StringTemp.concat(FloatStuckLowCntrMins);
StringTemp.concat("____ Limit = ");
StringTemp.concat(FloatStuckMinsLowLimit);
Serial.println(StringTemp);
}
StringTemp = " Tot Float Stuck Hi cnt = ";
StringTemp.concat(TotalFloatStuckHighCnt);
Serial.println(StringTemp);
StringTemp = "";
StringTemp = " Tot Float Stuck Lo cnt = ";
StringTemp.concat(TotalFloatStuckLowCnt);
Serial.println(StringTemp);
if (MaxOnTimeFlg == 1) {
StringTemp = " Pump Max Time Limit Exceeded = ";
StringTemp.concat(MaxManOnTimeLim / 60);
StringTemp.concat(" Minutes");
Serial.println(StringTemp);
}
}
As you can see I get double printing in one case, pump jog cycles printout,
and a line appended to that duplicate line which shoulkd be a new line.
Debugger set for CR & LF in the monitor.
Device is ESP32, IDE is 2.3.4
Any help as always greatly appreciated.
xfpd
December 30, 2024, 10:26pm
2
danadak:
StringTemp
If you posted the code that compiles, I suspect you have overrun this buffer.
Since the ESP32 core supports printf, why would you mess around with String? Assuming all those variables are ints, it reduces to:
void DispStatus() {
.
.
.
Serial.printf(" Pump Normal Cycles = %d\n", PumpActiveCycles);
Serial.printf(" Pump Jog Cycles = %d\n", PumpJogCycles);
if (FloatStuckHiCntrMins >= FloatStuckMinsHighLimit) {
Serial.printf(" Stuck Float Hi cnt (Mins) = %d____ Limit = %d\n",
FloatStuckHiCntrMins, FloatStuckMinsHighLimit);
}
if (FloatStuckLowCntrMins >= FloatStuckMinsLowLimit) {
Serial.printf((" Stuck Float Low cnt (Mins) = %d____ Limit = %d\n",
FloatStuckLowCntrMins, FloatStuckMinsLowLimit);
}
Serial.printf(" Tot Float Stuck Hi cnt = %d\n", TotalFloatStuckHighCnt);
Serial.printf(" Tot Float Stuck Lo cnt = %d\n", TotalFloatStuckLowCnt);
if (MaxOnTimeFlg == 1) {
Serial.printf(" Pump Max Time Limit Exceeded = %d Minutes\n",
MaxManOnTimeLim / 60);
}
}
1 Like
danadak
December 30, 2024, 10:52pm
4
I am using Tuniot (block programming tool), which targets the Arduino IDE,
to gen the code. So Tuniot gens the code I posted, and the Arduino IDE compiler
seems to be good with it.
Code compiles fine in Arduino IDE, so not sure why the
Serial.println statements not working right, some of the time.
Regards, Dana.
danadak
December 31, 2024, 12:35am
5
But i keep assigning new strings to the buffer, which overwrites, not adds, unless
I was doing continuous concatenations right ?
Note I was suspicious about buffer behavior so I preceded all assigns with a
StringTemp = ""; that made no difference.
Regards, Dana.
StringTemp = " Pump Jog Cycles = ";
StringTemp.concat(PumpJogCycles);
Serial.println(StringTemp);
if (FloatStuckHiCntrMins >= FloatStuckMinsHighLimit) {
StringTemp = " Stuck Float Hi cnt (Mins) = ";
StringTemp.concat(FloatStuckHiCntrMins);
StringTemp.concat("____ Limit = ");
StringTemp.concat(FloatStuckMinsHighLimit);
Serial.println(StringTemp);
}
if (FloatStuckLowCntrMins >= FloatStuckMinsLowLimit) {
StringTemp.concat(" Stuck Float Low cnt (Mins) = ");
StringTemp.concat(FloatStuckLowCntrMins);
StringTemp.concat("____ Limit = ");
StringTemp.concat(FloatStuckMinsLowLimit);
Serial.println(StringTemp);
}
Code is doing exactly what you asked it to. In the 2nd if statement, you concatenate onto whatever is already in StringTemp, leading to the double printing of the pump jog cycles.
It seems that Tuniot forgot to reinitialize the String variable for the second go-around. Or you modified the code and introduced that error,
As pointed out, there is no need to use Strings, and they very often cause memory problems on Arduinos with small amounts of RAM.
danadak
December 31, 2024, 2:04am
8
Thanks David, that was the problem. I am blind as a bat, prescription glasses
not helping anymore....
Thanks all who contributed aid to me.
Regards, Dana.
danadak
December 31, 2024, 10:26am
9
The application is ESP32.
Tuniot was not in error, I did not init for a new string, kept
adding to old one. Note compiler memory manager fine
with my error as it did not detect any violation. Problem was
just my bad coding.
system
Closed
June 29, 2025, 10:27am
10
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.