Your problem is you are not actually updating the variables you want to update.
More specifically, you are using "local" in timer() to set done equal to true. This is creating a new variable called done only accessible in that scope.
Same with your triggered variable, you are just re creating it.
All you have to do is just remove the local from line 12 and 19, it will instead just change the variable you had already defined instead of defining a new one for that scope.
It is "resetting" itself, because after that code in connect() and timer() are finished, it is still using the other variables you made at the beginning of the script because the other variables are now out of scope.
Hope this helped.