I will start off by saying, I am not really very knowledgeable about Linux nor PiAware.
I put my first feeder on in August, 2019, and have done a number of things to the improve it’s performance. Then as some of the things I tried had a negative impact, I decided to put up a test feeder I could make changes to with out affecting my main feeder.
I put my test feeder in my boathouse which does not have Ethernet connectivity. Seeing as the PiAware image supports WiFi I thought this would work very well. Set it up, and it worked great! Then it suddenly was not seen on the network. Rebooted the Raspberry Pi 3 B+, and everything worked great again, for a while. Thinking the Pi might be overheating, I got a case with a fan. The Pi would still disappear off the network periodically and randomly. I decided the Pi must be loosing connectivity through the WiFi. So I got to thinking and cribbed together the following script which is run as root by Cron. The corntab entry is
* * * * /home/pi/check-network.sh
So the script checks the network connection every minute. And if the Pi cannot ping the default gateway, it restarts the Pi’s Networking. And records the Network restart. If after a minute the default gateway is still not pingable, the script reboots the Pi.
My scripting skills are poor, but it seems to work for me. I have not had any outages of several hours since I got the script working the way I want several days ago.
The script listing is below.
#!/bin/sh ping -c2 192.168.1.1 > /dev/null if [ $? -eq 0 ]; then echo .>/dev/null if [ -e /tmp/NetworkRestartedOnce ] then rm /tmp/NetworkRestartedOnce fi else if [ -e /tmp/NetworkRestartedOnce ] then cp /tmp/NetworkRestartTimes /home/pi/NetworkRestarTimes$(date +"%Y-%m-%d") sudo reboot fi cur_time=$(date +"%Y-%m-%d %H:%M %Z") if [ ! -e /tmp/NetworkRestartTimes ] then touch /tmp/NetworkRestartTimes fi echo Network Restarted: $cur_time >> /tmp/NetworkRestartTimes sudo service networking restart touch /tmp/NetworkRestartedOnce fi