time.ticks_ms() while sleeping

Does anyone know how the XBee3 ticks_ms() works whilst the module is put to sleep? Does it stall, or continue during sleep or?

The reason I ask is that I’m observing it jump forward by a significant but apparently random amount of time. In one case it jumped forward by over 7 hours when I put the module to sleep with xbee.sleep_now() and the module woke immediately due to the DTR being asserted (i.e. just a second or so spent sleeping).

xbee.atcmd(‘SM’, 6)
xb = xbee.XBee()
while xb.wake_reason() != xbee.PIN_WAKE:
_ = xb.sleep_now(300000, True) # 5 min
xbee.atcmd(‘SM’, 0)

Cheers, Ross

Which firmware is this? Cellular? DigiMesh? Zigbee? 802.15.4? It might be a bug. The tick_ms value is expected to advance based on the actual sleep duration, even if it’s cut short by pin wake. If not, it’s a bug that should be reported.

Please let me know the firmware version and I’ll try to reproduce it.

Hi Tom,

This is an XBee3-TH running ZigBee 3.0 firmware 100A (hardware 4244).

I believe I’ve figured out what is happening. The call to xbee.sleep_now() is truncating the timeout value to 16 bits. If a larger value than 65535ms is entered, the actual timeout is just the least significant 16 bits, while the overall time jumps forward by the full timeout requested. A similar error occurs in the computation if pin wake occurs.

For example, xb.sleep_now(80536, True) returns 80543 after exactly 15 seconds. The ticks_ms() function returns values consistent with being advanced by 80543ms.

Looks like this is a bug.

I also notice a difference in the behavior of pin wake. In 1006, it was falling edge sensitive while in 100A it is low level sensitive. I’m not sure if this is an intentional change or not. It is not mentioned in the release notes.

Cheers, Ross

1 Like

Thanks for the detailed report. I’ve opened a bug report for this issue. Watch release notes for mention of a fix. Until then, you can work around it by limiting your sleep times and waking up briefly to sleep again.

Thanks Tom for raising the bug report. Ironically I already do use a timeout and loop, I just chose 5min! I’ve reduced that to 1min and all is sweet.
/Ross