Internet Connection Check and Reboot.

17 views
Skip to first unread message

Mike Backus

unread,
Apr 6, 2026, 6:00:08 PM (22 hours ago) Apr 6
to DigiPi
Here is my problem and my solution.

I am running several Digipi's for a couple purposes, but one of them is a dedicated fill in APRS Digipeater for our area. It fills a 15 mile hole in coverage in the county. It is also a igate for the coverage area. 

However, where I live, power is fairly reliable, but the connection to my ISP is frequently down. I found that when the ISP connection went down, the Digipi, as intended, switched from a wi-fi connection to my router, to a wi-fi hotspot, again, as intended. When the connection to the internet returned, the Digipi did not reconnect. Again, this is exactly how the Digipi is setup and for most use cases makes sense. 

As this system is relatively unmonitored, this led to two week long timeframes that the digipeater was functioning fine, but none of the packets were getting forwarded to the internet services and non of the packets from the internet services were getting rebroadcasted by my digipeater. 

After a bit of reading, here is the solution that I found. I created the following script file which is outside of the Digipi system. It creates a cron job in the Raspberry Pi OS that looks for a internet connection at the top of every hour. If there is no connection, it reboots the Pi. If there is a connection, it does nothing. It tries to create a log file entry for each check. I think that the fact that the digipi runs with the file system unmounted, that log file is not actually created, but I am too lazy to take it back out of the cron job. 
 
Also because I am lazy and have already tired of typing, I have attached a word document. It is an AI summary of the script and the instructions for the install. 

There are of course operational issues with having this reboot every hour without an internet connection. Do not use this for anything that you would take portable or do not have an internet connection to or it will reboot every hour whether you want it to or not. There may be smoother or more efficient ways to do this. 

Your mileage may vary. I am not a great programmer and had help from AI in getting the errors out of my original script. I have been running this for a couple months now and it has not melted my Pi 2 Zero W nor have I had to manually reboot the pi after an internet outage. It could be useful for any unmonitored Pi that needs to reboot if it loses connection to the outside world or (with a bit of modification) to another device of your network. 

Here is the Script in Txt Format. 

#!/bin/bash
# hourlyinternetcheck.sh - Checks for internet connection every hour and reboots if none is found

CRON_FILE="/etc/cron.d/hourlyinternetcheck"
CHECK_SCRIPT="/usr/local/sbin/hourlyinternetcheck.sh"

# Must run as root
if [[ $EUID -ne 0 ]]; then
  echo "Error: This script must be run as root (use sudo)."
  exit 1
fi

# Write the internet-check script
cat > "$CHECK_SCRIPT" << 'CHECKER'
#!/bin/bash
# Reboots the device only if there is no internet connection

LOG_FILE="/var/log/hourlyinternetcheck.log"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')

check_internet() {
  # Try pinging two reliable hosts in case one is temporarily unreachable
  ping -c 2 -W 5 8.8.8.8 > /dev/null 2>&1 && return 0
  ping -c 2 -W 5 1.1.1.1 > /dev/null 2>&1 && return 0
  return 1
}

if check_internet; then
  echo "[$TIMESTAMP] Internet is up. Reboot skipped." >> "$LOG_FILE"
else
  echo "[$TIMESTAMP] No internet detected. Rebooting now..." >> "$LOG_FILE"
  /sbin/reboot
fi
CHECKER

chmod 755 "$CHECK_SCRIPT"

# Write the cron job to call the check script every hour
echo "0 * * * * root $CHECK_SCRIPT" > "$CRON_FILE"
chmod 644 "$CRON_FILE"

echo "Hourly internet check configured."
echo "Device will reboot if no internet connection is detected."
echo ""
echo "Files created:"
echo "  Cron job:     $CRON_FILE"
echo "  Check script: $CHECK_SCRIPT"
echo "  Log file:     /var/log/hourlyinternetcheck.log (created on first run)"
echo ""
echo "To change the frequency, edit $CRON_FILE"
echo "To remove the scheduled check, run:"
echo "  sudo rm $CRON_FILE $CHECK_SCRIPT"



hourlyinternetcheck_summary.docx

Craig

unread,
Apr 6, 2026, 7:06:58 PM (21 hours ago) Apr 6
to Mike Backus, DigiPi
Yah, that's a real good problem characterization.  DigiPi was not designed to fallback to hotspot
mode if wifi became unavailable.  It's only supposed to be a hotspot if and only if wifi isn't
available when it first boots.

According to NetworkManager, setting

autoconnect-retries=0

in /etc/NetworkManager/system-connections/wlan0.nmconnection

will tell it to retry downed wifi forever.  

NetworkManager completely ignores this obviously and just randomly ups the hotstpot.nmconnection
file if wifi fails after a while, instead.

I was going to further embrace the horror of NetworkManager and add

autoconnect=false

to hotspot.nmconnection and see if it works that way.

In your case, for now, you could simply delete /etc/NetworkManager/system-connections/hotspot.nmconnection


cool,
-craig
KM6LYW
--
You received this message because you are subscribed to the Google Groups "DigiPi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to digipi+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/digipi/0e7fb8a9-e72b-4e12-a860-072489dc91e5n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages