Sleeping devices can 'freeze' after wkeup randomly

Hi everyone !

I’m working with 3 XBee3 eval board and X2E gateway.

  • X2E as coordinator
  • 1 xbee3 as router
  • 2 xbee3 as end node sleeping devices

The 3 XBees running with micropython, and sleeping duration is 1 minutes for now just for testing, but it will be about around a day.

My problem is that sometime XBee end devices can freeze just after wakeup. ON/SLEEP led is ON and ASSOC can be ON or OFF locked.
At this point, on REPL terminal, i can’t interrupt the code with CTRL-C, but i can read XBee value with XCTU and i have :

  • AI = FF
  • OP = 0
  • OI = FFFF
  • CH = 0
  • NC = 0

I understand that XBEE is not associated, and stay in this state indefinitely.
The only way is to perform a physicaly hardware reset and xbee run properly.

That i do i my code, globally in main WHILE :

  • XBEE wake up from sleeping period.
  • Wait for assotiation within 60 seconds then perform a soft reboot
    # Wait for association
    for x in range(60):
        if xbee.atcmd("AI") is 0:
            break
        else:
            time.sleep(1)
        if x is 60-1:
            machine.soft_reset()
  • If associated, pool to check any massage stored in parent router.
  • Get data sensors
  • Send data to server and wait if receive a new data from server
    try:
        xbee.transmit(xbee.ADDR_COORDINATOR, packet_dict)
    except OSError:
        print('No xbee connection')
    else:
        rdata = receive_data()
        if rdata is not None:
            use_data_in(rdata)
  • Then enter in sleeping time :
    if bkp_mod == 'awk':
        time.sleep_ms(off_dly)
    elif bkp_mod == 'slp':
        print('Delay = ', off_dly, 'ms')
        xbee.XBee().sleep_now(off_dly, False)

When program start during initialisation, i set ET parameter to a value greater than sleeping time.

When issue comes, i don’t know if micropython code is running or not.

What is a problem ? What i’m missing ?
If not, how can i capture this problem state and perform for exemple a machine.reset() or maybe using the watchdog ?

Thank you for help in advance,

How are you using the sleep function for the modules?

Thanks,

I can change remotely if the module is in end device and sleeping mode or router.

I read settings from a flash conf file in XBee3 and apply like this :

off_dly = min_to_ms(int(bkp_frq))
 if bkp_mod is 'awk' and xbee.atcmd('SM') is not 0:
     xbee.atcmd('SM', 0)
 if bkp_mod is 'slp' and xbee.atcmd('SM') is not 6:
     xbee.atcmd('SM', 6)

Then when i’m in the main loop, i do that :

    if bkp_mod == 'awk':
        time.sleep_ms(off_dly)                   # Wait for 'off_delay'
    elif bkp_mod == 'slp':
        print('Delay = ', off_dly, 'ms')
        xbee.XBee().sleep_now(off_dly, False)    # Sleep for 'off_delay'

I don’t touch directly parameters like SP, SN, SO, because i think the fonction sleep_now() set theses settings correctly ?

I would suggest looking at the Set Sleep example in PyCharm as it explains how to set sleep and how to use it properly,