Help saving Serial Conversations

Hello, I am working on a school project to water 8 plants automatically. So far, the code is great and serves its purpose. But when the user finishes the conversation, closes the serial monitor that was used to talk, and opens it again, the conversation just doesn't save into the monitor. So, I need help finding a way for the serial monitor to save the conversations and keep them there even when the monitor is closed.

int motor = 7; 
float dayset = 0;  // Change to float for decimal input
unsigned long daycal = 0;
bool isOn = false;  // Use a boolean variable for true/false states
int dayspass = 0;
int timethatdidpass;

void setup() {
  Serial.begin(9600);
  pinMode(motor, OUTPUT);
  Serial.println("Hello, welcome to David's Aqua Bionic. Please insert the number of days for the cycle.");
}

void loop() {
  if (!isOn) {
    // Wait for user input
    while (Serial.available() == 0) {}

    dayset = Serial.parseFloat();  // Use parseFloat to handle decimal values
    daycal = (unsigned long)(dayset * 24 * 60 * 60 * 1000);  // Convert days to milliseconds

    Serial.println("Ok, loading...");
    delay(2000);
    Serial.print("Time set in Arduino time (milliseconds): ");
    Serial.println(daycal);
    Serial.println("Loading again...");
    delay(3000);
    Serial.println("Thanks for waiting! The Aqua Bionic is ready for use now. If you need help, ask David. (Side note when you type log you need to wait until the day passed and the log will be showed))");
    isOn = true;  // Set the flag to indicate the system is ready
  } else {
    // Default motor schedule
    delay(2000);
    Serial.println("We have passed the else stage");
       
    // Check if the user entered "log" while waiting for the motor cycle
    if (Serial.available() > 0) {
      String command = Serial.readStringUntil('\n');
      if (command == "log") {
        Serial.println("Welcome to the log, here is the information that we have gathered:");
        timethatdidpass = daycal * dayspass*1000;  // Corrected to use dayspass and added semicolon
        delay(2000); 
        Serial.println(timethatdidpass);
      }
    }
    delay(daycal);
    digitalWrite(motor, HIGH);
    Serial.println("High");
    dayspass = dayspass + 1;
    Serial.println(dayspass);
    delay(16000);
    Serial.println("Low");
    digitalWrite(motor, LOW);
  }
}

Sorry for the cutoff message my cat did it

Use a better terminal program like PuTTY or similar that can record the terminal session.

PUTTY DOWNLOADS

1 Like

Is there another way? (I am just looking for different solutions for my school document).

Write your own program using something like Python?

1 Like

I'm wondering why OP needs to save the messages, are they looking to save settings?
(EEPROM?)
(Pardon if this is not what is desired. - unsure.)

Yeah I need to save the settings but then also to show that my machine does work for days and not for the span of like 5 min.

So it has to be Serial data to show that? What about some pattern of led blinking using the built in led? That would show it's still making it through the loop and presumably working the same as the last time you examined the data from the Serial monitor, or wouldn't it?

I like the serial monitor and since everything is there I just decided to add that in there too. The ELD is not a bad idea though I like it. (Edit: I am using "logs" to save my data using the serial monitor.)

I recommend the TeraTerm terminal emulator, as it seems easier to use than PuTTY. Saving complete session log files is trivial and reliable, for weeks to months at a time.

2 Likes

You may like this

which is a branded version I think of an open source project call openlog. You can find less expensive modules and risk whatever that would be risking.

Drop one into your project and everything "said" is recorded.

a7

2 Likes