I have a Python Script which automatically checks the internet connection and is supposed to restart the wifi connection, if the internet fails.
This is the function that does this:
def RestartWifi():
print 'Restarting Wifi.'
os.system('sudo ifdown --force wlan0')
time.sleep(6)
os.system('sudo ifup wlan0')
I have added the sleep command to make sure, that there is enough time to disable, before re-enabling the connection.
However, is there a way to speed this up and somehow enable the wifi as soon as it is disabled? Also, what would happen if the first command takes longer than 6 seconds? Is there a way to wait for the command to 'return' like a function when it has finished?
Big thanks for your help!