1

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();
    command.trim();
    Serial.println(command);

    if (command == "today")
    {
        //client.println("hello");

        // 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') {
                //client.println("");               
              }
              Serial.print(c);
              client.print(c);
          }
          myFile.close();
      }
    }

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

  } else {
      MonitorIRGate();
  }
}

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.