Create a file, wifi_reconnect.sh and make it executable “chmod a+x wifi_reconnect.sh”.  This file should contain the following code:

d=$(date +%H%M%S)
if [ $(connmanctl state | grep -c "online") = 0 ] && 
[$(connmanctl state | grep -c "ready") = 0] 
then 
     echo "not good"$d >> /root/test.txt 
     connmanctl disconnect wifi_long.number_managed_psk 
     connmanctl connect wifi_long.number_managed_psk 
else 
     echo "good"$d >> /root/test.txt 
fi

At this point, the state “online” might be too strict and a state of “ready” might be acceptable. The state “online” indicates connectivity as determined by actual connection to ipv4.connman.net (or ipv6.connman.net if that’s how you’re rolling).

Get this code to execute every five minutes using cron.  Enter the editing mode by typing “crontab -e”.  When prompted (first time only) pick your editor (e.g. emacs).

Enter the following line:

*/5 * * * * sh /root/wifi_reconnect.sh

Save and exit.  Cron will call wifi_reconnect.sh every 5 minutes.  If connmanctl shows that wifi is down, it will automatically disconnect and then reconnect.  It will put an entry into test.txt regardless.  These lines aren’t necessary, so they can be commented out.

This step is an amazingly important step.  Even though the beaglebone’s wireless connectivity is much better than it was when I started, you will always lose connections.  This basic step allows the system to recover.