() procedure start_scan()
()  best_parent_addr = 0XFFFF; best_rssi = 0; scan_timer = ON
()  wake_after(0)                                       wakeup now
()  start_scan_timer(0, SCAN_LENGTH)         scan_timer starts now and will fire after SCAN_LENGTH
() end procedure
() procedure recv_beacon(src, rssi, more)                         more bit in CTRL byte
()  if scan_timer then
()   if (rssi > best_rssi & more) then                     replace current candidate parent
()      best_rssi = rssi
()     best_parent_addr = src
(11)   end if
()   if (my_parent_addr == best_parent_addr) then            restore synchronization with last parent
()    stop_timer()
()    scan_timer = OFF
()   end if
() end if
() if scan_timer then
()   return
() end if
() if (data available) then
()   sleep_after(slot_time)
()   wake_after(beacon_frame)                     wake on next frame to send more data
()   try_send_data()
() else
()   sleep_after(0)
() end if
() end procedure
() procedure scan_handler()                           called when scan timer is fired
() if (best_parent_addr < 0XFFFF) then
()   my_parent_addr = best_parent_addr
()   scan_timer = OFF
() else
()   drop_packet()
()   sleep_after(0)                    sleep now and wake up when new packet is available
() end if
() return
() end procedure
Algorithm 2: Node join algorithm.