WiFly RN-XV webclient disconnects from the server

I need some help with the WiFly RN-XV to function as webclient.

I managed to connect to the server and store the sensor data. But the problem is that it is only stored one time. Soon after the first value is stored, the module disconnects from the server and does not store any more data.

Must be something pretty simple, but i can´t solve it … can someone help me please?

the library that I’m using is the WiFlyHQ.

I am using a lylipad and a wifly module with an lilypad xbee breakout board

the code is working, because every time i run the program, I can see in mysql server the value in the database. But only the 1st value is sent, after that, the module disconnects…

I’ve tried to follow the example in this link
https://codebender.cc/example/WiFlyHQ/httpclient

but it doesn´t work either.

here is my code:

#include <WiFlyHQ.h>
#include <SoftwareSerial.h>
SoftwareSerial wifiSerial(10,6);
WiFly wifly;
//Dados da rede
const char meuSSID = “myssid”;
const char minhaPassword = “myphrase”;
//Endereço do servidor
const char site = “mysite”;

// VARIABLES
int pulsePin = A5; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 5; // pin to blink led at each beat
int fadePin = A2; // pin to do fancy classy fading blink at each beat
int fadeRate = 0; // used to fade LED on with PWM on fadePin

// these variables are volatile because they are used during the interrupt service routine!
volatile int BPM; // used to hold the pulse rate
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // holds the time between beats, must be seeded!
volatile boolean Pulse = false; // true when pulse wave is high, false when it’s low
volatile boolean QS = false; // becomes true when Arduoino finds a beat.

char buffer[200];
unsigned long lastSend =0;

void setup(){
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(fadePin,OUTPUT); // pin that will fade to your heartbeat!
Serial.begin(115200);
char buf[32];
Serial.println(“A iniciar”);
Serial.print("Memoria livre: ");
Serial.println(wifly.getFreeMemory(),DEC);
wifiSerial.begin(9600);
if (!wifly.begin(&wifiSerial, &Serial)) {
Serial.println(“Falha a iniciar o wifly”);
}
//Se não estiver associado, associar à rede
if (!wifly.isAssociated()) {
//Comandos para ligar à rede
Serial.println(“Ligar a rede…”);
wifly.setSSID(meuSSID);
wifly.setPassphrase(minhaPassword);
wifly.enableDHCP();
if (wifly.join()) {
Serial.println(“Ligado a rede wireless”);
} else {
Serial.println(“Falha a ligar a rede”);
}
} else {
Serial.println(“Wifly ja se encontra ligado”);
}
Serial.print("MAC: ");
Serial.println(wifly.getMAC(buf, sizeof(buf)));
Serial.print("IP: ");
Serial.println(wifly.getIP(buf, sizeof(buf)));
Serial.print("Netmask: ");
Serial.println(wifly.getNetmask(buf, sizeof(buf)));
Serial.print("Gateway: ");
Serial.println(wifly.getGateway(buf, sizeof(buf)));
Serial.print("Host: ");
Serial.println(wifly.getHostIP(buf, sizeof(buf)));
if (wifly.isConnected()) {
Serial.println(“A desligar”);
wifly.close();
}
if(wifly.open(site, 80)){
Serial.print("Ligado a ");
Serial.println(site);
} else {
Serial.print("Falha a ligar a ");
Serial.println(site);
}
interruptSetup(); // sets up to read Pulse Sensor signal every 2mS
// UN-COMMENT THE NEXT LINE IF YOU ARE POWERING The Pulse Sensor AT LOW VOLTAGE,
// AND APPLY THAT VOLTAGE TO THE A-REF PIN
analogReference(EXTERNAL);
}
void loop(){
unsigned long tempo = 20000;
unsigned long currentMillis = millis();
if (QS == true){ // Quantified Self flag is true when arduino finds a heartbeat
fadeRate = 255; // Set ‘fadeRate’ Variable to 255 to fade LED with pulse
if(currentMillis + tempo > lastSend){
envioDados(BPM);
lastSend = currentMillis;
}
QS = false; // reset the Quantified Self flag for next time
}
ledFadeToBeat();
delay(20); // take a break
}
void ledFadeToBeat(){
fadeRate -= 15; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(fadePin,fadeRate); // fade LED
}
void envioDados(int dados){
if(wifly.isConnected()){
sprintf(buffer, “GET /add.php?valor=%d HTTP/1.0”, dados);
wifly.println(buffer);
wifly.println();
}
}

Thank you in advance for the help.

Just a reminder: you forgot the links the used library and you don't have code tags around the posted code.

To your problem: I never got the RN-XV to work reliably using a SoftwareSerial connection. It's quite picky about serial timings, so it often gets wrong characters from the SoftwareSerial. I changed my sketch to use the hardware serial interface and my problems went away immediately.

Then you open the connection in the setup routine, sending a GET request in the loop. The GET request is made using HTTP version 1.0, which means that the connection is closed after each request. Don't move to HTTP 1.1 and leave the connection open but change your code to open a new connection for each request. This is much more reliable and the usual way to go on an embedded platform.