Struggling with Power management with MicroPython sleep feature example

I am using a XBIB-U-DEV, PyCharm version 2020.1.1, Xbee plugin Version 1.0.4 and the Xbee 3G Global module firmware version 11315. Also,I run the same code directly from the XCTU micro python terminal REPL.

I have followed the Power management with MicroPython sleep feature example given below.

from machine import Pin
import time
import xbee

def read_switch(iopin = None):
if iopin.value() == 0:
print(“SW2 has been pressed!”)
return True
return False

Configure DIO0(SW2) to put module to sleep

dio0 = Pin(‘D0’, Pin.IN, Pin.PULL_UP)

x = xbee.XBee()

print("
")
print(“How to use this example:”)

pressing SW2 triggers sleep for 30 seconds

print(“Option 1 press SW2 and let the program run until it wakes from 30 seconds sleep.”)
print("Option 2 press SW2 to put the module under sleep for 30 seconds, "
“then while its sleeping toggle DTR by Close/Open MicroPython Terminal Com port.”)
print(“Option 3 press SW2 then do ^C (cancel) to exit example program while its sleeping”)

print(“Waiting for SW2 to be pressed to Sleep. Please Press SW2”)

while True:
sw2 = read_switch(dio0)
if sw2:
# sleep for 30 seconds, wake early DTR toggled active.
print(“sleeping for 30 seconds”)
sleep_ms = x.sleep_now(30000, True)
print(“slept for %u ms” % sleep_ms)
if x.wake_reason() is xbee.PIN_WAKE:
print(“woke early on DTR toggle”)

  print("woke early on DTR toggle")

When I run this code, everything works apart from one issue.
In option 1, when I press SW2 and let the program run until it wakes from 30 seconds sleep. Every time Xbee 3G Global module wakes up before 30 seconds even I have not toggled DTR. Prints message “slept for 17587 ms”. The amount of milliseconds module sleeping is random.

Does anyone know why the module is waking up early? Is there any guidance on how to following API: class xbee.XBee(*args, **kwargs)?

Where can I find sleep-related micro python in detailed documents?

Any help is appreciated.

Thanks
Omkar

Please contact Digi Support at tech.support@digi.com