Fixed, but I don't know what is causing the problem, hence the topic.
Parsing a text file to create a JSON object. The text file is of the form:
VERSION=Oil Sensor V10.2, 02 Feb 23
LEVEL=369
SUCCESS=255
TOTAL=264
DATE=Sat 04 Feb 2023, 16:37
UNIXT=1675528654
PERCENT=96.59
VOLT=5.02
TEMP=19.50
FULL=0
And the output should be of the form:
String Result = {"version":"text string","level":value, etc...}
^ ^
except CR (0x0D) are being inserted after all the values as indicated before the comma delimiter. Checked and rechecked the source file to ensure that no carriage returns are inserted, each line in the input file is only terminated with a line feed.
The code parsing the text file:
const String VersionNo = "VERSION=";
...repeat definitions for other lines
while (ReadingsF.available()) {
aline = ReadingsF.readStringUntil(LF); //read a line from file
//check for VERSION
if (aline.indexOf(VersionNo) == 0) {
aline.replace(VersionNo,"");
Result += qt + "version" + qt + delim;
Result += qt + aline + qt + comma;
continue; //go to next iteration
}
...repeat for other variables in text file
qt (quote) is a double quote (") and delim is a colon. Somehow aline is acquiring a CR at the end of the string?
Fixed by searching for and replacing all occurrences of CR in the Result string, but how did the CR get there in the first place??
Background - this is an oil level sensor for my central heating oil tank using a JSN-SRN04T (also caused me problems). ESP8266 on the tank takes readings, ftp's readings every few hours (format as above) then goes to sleep. Files are ftped to another ESP8266 acting as a webserver that delivers a webpage showing how much I've got.
Development environment - running linux (mint) with Arduino 1.8.19.
