SPIFFS println weird behavior with long strings · Issue #8372 · esp8266/Arduino (original) (raw)
Basic Infos
- This issue complies with the issue POLICY doc.
- I have read the documentation at readthedocs and the issue is not addressed there.
- I have tested that the issue is present in current master branch (aka latest git).
- I have searched the issue tracker for a similar issue.
- If there is a stack dump, I have decoded it.
- I have filled out all fields below.
Platform
- Hardware: Wemos D1 mini
- Core Version: commit: bf2882d
- Development Env: Arduino IDE
- Operating System: Windows
Settings in IDE
- Module: Wemos D1 mini
- Flash Mode: dio
- Flash Size: 4MB
- lwip Variant: v2 Lower Memory
- Reset Method: default
- Flash Frequency: 40Mhz
- CPU Frequency: 80Mhz
- Upload Using: SERIAL
- Upload Speed: 916200
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