-
Notifications
You must be signed in to change notification settings - Fork 7k
[Yun] Buffer overflow (maybe?) when writing to SD card #4530
Description
I modified the DataLogger Yun example to work in my project and i noticed a very strange behaviour when the data is written on the SD.
Working code:
`
...
float liv; //variable used to read data from a sensor
...
void loop() {
...
String dataString = "";
dataString = getTimeStamp();
Serial.println(dataString);
File dataFile = FileSystem.open("/mnt/sda1/datalog.txt", FILE_APPEND);
if (dataFile) {
dataFile.println(getTimeStamp() + "," + String(liv));
dataFile.close();
}
...
}
String getTimeStamp() {
String result;
Process time;
// date is a command line utility to get the date and the time
// in different formats depending on the additional parameter
time.begin("date");
time.addParameter("+%D-%T"); // parameters: D for the complete date mm/dd/yy
// T for the time hh:mm:ss
time.run(); // run the command
// read the output of the command
while (time.available() > 0) {
char c = time.read();
if (c != '\n') {
result += c;
}
}
return result;
}`
As you can notice the dataString variable isn't used and I want to remove it, but when I do, dataFile becomes unavailable and I can't write on the SD.
I tried to show dataString in the Serial monitor and I noticed that the output is very strange:
�101
After 101 there is a number of spaces increasing on every loop() cycle but the output of getTimeStamp on the SD is always fine.
Even assigning a custom value to dataString changes nothing on the SD side (nothing is written).
So I assumed that getTimeStamp is causing an overflow in the string and it's causing dataFile to work (???).
Am I doing something wrong or is something going wrong on the Arduino?