Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong TimeStamps #12

Open
Praneethsvch opened this issue Nov 18, 2020 · 1 comment
Open

Wrong TimeStamps #12

Praneethsvch opened this issue Nov 18, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Praneethsvch
Copy link
Collaborator

When used this block of code which was used to develop the library, wrong timestamps are observed:

void setup_featherWing(void) {

  //RTC init
//  if (! rtc.begin()) {
//    Serial.println("Couldn't find RTC");
//    Serial.flush();
//    abort();
//  }

  if (! rtc.initialized() || rtc.lostPower()) {
    Serial.println("RTC is NOT initialized, let's set the time!");
    // When time needs to be set on a new device, or after a power loss, the
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
    //
    // Note: allow 2 seconds after inserting battery or applying external power
    // without battery before calling adjust(). This gives the PCF8523's
    // crystal oscillator time to stabilize. If you call adjust() very quickly
    // after the RTC is powered, lostPower() may still return true.
  }

  // When time needs to be re-set on a previously configured device, the
  // following line sets the RTC to the date & time this sketch was compiled
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  // This line sets the RTC with an explicit date & time, for example to set
  // January 21, 2014 at 3am you would call:
  // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));

}

String get_timestamp(void){
  DateTime now = rtc.now();
  String custom_timestamp_calibrated = String(now.year(), DEC) + String('-') + String(now.month(), DEC)+ String('-') + String(now.day(), DEC)+ String(' ') + String(now.hour(), DEC)+ String(':') + String(now.minute(), DEC) + String(':') + String(now.second(), DEC);
  return custom_timestamp_calibrated;
}

void writeToSDCard(String StringtobeWritten) {
  //add time stamp to every sd card write
  String timestamp = get_timestamp();
  StringtobeWritten = timestamp + String(',') +StringtobeWritten ;
  char buffchar[StringtobeWritten.length() + 1];
  StringtobeWritten.toCharArray(buffchar, StringtobeWritten.length() + 1);
  digitalWrite(8, HIGH);
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
    // set the SD_ERROR flag high;
    SD_ERROR = 1;
    Serial.println("SD Initialization Failed.");
  }
  else
  {
    ofstream sdout(name, ios::out | ios::app);
    if (!sdout)
    {
      Serial.println("SD Card Open Failed.");
      SD_ERROR = 1;
    }
    else {
      sdout << buffchar << endl;
      // close the stream
      sdout.close();
      SD_ERROR = 0;
    }
  }
  digitalWrite(8, LOW);
}

Screen Shot 2020-11-18 at 4 08 51 PM

@Praneethsvch Praneethsvch added bug Something isn't working enhancement New feature or request labels Nov 18, 2020
@Praneethsvch Praneethsvch self-assigned this Nov 18, 2020
@Praneethsvch Praneethsvch removed the enhancement New feature or request label Nov 25, 2020
@Praneethsvch
Copy link
Collaborator Author

same issue found here but unresolved: https://forums.adafruit.com/viewtopic.php?f=31&t=134309&p=666320#p666320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant