I have a Raspberry Pi Zero W-based device that records data from sensors. The device is mobile so it gets out of access point's range several times per day.
When the device returns to the access point's range, it reconnects, and starts uploading the data to a server.
The problem is that the Raspberry Pi takes too long to reconnect to the access point; about two to five minutes.
We know the device is in range because we are in the same room of the AP, about 3 meters away. I wrote a script that pings the server every 5 seconds and if no response is received, the script shutdown the interface and then restart it with ifdown and ifup. The scripts works and now the time of reconnection is about less than 30 seconds, but now sometimes the pi doesn't reconnect until a reboot. I don't know if this way can damage the interface.
How can reduce the time to reconnect to the access point?
Thanks in advance.