Printing DateTime variable within object

Hello folks !

I'm testing the functionality of my function findDateHour (). This functions reads a JSON which contains the values of day,hour,minute and seconds. And it should store them within *schedule. I made a DateTime type variable which will have those values. Let's go for the coding.

// Function that reads characters and stops when the declared char is found.
void ReadCaracter (char c, File file) {  
    char caracter;
    while (file.available()) {
      caracter = file.read();
      if (caracter == c) break;
    }


void findDateHour(Schedules *schedule) {
    int dayy, hourr, minutes, seconds;
    int monthh = 12; int yearr = 2016;

    LeCaracter(':', file);
    

    dayy = ((file.read() - 48));
    Serial.print("Day : ");
    Serial.println(dayy);

    ReadCaracter(':', file);
    ReadCaracter('"', file);

    hourr = ((file.read() - 48) * 10);
    hourr = hourr + ((file.read() - 48));
    Serial.print("Hour : ");
    Serial.println(hourr);

    ReadCaracter(':', file);

    minutes = ((file.read() - 48) * 10);
    minutes = minutes + ((file.read() - 48));
    Serial.print("Minutes : ");
    Serial.println(minutes);

    ReadCaracter(':', file);

    seconds = ((file.read() - 48) * 10);
    seconds = seconds + ((file.read() - 48));
    Serial.print("Seconds : ");
    Serial.println(seconds);

    // Creates dateTime variable
    
DateTime date =  DateTime(yearr, monthh, dayy, hourr, minutes, seconds);
    schedule->setHourSchedule(date);

   
}


}

So my question is, i want to print in the serial the getHourSchedule(), but Serial.println(schedule->getHourSchedule()); is not working. How should I do then?

Schedules.h

class Schedules 
    {
        public:
            void setHourSchedule(DateTime hourSchedule);
            DateTime getHoraAgendamento();
            
            
        private :
            DateTime hourSchedule;
            
      
    };

Schedules.cpp

void Scheduless::setHourSchedule(DateTime data){
	
	hourSchedule = data;
}

DateTime Schedules::getHourSchedule(){
	return hourSchedule;
}

Thanks in advance,

Rezik

I may be misunderstanding your application, but:

  1. You state the your file is a JSON with comma delimiters between day,hr,min,sec. -not ":".
    Why not just read these as values?

  2. Your function readCaracter does not return anything to the call. It just reads the file until it hits a ":" and stops. You need to add "return character" at the end (after the while ends) to send it back to the call.

  3. I think your read as written will only have the last character read. "12:03:00" will contain "2" not "12". I think you need caracter = caracter + file.read();
    note: initialize the char character = "";

  4. It might make more sense to read the entire line into a variable at one go and use parse to extract the individual components.

Perhaps some of the experts can give a better answer. But this might get you started.

Thank you for taking your time to reply this thread. The code works fine for my application, I've tested it and I'm able to read any value. I will keep those suggestions in mind, it may be useful for me in future changes. But right now I can't change it. And as stated in my first post, all I need is to print the schedule->get content which is a DateTime variable. Clues ? Thanks again.