RTC RAK3172 configuration

I’m currently trying to use the RTC with the LSE clock in a project where I’m working with the RUI3 API together with Arduino.
My goal is to update and display the time every second.

I ran a test where I attempted to manipulate the RTC through the HAL interface, but the result is that the time does not update or display every second as programmed.

My question is:
Is it possible to access the internal RTC either through the RUI3 API or directly by implementing the HAL interface, without causing conflicts with the internal functions that RUI3 already uses?

Any guidance or previous experience with this would be greatly appreciated.

Welcome to the forum @MiguelA

I am using LoRaWAN timereq to set the RTC of the RAK3172.
Then I get the system time with SysTimeGet() and convert it to a date/time structure:

struct tm localtime;
SysTime_t UnixEpoch = SysTimeGet();
UnixEpoch.Seconds -= 18;			/*removing leap seconds*/
UnixEpoch.Seconds += (int32_t)(g_custom_parameters.timezone * 60 * 60); // Make it GMT+8
SysTimeLocalTime(UnixEpoch.Seconds, &localtime);
MYLOG("APP", "LNS Time %d %d %d %d:%d:%d\n", localtime.tm_year + 1900, localtime.tm_mon + 1,
			  localtime.tm_mday, localtime.tm_hour,
			  localtime.tm_min, localtime.tm_sec);

If you want to use LoRaWAN timereq, you need
(1) (Optional) A callback function to check whether you received the time from the LNS

void timereq_cb_lpw(int32_t status)
{
	MYLOG("TREQ", "Time request status %d", status);
	if (sync_time_status == 0)
	{
		sync_time_status = 1;
	}
}

(2) Request the time from the LNS. You will get the time after your next uplink, so use this before you initiate an uplink:

MYLOG("APP", "Request time");
api.lorawan.timereq.set(1);

(3) above function to retrieve the time

I never set the time manually, but there is a void SysTimeSet(SysTime_t sysTime) function.

1 Like