LoraWAN TimeReq on CubeCell

Hello,
I need to retrieve the time from the LoRaWAN gateway by sending the TimeReq message (as per LoRaWan specs, no payload msg).

is there a way to send such a message at MAC level to get the time from the gateway?

I’m using AB01 and AB02

thanks

Sorry, the lora gateway does not have this function.

You can try to get what you want in mqtt

mmm … my question is for the AB02 CubeCell software.

it is at MAC layer and I see it supported int he core library, but I do not see how to use it from the LoRaWan library level.

btw: my gateway does support this feature, it is a ChirpStackOS on raspberry.

thanks

hi,

we have updated the code: https://github.com/HelTecAutomation/ASR650x-Arduino/blob/master/libraries/LoRa/examples/LoRaWAN/LoRaWan_TimeReq/LoRaWan_TimeReq.ino

please git pull.

wow! thanks a lot Jason, I’ll test this week and report back.

hey Jason, looking at the code I can see how we do a TimeReq but it is not clear to me where we update the local clock. Who is going to process the TimeAns reply from the gateway??

also in your example how do we know if the request was successful?

again … tanks a lot for your help

LoRaMac.c
static void ProcessMacCommands** ( uint8_t *payload, uint8_t macIndex, uint8_t commandsSize, uint8_t snr, LoRaMacRxSlot_t rxSlot )

           case SRV_MAC_DEVICE_TIME_ANS:
                {
                    TimerTime_t currentTime = 0;
                    TimerSysTime_t sysTimeAns = { 0 };
                    TimerSysTime_t sysTime = { 0 };
                    TimerSysTime_t sysTimeCurrent = { 0 };

                    sysTimeAns.Seconds = ( uint32_t )payload[macIndex++];
                    sysTimeAns.Seconds |= ( uint32_t )payload[macIndex++] << 8;
                    sysTimeAns.Seconds |= ( uint32_t )payload[macIndex++] << 16;
                    sysTimeAns.Seconds |= ( uint32_t )payload[macIndex++] << 24;
                    sysTimeAns.SubSeconds = payload[macIndex++];

                    // Convert the fractional second received in ms
                    // round( pow( 0.5, 8.0 ) * 1000 ) = 3.90625
                    sysTimeAns.SubSeconds = sysTimeAns.SubSeconds * 3.90625;

                    // Add Unix to Gps epcoh offset. The system time is based on Unix time.
                    sysTimeAns.Seconds += UNIX_GPS_EPOCH_OFFSET;

                    // Compensate time difference between Tx Done time and now
                    sysTimeCurrent = TimerGetSysTime( );

                    sysTime = TimerAddSysTime( sysTimeCurrent, TimerSubSysTime( sysTimeAns, LastTxSysTime ) );
#ifdef LORAMAC_CLASSB_TESTCASE
                    DBG_PRINTF("receive SRV_MAC_DEVICE_TIME_ANS, set time=%u.%d\r\n", (unsigned int)sysTime.Seconds, sysTime.SubSeconds);
#endif
                    // Apply the new system time.
                    TimerSetSysTime( sysTime );
                    currentTime = TimerGetCurrentTime( );
                    
                    LoRaMacClassBDeviceTimeAns( currentTime );
#ifdef CONFIG_LWAN                    
                    McpsIndication.DevTimeAnsReceived = true;
#endif    
                }
                break;

hi,

we have updated the code again. please git pull.

we add a function.When the time is updated, this function will be called(You can add what you want in this function). please refer the picture.

thanks a lot for your help. I can confirm that TimeReq works now using CubeCell AB02 and using a gateway (raspberry + i880a) with ChirpStackOS