[Solved] SD Datalogger dataFile.close() issue

Hi dear geniuses,

So I just bought an Arduino Yun for the first time.
I directly uploaded the OPENWRT-YUN 1.5.3 to be sure I had the last version. And tried the datalogger example of Arduino IDE over Serial with a FAT32 SD card I had. This example simply to create a string with a timestamp and values from analog ports and then uses the Bridge.h to write it over the SD card on a txt file. This happens at least every 15secs because of the delay(15000) at the end of the loop. I only modified the code to write random value between 0 and 100 instead of taking values from Analog Ports and speeded up the code by reducing the delay to 5 seconds.

The problem is that after the first line writing, the Arduino stop appending the time stamp (as showed in the serial monitor as followed - I added line numbers manually here) :

[sub](1) Filesystem datalogger
(2) 
(3) 07/11/15-20:26:28 = 261,207,160
(4)  = 90,112,91
(5)  = 89,110,90
(6)  = 89,110,90
(7)  = 90,112,91[/sub]

Moreover, the writing speed is incredibly low, this writing appears every 25 seconds with the original code. When I change the delay in the end of the loop() to 5000ms, the writing keep happening every 25 seconds.

I tried to play around with the code to see where the delay happens. I added time lapses calculation and prints every line of the writing process and it seems that the line "dataFile.close();" is somehow "bloking" the loop for a long time. Even though, surprisingly the time lapse for this line is not over 20ms when the loop is "unblocked". I'm Lost -_-

Here is a detail of the full code I used (that is directly copied from the example provided in the Arduino IDE with only the random(0,100) line modified early in the loop() function)

[sub]#include <FileIO.h>

void setup() {
  // Initialize the Bridge and the Serial
  Bridge.begin();
  Serial.begin(9600);
  FileSystem.begin();

  while (!Serial); // wait for Serial port to connect.
  Serial.println("Filesystem datalogger\n");
}


void loop () {
  // make a string that start with a timestamp for assembling the data to log:
  String dataString;
  dataString += getTimeStamp();
  dataString += " = ";

  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = random(0,100);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ",";  // separate the values with a comma
    }
  }

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  // The FileSystem card is mounted at the following "/mnt/FileSystema1"
  File dataFile = FileSystem.open("/mnt/sd/datalog.txt", FILE_APPEND);

  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  }

  delay(15000);

}

// This function return a string with the time stamp
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;
}[/sub]

Hopping I provided you with enough informations, I also hope that you will be able to guide me.

I already thank you for your help

Cheers

KGRI

[Solved]

The Bridge Library wasn't up to date in my Arduino IDE.
Upgrading it solved the issue, and I'm now able to get the time stamp and write on the SD card with about 0.2sec delay.