Im trying to creat a .txt file inside the sd card with current hour as the name of the file,
but it just dont work. the esp32 gets the current hour from a gnss receiver.
here is the part of the code a get the hour from:
void GetTime(){
if (millis() - lastTime > 1000)
{
lastTime = millis(); //Update the timer
long latitude = myGNSS.getLatitude();
Serial.print(F("Lat: "));
Serial.print(latitude);
long longitude = myGNSS.getLongitude();
Serial.print(F(" Long: "));
Serial.print(longitude);
Serial.print(F(" (degrees * 10^-7)"));
long altitude = myGNSS.getAltitude();
Serial.print(F(" Alt: "));
Serial.print(altitude);
Serial.print(F(" (mm)"));
byte SIV = myGNSS.getSIV();
Serial.print(F(" SIV: "));
Serial.print(SIV);
Serial.println();
Serial.print(myGNSS.getYear());
Serial.print("-");
Serial.print(myGNSS.getMonth());
Serial.print("-");
Serial.print(myGNSS.getDay());
Serial.print(" ");
Serial.print(myGNSS.getHour());
Serial.print(":");
Serial.print(myGNSS.getMinute());
Serial.print(":");
Serial.print(myGNSS.getSecond());
Serial.print(" Time is ");
if (myGNSS.getTimeValid() == false)
{
Serial.print("not ");
}
Serial.print("valid Date is ");
if (myGNSS.getDateValid() == false)
{
Serial.print("not ");
}
Serial.print("valid");
Serial.println();
sprintf(Date, "%04d-%02d-%02d", myGNSS.getYear(), myGNSS.getMonth(), myGNSS.getDay());
sprintf(hour, "%02d:%02d:%02d", myGNSS.getHour(), myGNSS.getMinute(), myGNSS.getSecond());
sprintf(FileName, "%s/%s.ubx", Date, hour);
Serial.print(FileName);
}
}
here is where I creat the directory:
void createDirectory() {
Serial.println("");
Serial.println("Creating directory test");
// if the folder already exists, don't bother creating it
if (!sd.exists(Date)) {
// attempt to access the root directory information
if (myDir.open("/")) {
// Create a new folder called 'testFolder'
// mkdir will return true if it completes successfully
if (sd.mkdir(Date)) {
Serial.println(F("Created 'testFolder' successfully"));
} else {
Serial.println("Create 'testFolder' failed");
}
} else {
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
delay(300);
digitalWrite(buzzer, HIGH);
delay(300);
digitalWrite(buzzer, LOW);
Serial.println("Open 'testFolder' failed");
}
} else {
Serial.println("Folder 'testFolder' already exists!");
}
}
and here is where the .txt file should be created:
GetTime();
createDirectory();
myFile = sd.open(FileName, FILE_WRITE);
Serial.println("PPP Base enabled!");
Serial.println("Iniciating...");
delay(2000);