@osprey, the code i wrote will automatically attempt to reconnect the moment wifi connection drops.
If you have a requirement that the device must first connect upon boot-up, you can add a Spark.connect() in setup().
I have to warn that your device will be stuck here until it finally connects so it is all or nothing.
Otherwise, the snippet i wrote above will work well. Give it a try and see how it behaves 