Hi am in need to taking timestamps when an event on my device (RAK3172 module integrated on a custom application PCB), is generated. I have read an understood the documentation on using api.lorawan.timereq.set()/get(). What is not clear to me is how do I access the confirmed timereq() during the Callback function call? Is my assumption that the Callback furnishes timestamp data correct at all? Thank you
Welcome to the forum @chrissoyza
You do not need to access anything.
You request the time from the LoRaWAN server with api.lorawan.timereq.set(1);
The callback just tells you whether the time request was successful. You can set a flag here, e.g. sync_time_status
void timeReqCallback(int32_t status)
{
// MYLOG("TREQ", "Time request status %d", status);
if (sync_time_status == 0)
{
sync_time_status = 1;
}
}
And then, where you need the time, you can get the system time and convert it to day/month/year/our/minute/seconds. Example code below assumes that the device is GMT+8, so you need to adjust it.
char local_time[30] = {0};
struct tm localtime;
SysTime_t UnixEpoch = SysTimeGet();
UnixEpoch.Seconds -= 18; /*removing leap seconds*/
UnixEpoch.Seconds += 8 * 60 * 60; // Make it GMT+8
SysTimeLocalTime(UnixEpoch.Seconds, &localtime);
sprintf(local_time, "%02dh%02dm%02ds on %02d/%02d/%04d", localtime.tm_hour, localtime.tm_min, localtime.tm_sec,
localtime.tm_mon + 1, localtime.tm_mday, localtime.tm_year + 1900);
Serial.printf("MCU %s\n", local_time);
Hi BeeGee,
Thank you very much for clarifying this as well as to responding immediately. Kudos to you and the RAK Wireless team with 2 thumbs up for the rapid response!
I had spent much time trying to figure this on top of throwing similar queries to the ‘usual well known’ AI agents without much success.
sincerely
chrissoyza