How many ms for os_queryTimeCriticalJobs

Hi,
I have a question about the LMIC MCCI library.
Before i send the atmega4809 to sleep i call os_queryTimeCriticalJobs(ms2osticks(1000)) but i don’t know how many ms it needs.
A value of 1000 works but i don’t really understand whats going on under the hood

if(!os_queryTimeCriticalJobs(ms2osticks(1000))){
			Serial.println("Can go to sleep");
bit_t os_queryTimeCriticalJobs(ostime_t time) {
    if (OS.scheduledjobs &&
        OS.scheduledjobs->deadline - os_getTime() < time)
        return 1;
    else
        return 0;
}

Maybe somebody can give me a hint?

As the comment in the code says:

// return true if there are any jobs scheduled within time ticks from now.
// return false if any jobs scheduled are at least time ticks in the future.

The number you should provide is how long you plan to sleep for.

2 Likes

As above, but bear in mind you may be mid-transmission, so you need to be checking for the Rx2 interval.

Or just sleep after the EV_TXCOMPLETE event.

1 Like

Hi, Thank you for answering

Sorry i forgot to say that i stop the main clock.

That means, when the ticks are counting only 9 seconds(Sensor readings, TX RX1 RX2)then the Main Clock and CPU is stopped for 30 minutes, i enter anyway the whole 30 minutes time
I did it that way and for the last couple of hours it works

17:51:09.920 -> os time in seconds: 713
17:51:09.920 -> Waking up and schedule sensor readings
17:51:12.044 -> 44748952: EV_TXSTART
17:51:12.091 -> Packet queued
17:51:18.138 -> 45129099: EV_TXCOMPLETE (includes waiting for RXwindows)
17:56:38.998 -> os time in seconds: 722
17:56:39.045 -> Waking up and schedule sensor readings
17:56:41.166 -> 45266989: EV_TXSTART
17:56:41.166 -> Packet queued
17:56:47.253 -> 45647259: EV_TXCOMPLETE (includes waiting for RXwindows)

Thank you
I set a Flag in the EV_TXCOMPLETE and have a if query in the loop

void loop() {
	os_runloop_once();
	if(canGoToSleep == 1){
		//Serial.println("packet sent, check if current RX/TX job running");
		if(!os_queryTimeCriticalJobs(ms2osticks(sleepMinutes*65536))){

maybe it is better to put the sleep section in the EV_TXCOMPLETE so i dont have to poll

Ugh, no, best to keep that as clean as possible.

And you may end up with other state flags which are best processed in the main loop.

Thank you,
it is good to know that i am following the right approach
Happy new Year