I am thinking about adding OpenHab on a RPi to our summer cottage. Not that I need to automate much, but why not?
The place has no internet connection, but I have a TP-Link router (TL-MR3420) with a 3G stick plugged into it. When I stay there sometimes I notice that the stick looses connection and there is not much I can do make it reconnect. TP-Link just have a simple setting keep connection alive or not. I always unplug the router and plug it back again. Of course I can do that with OpenHab by disconnecting the power to the router with a relay on the GPIO. But what is the best way to check the network connection? Is this the HealthCheck binding which keeps checking something like google.com every 5 minutes? Any other methods you recommend?
Using network to ping a site is one way of doing it, but what if google goes down temporarily or for some reason you’re unable to resolve it’s domain? You’ll disconnect the power to your router a little unnecessarily.
Can ping your default gateway using an exec command instead? i.e.
ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` > /dev/null && echo ON || echo OFF
Whoops, sorry completely misunderstood that. My bad…
I think what you’re doing is fine though, since it’s likely that the website would go down. You can try their DNS server ip directly (184.108.40.206) in case your current DNS server faults. That or using a couple of additional locations outside of google will minimise the risk of a false alarm.
Connecting to an IP directly and having multiple sites are both excellent recommendations. You should follow these.
I just want to add that I am monitoring several devices solely by checking 220.127.116.11 and there was not once a false negative.
Just bumped into this old topic. Can I ask a follow on question pls?
OK, so if I poll 5 different sites and they’re all down, my internet connection is gone. I get that.
My question is this - what is the most violent thing I can put in a script for a raspberry pi to correct this situation WITHOUT resorting to a reboot?
I have tried using ifdown/ifup but that didn’t solve it.
I tried sudo service networking restart but that seemed to overwrite my /etc/resolv.conf to the extent that the rpi couldn’t resolve any domain names (it emptied out the previously existing nameserver entry which is what I think happens on a reboot but it wasn’t clear to me what process is supposed to re-create it in a workable form)
So, to reiterate - what can I do short of a reboot that I haven’t already tried?