SPIFFS println weird behavior with long strings · Issue #8372 · esp8266/Arduino (original) (raw)

Basic Infos

Platform

Settings in IDE

Problem Description

Sporadically, File::println("message") fails, and instead of recording "\r\n" it prints 0xFFFF. In this sketch, this happens only with long messages (i.e. >350 chars). However, in more complicated sketches (where multiple write per lines occurs), it happens even with short strings. It happens with Arduino Core 3.x.x, as well as the latest commit, but it works fine in previous releases (2.7.4 and lower).

I know that SPIFFS is deprecated, but this seems a regression and it should be mentioned.

Sketch

print 10 lines on file and then print back to Serial.

#include <FS.h>

void setup() { Serial.begin(115200); while(!Serial); Serial.println();

// You mays need to format the flash before using it //SPIFFS.format();

if(SPIFFS.begin()){ Serial.println("Filesystem mounted successfully"); }else{ Serial.println("Filesystem NOT mounted. System halted"); while(1) delay(100); } }

void loop() { for(int i=0; i<10; ++i){ Serial.println(i); File f = SPIFFS.open("/mytext.txt", "a"); if(f){ f.println("{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}");
f.close();
} else { Serial.println("error"); } delay(1000); }

File f = SPIFFS.open("/mytext.txt", "r"); while(f.available()){ Serial.println(f.readStringUntil('\n')); } f.close(); SPIFFS.remove("/mytext.txt"); }

Debug Messages

Sometimes 2 messages are printed on the same line. It seems that println prints 0xFFFF instead of "\r\n". An example (there are 2 '⸮' in the middle of the string):

{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}⸮⸮{"glossary":{"title":"example glossary","GlossDiv":{"title":"S","GlossList":{"GlossEntry":{"ID":"SGML","SortAs":"SGML","GlossTerm":"Standard Generalized Markup Language","Acronym":"SGML","Abbrev":"ISO 8879:1986","GlossDef":{"para":"A meta-markup language, used to create markup languages such as DocBook.","GlossSeeAlso":["GML","XML"]},"GlossSee":"markup"}}}}}

If I use f.print("mymessage\r\n") the sketch works as expected