I have a web connection monitor that pings a site with two pings every 60 sec and records the ping metrics to spiffs that is (infrequently) accessed as required via FTP. Example data from SPIFFS is shown below.
For some reason it SOMETIMES inserts substitute characters at the end of a line. So instead of
; LF (ASCII 3b 20 0a) it records ÿÿÿ (ff ff ff)
It seems to be consistent in that IF its wrong its always the last three characters of the line that are incorrect so (below) *ÿÿÿ SHOULD have been ***LF
ADDED: When I send the fStatsLine to the serial monitor it prints correctly - but the line in SPIFFS is still incorrect.
any ideas?
Date, Time; WiFIStatus%; lost, wait;
2022/03/10, 11:43:34; 100; 0.00, 0.33;
2022/03/10, 11:46:34; ; , ; *** netLogger restart - mains failure? *ÿÿÿ2022/03/10, 11:46:34; ; , ; *** web available ***
2022/03/10, 11:47:46; ; , ; *** netLogger restart - mains failure? ***
2022/03/10, 11:47:46; ; , ; *** web available ***
2022/03/10, 12:46:49; 100; 0.00, 21.45, 2.31ÿÿÿ2022/03/10, 13:46:50; 100; 0.00, 21.17, 2.09;
2022/03/10, 14:46:50; 100; 0.00, 21.53, 2.06;
2022/03/10, 15:46:50; 100; 0.00, 21.37, 1.54;
2022/03/10, 16:46:50; 100; 0.00, 21.63, 2.54ÿÿÿPinging 185.217.104.171 test server
Date, Time; WiFIStatus%; lost, wait, sigma;
2022/03/10, 17:11:21; 100; 0.00, 0.33, 2.56;
2022/03/10, 18:11:22; 100; 0.00, 21.72, 1.92;
2022/03/10, 19:11:23; 100; 0.00, 22.75, 3.39;
2022/03/10, 20:11:22; 100; 0.02, 25.05, 11.66;
2022/03/10, 21:11:22; 100; 0.00, 23.17, 3.03ÿÿÿ2022/03/10, 22:11:23; 100; 0.00, 23.45, 2.86;
2022/03/10, 23:11:23; 100; 0.00, 23.85, 3.34ÿÿÿPinging 185.217.104.171 test server
Date, Time; WiFIStatus%; lost, wait, sigma;
2022/03/11, 00:00:22; 100; 0.00, 20.88, 10.81;
2022/03/11, 01:00:23; 100; 0.00, 25.70, 6.18;
2022/03/11, 02:00:23; 100; 0.00, 27.18, 5.21;
2022/03/11, 03:00:23; 100; 0.00, 27.02, 4.80;
2022/03/11, 04:00:23; 100; 0.00, 28.45, 4.99ÿÿÿ2022/03/11, 05:00:23; 100; 0.02, 27.68, 12.36;
2022/03/11, 06:00:23; 100; 0.00, 28.30, 15.17;
The string to be printed is prepared in "prepStats()" and printed with "writeFile()"
void prepStats() {
//prepare header lines for filing Dont use colons because then date gets separated
//prepare stats line for filing - about 50 chars.
//fHeadLine: Pinging 107.162.133.62 test server
//fHeadLine1: Date, Time; WiFIStatus%; lost, wait;
//fStatsLine: 05/09/2021, 09:00:03; 100; 0.00, 1.90;
if(diagnostic) Serial.println("prepStats: Stats for filing on SPIFFS: ");
fHeadLine = "Pinging ";
fHeadLine += host1[6].ipString;
fHeadLine += testServer;
fHeadLine += "\n";
fHeadLine1 = "Date, Time; WiFIStatus%; lost, wait, sigma;";
fHeadLine1 += "\n";
//prepare total loss values and ping averages - force excel to see as floats
host1[6].nAvPing = (pingLossTotals[6] / nRounds);
host1[6].tAvPing = (tPingTotals[6] / nRounds);
fStatsLine = "";
fStatsLine += myFormattedDate;
fStatsLine += "; ";
//here WiFiUp is just a number; convert to percentage & add to fStatsLine
WiFiUp = WiFiUp * 100;
WiFiPercent = WiFiUp / nRounds;
fStatsLine += WiFiPercent;
fStatsLine += "; ";
//add lost & wait to fStatsLine
fStatsLine += host1[6].nAvPing; //total lost pings
fStatsLine += ", ";
fStatsLine += host1[6].tAvPing; //average ping time
fStatsLine += ", ";
//*** calculate sigma and add to stats line
float temp = host1[6].tSp;
temp *= temp;
temp = temp / nRounds;
temp = host1[6].tSpSq - temp;
temp = temp / nRounds;
sigma = sqrt(temp);
fStatsLine += sigma;
fStatsLine += "; \n"; // END OF STATS LINE WITH ASCII 3b 20 0a
}
void writeFile() { //write stats; and header line only if its a new day or first readings
int bytesWritten;
String fileName = "/" + sYear + "-" + sMonth + ".txt"; //filename MUST be fully qualified ie have a leading slash.
File file = SPIFFS.open(fileName, "a"); //"w" to write a file, "a" to append
if (!file) {
Serial.println("Error opening file for writing");
return;
}
if (DD != today) { //write headline only if its a new day
bytesWritten = file.print(fHeadLine);
bytesWritten = file.print(fHeadLine1);
today = DD;
}
//write stats
bytesWritten = file.print(fStatsLine);
file.close();
}