Hello brother I did this to my sketch it might help u with what u are asking
So when I loose the connection it will start to connect to internet for 8 seconds if the connection made then it will connect if not the project will work for 30 seconds and then For 8 seconds it will keep trying to connect again etc…