The github script above currently doesnt work. The issue is that after you switch Wifi on - it takes a few seconds until the Kindle connects to your network, and gets online - the script at that stage already is in the "connecting" stage - ("connecting" gets displayed) and seemingly not reinitializing the connection attempt, but just sitting idle/timing out.
Thats why I had the sleep 7 (sleep 6 should suffice as well

) delay in my "attempt" - but pinging until you get an answer would be a more elegant solution (maybe even shave off a second.

).
Cheers,
n.