I would like to write a script in which it keeps on trying to connect to a network, even if it is not available so as soon at it becomes available it will connect to it. This is what I have now
def connect_to_yeelight(ssid, iface):
sys.setrecursionlimit(2000)
iface_channel = f"sudo iwconfig {iface} channel 6"
os.system(iface_channel)
connect_yeelight_cmd = f"nmcli d wifi connect {ssid} ifname {iface} > /dev/null 2>&1"
def try_connection():
if os.system(connect_yeelight_cmd) != 0:
try_connection()
time.sleep(1)
else:
return True
try_connection()
as you can probably tell with this code I get a "RecursionError: maximum recursion depth exceeded in comparison". Is there any other way I could achieve such script, I feel like Im looking at this from a wrong angle.