The below code is meant to display lines stored in a text file to an arduino based web page (it's a IR gate monitoring solution).

When I visit I can execute client.println("hello") and I see the word "hello" on the page.

Then I loop round the SD card rows and I can Serial.print (by char) in the Serial Monitor all the lines in the text file. Great - so far so good.

But when I attempt to print to screen (instead of Serial Monitor) it does not work. The offending line (but don't know why) is the FileSystem.Open - this prevents any further output to screen.

Why does FileSystem.Open prevent client.print from working?

  void loop() {

  YunClient client = server.accept();

  if (client) {
    String command = client.readString();

    if (command == "today")

        // Get a timestamp
        String strTS = getTimeStamp();
        String strFileName = strTS;

        // Build the file name containing the 
        strFileName.replace("-", "_");
        strFileName.replace("/", "-");
        strFileName.replace(":", "-");
        strFileName = strFileName.substring(0, 8);
        strFileName = "/mnt/sd/BeerLogger/" + strFileName + ".txt";

        // Display the file name in the serial window
      //  Serial.println((strFileName).c_str());

        // Print the contents of the text file to screen
        File myFile = FileSystem.open(strFileName.c_str(), FILE_READ);

        if (myFile) {
           while (myFile.available()) {
              char c = myFile.read();
              if ( c == '\n') {

    // Terminate the client connection so we may resume
    //Serial.println("client disconnected");

  } else {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.