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 transmits data to my web server).
When the battery runs out I replace with another battery, but then the wifi/arduino no longer communicates with my server..
I'm a newbie on Arduino and I don't understand whether if every time the power is off Arduino loses the program, or simply that the wifi is not able to auto-connect...
Is this a software problem or hardware? And if software what am I doing wrong?
This is my sketch example - I'm just sending a string to my server:
#include "WiFly.h"
#include "Credentials.h" // includes ny user:pass wifi network
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 everything works fine but when I unplug the power and plug it back the arduino doesnt restart the process.
I found the solution myself - the problem was with the hardware.
The problem was in my Arduino UNO R2, there is a known bug.
I bought a UNO R3 and I don't have this problem anymore.