I have to agree with @AndyW there should not be any reason for your counter to stop counting and even less to reset just because the WiFi conks out.
Unless there is something going on that causes a reset to the system - e.g. hard fault, TCP issue, …
I’d drop the code you got there, especially since you don’t quite know why you have it in the first place and start anew.
So I’ll try to whip up some easy to understand test code that will survive a longer lasting WiFi drop out with as little “special features” as possible on a Photon with 0.4.6.