How does openlog readFile work?

Instead of trying to read my MicroSD direct with the computer, I've set up a "logswitch" button, whereby when HIGH, openlog will log data to test.log. When it is LOW, I want to readFile, and dump the data to the serial port (where I can capture the whole log with gobetweeno).

Is this practical or possible? If so, could someone help me with the readFile(x, y, z)? I would really just like a better explanation of how readFile works- as in, x is filename, y is start record (zero- I want the whole log) and z? can I determine the end of the record on the SD, then set it as a variable in place of z- in order to save the entire log to variable fullog?

ps, I know there is a problem with this part of the sketch, since openlog is not dropping into command mode (and therefore printing 13 to serial monitor). The logging part works fine though :slight_smile:

void logserial(){ 
  logger.begin(9600);
  if(digitalRead(logswitchpin) == HIGH){
  //logger.print(26, BYTE);
  //logger.print(26, BYTE);
  //logger.print(26, BYTE);
  //logger.print(13, BYTE);
  //delay(wait); 
  //logger.print("append ");
  //logger.print("test.log");
  //logger.print(13, BYTE);
  //delay(wait);
  DateTime now = RTC.now();
   if(now.hour() < 10) {
     logger.print("0");
    }
  logger.print(now.hour(), DEC);
    logger.print(':');
    if(now.minute() < 10) {
      logger.print("0");
    }
    logger.print(now.minute(), DEC);
    logger.print(':');
    if(now.second() < 10) {
      logger.print("0");
    }
    logger.print(now.second(), DEC);
  logger.print(" ");
  logger.print(temp);
  logger.print(13, BYTE);
  logger.print(10, BYTE);
  }
  if(digitalRead(logswitchpin) != HIGH){// if we aren't loggin', were printin'!
  logger.print("sync");
  logger.print(13, BYTE);
  readFile("test.log",0, 8);
  String fulllog;
  fulllog = logger.read();
  Serial.begin(9600);
  delay(wait);
  Serial.print(fulllog);
  }
}
void readFile(char fname[40], int start, int length)
{
  int wait = 200;

  //Send escape command
  logger.print(26, BYTE);
#ifdef OPENLOG_VERSION  NEW
  logger.print(26, BYTE);
  logger.print(26, BYTE);
#endif
  //We don't know where we are without checking. Either we just dropped to command prompt, or we were already sitting at the command prompt.
  //If we were already at the command prompt, then we've got a bunch of command characters sitting there.
  //Press enter to dump them
  logger.print(13, BYTE);
  delay(wait);
  logger.print("read ");
  logger.print(fname);
  logger.print(" ");
  logger.print(start);
  logger.print(" ");
  logger.print(length);

  //OpenLog is echoing all the commands up to this point including 'read test.log 0 100', etc. We don't want this stuff in the buffer
  logger.flush(); //Remove all the trash in the current buffer

  //Now send the enter command to OpenLog to actually initiate the read command
  logger.print(13, BYTE);

  delay(wait);
}

Hmmm re-read the commands list over at GitHub, looks like sending openlog simply "read test.log" then ASCII 13, then doing a logger.read() will read the entire contents of the file, start to finish...

You know, I think most of the problems people have with openlog aren't because of openlog itself- but because the openlog examples given do not work. I reworked the example sketch, and I have at least the logging part of mine working flawlessly, every time. As soon as I can get the readfile working, I'm going to post up a new example that is tested and working(for at least the newest version of openlog).

hi!

did you manage to read a file / a string / whatever from openlog until today?

what i figured out is, that you need openlog to have firmware v2.5 to send it back to logging-mode using the 'reset' command from the command-mode.

perhaps we can help each other.

what i managed to achieve until now is: startup openlog, tell it to go to command-mode, tell it to open a file (which it does), and then send it back to log-mode.

what somehow doesn't work is reading openlogs output following the 'read file.txt' command to a variable which i could use.
it seems that something like this doesn't work (with or without the delay(50)):

String str="";

while (Serial.available()) {
    delay(50);
    char c = Serial.read();
    str += c;
  }

anyone an idea on how to read in the output the 'read file.txt' command of openlog in command-mode?