2

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.

  • it is unknown how quickly the RPi approaches the AP .... perhaps the reason for the slow reconnection is because tha RPi spends much time in the signal fringe area ..... try using a WiFi repeater to extend the WiFi coverage – jsotola Apr 6 at 1:39
  • How have you determined the length of time between the pi being "in range" to "connected"? Is your SSID hidden? – Jaromanda X Apr 6 at 1:49
  • Hi. We know the device is in range because we are in the same room of the AP, about 3 meters away. I writed a script that pings the server every 5 seconds the server 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 doesnt reconnect until a reboot. I don't know if this way can damage the interface. – JesusCN Apr 6 at 6:11
1

wpa_supplicant has an option autoscan= that is responsible for scanning the network if disconnected or on inactive state. Just look at

rpi ~$ zcat /usr/share/doc/wpa_supplicant/examples/wpa_supplicant.conf.gz | less

You will find:

# Automatic scan
# This is an optional set of parameters for automatic scanning
# within an interface in following format:
#autoscan=<autoscan module name>:<module parameters>
# autoscan is like bgscan but on disconnected or inactive state.
# For instance, on exponential module parameters would be <base>:<limit>
#autoscan=exponential:3:300
# Which means a delay between scans on a base exponential of 3,
# up to the limit of 300 seconds (3, 9, 27 ... 300)
# For periodic module, parameters would be <fixed interval>
#autoscan=periodic:30
# So a delay of 30 seconds will be applied between each scan.
# Note: If sched_scan_plans are configured and supported by the driver,
# autoscan is ignored.

You can add it in /etc/wpa_supplicant/wpa_supplicant.conf also outside a network block to be valid for all networks, for example:

autoscan=periodic:10
network={
...
}

This will scan for networks every 10 seconds if disconnected.

  • Hi, thanks for your answer. We tried that with 5 seconds, but sometimes takes longer about 1minute. – JesusCN Apr 23 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.