Create a file, and make it executable “chmod a+x”.  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] 
     echo "not good"$d >> /root/test.txt 
     connmanctl disconnect wifi_long.number_managed_psk 
     connmanctl connect wifi_long.number_managed_psk 
     echo "good"$d >> /root/test.txt 

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 (or 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/

Save and exit.  Cron will call 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.