You said
The Wifi has build in re-connection function, the code is really for back plan.
Im sure I read somewhere that it would try for maybe 15 minutes then drop back to adhoc mode. In this case if the outage is > 15 minutes and it drops to ad hoc mode its not going to recover into normal wifi when the internet resumes
Can you please clarify where my above code should go. should it go in rc.local?
Any chance you could show me what the full rc.local would look like?