Restart network on connection loss


 

JakeBrown

TVWBB Member
Upon losing wireless network connectivity, is there a feature or custom script that can automatically restart the network?

I keep losing the wireless connection using a USB wireless adapter (Edimax). It happens every few hours. I pull the plug and reboot to reconnect.

I'd also like to find a wireless adapter that is more reliable.

Thanks,
Jake
 
Save the script below as /mnt/mmcblk0p4/net-watchdog.sh and make sure it's executable

Add a cron job to call the script every 10 minutes.

Code:
*/10 * * * *  /mnt/mmcblk0p4/net-watchdog.sh

What it does: Pings the gateway ( your wireless router ) and checks for the message "1 packets received". If that's not found, it will first attempt to restart the networking stack on the RasPi. It will then wait 2 minutes for things to stabilize and check again. If it still doesn't get a response, it will reboot the RasPi and that should get things sorted out.

Code:
#!/bin/sh

checkgw () {
ping_gw=$(netstat -nr | grep "UG" | awk '{print $2}' | xargs ping -q -w 1 -c 1 | grep "1 packets received")
result=$?
}

checkgw
if  [ "$result" -ge 1 ]
then
logger -p user.alert "Restarting network"
/etc/init.d/network reload
sleep 120
checkgw
    if [ "$result" -ge 1 ]
    then
    logger -p user.alert "Rebooting"
    /sbin/reboot
    fi
fi
 
This script is going to be a serious sleep savor!
But I noticed that if I use this script, I may not know how bad my network connection is. The script is doing something with "logger".

Where are the logs stored?
Where do I go to view the log?
 
logger just writes to syslog, which admittedly doesn't help a whole lot on OpenWrt as it's cleared on reboot.

Let's try this. This will log to /mnt/mmcblk0p4/net-watchdog.log and you can inspect it anytime.

The entry will look like:

"YYYY-MM-DD HH:MM:SS : Message"


Code:
#!/bin/sh

LOG=/mnt/mmcblk0p4/net-watchdog.log

checkgw () {
ping_gw=$(netstat -nr | grep "UG" | awk '{print $2}' | xargs ping -q -w 1 -c 1 | grep "1 packets received")
result=$?
}

checkgw
if  [ "$result" -ge 1 ]
then
echo "$(date "+%Y-%m-%d %H:%M:%S") : Restarting network" >> $LOG
/etc/init.d/network reload
sleep 120
checkgw
    if [ "$result" -ge 1 ]
    then
    echo "$(date "+%Y-%m-%d %H:%M:%S") : Rebooting" >> $LOG
    /sbin/reboot
    fi
fi
 
Last edited:
Do you see a lot a serial communication errors down in the "HeaterMeter Info" section of the config page? (below the setpoint) The reason I asked is sometimes comm errors can make the rPi act a bit funny and do things like drop the network connection. I would also reseat your SD card on the rPi.
The Edimax wifi adapter works pretty well in general, unless you got a lemon. How is the signal level when it is connected? I used the Edimax for a long time with no problems, and am currently using the Comfast CF-WU715N wifi adapter. I have never had the connection drop even when powered for weeks on end without reboot.
 
Wonder if it has to do with the router rather than the HM? 'cause my HM stays on 24/7 and never drops connection.
 
Do you see a lot a serial communication errors down in the "HeaterMeter Info" section of the config page? (below the setpoint) The reason I asked is sometimes comm errors can make the rPi act a bit funny and do things like drop the network connection.

Right now I'm seeing this:
Version 20141003B
Serial checksum errors: 2

...and it doesn't look like I've had a reboot for a while.

- - - Updated - - -

Wonder if it has to do with the router rather than the HM? 'cause my HM stays on 24/7 and never drops connection.

My other WiFi connections are operating without problems.
 
I think I found the potential problem...
The Edimax EW-7811Un has an operating temperature range between 32~104°F (0~40°C).
It was 25°F last night. Had to reboot between every 1 to 2 hours.
Now that the temperature has been above freezing, no network problems (at least I'm not seeing a log of a reported problem).
 
Seems like that could be a problem, it literally froze as apposed to the typical computer freeze... LOL

You could go the CAT5 route with the probes and bring your HM inside or to a warmer place, or somehow use some warmth from the grill to keep it above freezing... or maybe put the HM in one of those silver hot/cold bags and put the LCD on full brightness and hope that keeps things warm enough to function.
 
haha Yeah I will admit that here in South Florida, I have never tested the HeaterMeter wifi outdoors in sub-freezing temperatures. I've put it in my fridge though, which is 38F and it works ok. You could maybe put the whole heatermeter in some sort of insulated box (where the heat generated by the unit might be enough to keep it above freezing) or use Ralph's method of running a long cable outside to the probes/blower and keeping the heatermeter inside.
 
I've seen someone put a router in a hard plastic cooler with a thermostats + light bulb that warmed up the box and kept the electronics from freezing.
 

 

Back
Top