Resetting Unix time with RAK12002 RTC Module

Hi everyone. I am working on a RAK11310 with RAK12002 RTC Module. I want to extract time to the precision of milliseconds, but it seems that the Melepero library does not allow precision of milliseconds. I have tried dividing the value of seconds obtained by 1000 but it yields all zeroes at the back of the seconds value.
I have also tried getting Unix time but it seems that their counting of Unix time starts when the RTC module is first powered up. Is it possible to reset the Unix time to zero?

Many thanks in advance.

Did not try it, but what happens when you set the time to 1970 January 1st, 00:00:00.

Tried it, but when I set the year to any earlier than 2000, it sets it to beyond year 2000

I checked the Melepero library and it seems that they only consider years past 2000:


I’m currently trying with the RV-3028_C7-Arduino_Library and it can successfully set the Unix Time. However, I can’t seem to get it to a precision of at least milliseconds as it only returns seconds, any recommendations on how to increase the precision? Multiplying it by 1000 has not helped. The only way I can think of is using the millis() function, still trying to write out that bit

UNIX time is in seconds:

So you will not get milliseconds from there.

Yes I understand that, but I am trying to develop a solution that is precise to milliseconds. I have tried running the below code but possibly due to processing delay it seems to be around 26-30 milliseconds off. (this is the lowest offset I could achieve, if seconds is taken instead of UNIX time it can go up to 100+ milliseconds offset)

#include <RV-3028-C7.h>

RV3028 rtc;

uint32_t previousUnix;
unsigned long zeroMillis;
unsigned long currentMillis;
unsigned long totalMillis;

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println("RTC Example");

  Wire.begin();
  while (rtc.begin() == false) {
    Serial.println("Something went wrong");
    delay(1000);
  }
  Serial.println("RTC online!");

  rtc.setTime(0, 0, 12, 2, 20, 8, 24); //setTime(sec, min, hour, weekday, date, month, year);
  rtc.setUNIX(0);
  previousUnix = rtc.getUNIX(); 
  zeroMillis = millis();
  Serial.print("Initial Unix time is: ");
  Serial.println(previousUnix);
}

void loop() {
  getMilliUnix();
}

void getMilliUnix() {
  rtc.updateTime();
  uint32_t currentUnix = rtc.getUNIX();
  currentMillis = millis();

  if (currentUnix != previousUnix) {
    // A new second has begun
    zeroMillis = currentMillis; // Reset zeroMillis to the start of the new second
    previousUnix = currentUnix;
  }

  totalMillis = currentMillis - zeroMillis;

  Serial.printf("Current Unix Time: %d \n", currentUnix);
  Serial.printf("Milliseconds within the current second: %d \n", totalMillis);
}


The RTC cannot supply you with milliseconds, so your only option is to use millis().