Gerofi
Posts: 4
Joined: Tue Sep 11, 2018 2:16 pm

Reconnect ethernet raspberry

Tue Sep 18, 2018 8:33 pm

My english is bad, I need that when my raspberry does not find internet, do not leave the code, any ideas?

I tried this code to check if there is internet connection

Code: Select all

import urllib2

def internet_on():
    try:
        urllib2.urlopen('http://www.google.com', timeout=1)
        return True
    except urllib2.URLError as err: 
        return False
But I do not know how to make it to try again to connect

bertlea
Posts: 189
Joined: Wed Dec 07, 2016 6:33 am
Location: Hong Kong

Re: Reconnect ethernet raspberry

Wed Sep 19, 2018 1:41 am

If you mean you want to test the connection every minute, then just write a loop to call your function to report the return value (or do something according to the return value). You should also call the

Code: Select all

time.sleep(60)
function in your loop to only test it once a minute, to prevent it keep trying too frequently.

LeslieSantos
Posts: 1
Joined: Wed Sep 26, 2018 5:18 am

Re: Reconnect ethernet raspberry

Wed Sep 26, 2018 5:28 am

There must be some error in the program. I also think to use the loop function.

Return to “General discussion”