wifly + arduino + reconnect/autoconnect problem

I’m using the WiFly shield with Arduino, and everything works fine: I upload my skecth to Arduino via USB, i connect a 9V battery, i disconnect the USB, and the wifi module transmits everything fine (it transmit data to my web server).

when the battery runs out, i replace with another battery, but then the wifi/arduino doesnt communicate anymore with my server…

so i’m a newbie on Arduino and i dont understand if every time the power is off Arduino loses all the program, or simply is the wifi that is not able to auto-connect…

is a software problem or hardware?

and if software what i’m doing wrong?

this is my sketch example - i’m just sending a string to my server just as an example:

#include “WiFly.h”

#include “Credentials.h”

Client client(“[myserverip]”, 80);

void setup() {

Serial.begin(9600);

WiFly.begin();

if (!WiFly.join(ssid, passphrase)) {

Serial.println(“Association failed.”);

while (1) {

// Hang on failure.

}

}

connectServer();

}

void loop() {

if (client.available()) {

char c = client.read();

Serial.print(c);

}

if (!client.connected()) {

Serial.println();

Serial.println(“disconnecting.”);

client.stop();

delay(60000); // check every minute

connectServer();

}

}

void connectServer() {

Serial.println(“connecting…”);

if (client.connect()) {

Serial.println(“connected”);

String query = “GET /arduino/test?q=testString HTTP/1.0”;

client.println(query);

client.println();

} else {

Serial.println(“connection failed”);

}

}

so everythign works fine but when i unplug the power and plug it back the arduino doesnt restart the process

thanks