Forum Archive

Reconnecting to WiFi

Snaresman

Hello

I’m using an iPad as a data logger. The Pythonista program works great. My internet not so much. I loose connection several times a day on everything connected to it.

My question is: how I get python to check if it’s connected and if not, reconnect? I’ve looked at a lot of posts across the Internet and nothing addresses this.

mcriley821

You can use objc_util to check your connection type.

from objc_util import * 


NWPathEvaluator = ObjCClass('NWPathEvaluator')
connection = NWPathEvaluator.sharedDefaultEvaluator()


def isOnWifi():
    info=connection.path()
    if info.isExpensive():
        #on cellular data
        return False #Not on wifi
    elif info.status() == 2:
        #no connection
        return False #Not on wifi
    elif info.status() == 1:
        #on wifi
        return True #Wifi!
    else:
        return None #Unknown or Error 

Will continue to see if there’s a way to retry a connection....