Wifi Shield 2.0 (RN-171, Seeedstudio, WiFly): How to reconnect to AP

Ok, I did some further trying on my own.
For my first original question "How can I retrieve the information "still connected to AP" while being up and ready as a webserver?", I still haven't found an answer.
But at least I solved my second, alternative question "How can I make the Wifi Shield 2.0 automatically reconnect again once the AP is available again (after the circuit breaker for the room with the AP is in place again, for instance)?"
So finding a solution for the first question is not as urgent any more :mrgreen:

Anyway, here is the solution to make the wifi shield reconnect if the access point has been unavailable for some time.
It basically comes down to inserting

wifly.sendCommand("set wlan join 1\r");

If you have a look at the full code below, you will notice that my code still has the "delay" handling of executing commands (a delay of 100ms after each command) which is poor software design. It is a legacy from the example code that comes with the module.
You will notice that the delays around

wifly.sendCommand("set wlan linkmon 30\r");

have 500ms instead. It took me some time to find out that there appears to be a timing problem. Either I increase the delays, or I move linkmon up in the order of called commands (had it above set wlan hide first, and it worked with 100ms delay as well).
All very unsatisfying.

Anyway, here is the code (next post since this one exceeds 9000 characters) that finally works for me.
It is similar to example 5 of Wifi Shield V2.0 | Seeed Studio Wiki. But it has the ability to reconnect to the AP if the wifi connection failed temporarily.

Hope this helps some of the other newbies. Pros probably don't need this info since they would have known right away. :smiley: