Hi,
how often is an appropriate time to send a heartbeat packet?
It depends on your application. You could send an active request to the device that you want to check, Router case.
If you have sleep end devices, you could set a keep-alive time.
Can it be realized that the device can re-enter the network with the cooperation of the gateway and the device itself?
I am not sure if I am following the question, but if the device doesn't send the leave command, it will keep the key for that specific network.
Regards,
Mario