Use touch /home/pi/wifi-reconnect.sh to create shell script file,
with following content:
#!/bin/bash
SSID=$(/sbin/iwgetid --raw)
if [ -z "$SSID" ]
then
echo "`date -Is` WiFi interface is down, trying to reconnect" >> /home/pi/wifi-log.txt
systemctl restart wireless
fi
echo "WiFi check finished"
chmod +x /home/pi/wifi-reconnect.sh
sudo apt-get install cron
Use sudo vim /etc/crontab to edit crontab
By putting following content at end of file:
* * * * * root /home/pi/wifi-reconnect.sh
Test it by disconnecting from WiFi:
sudo ifconfig wlan0 down
Script should reestablish connection within 1 minute.
After the RPi reestablish connection, reconnect RPi and check log file:
/rcat /home/pi/wifi-log.txt
