SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By rubot
#141096
I'm trying to send data quickly then close the http connection but it seems to take as long as 10 seconds after the data has been sent. Ideally, i'm shooting for 1 - 2 seconds but i can't figure out what to set in order to close the connection faster. Anyone out there have any idea?

Setup:
Arduino IDE 1.0
WiFlySerial library
Arduino Uno
RN-XV
Xbee Break Out Board

Sketch:
Code: Select all
#include <SoftwareSerial.h>
#include <Streaming.h>
#include <WiFlySerial.h>

#define RX 2
#define TX 3
#define BUFFER_SIZE 80

WiFlySerial wifi(RX, TX);
char buffer[BUFFER_SIZE];
unsigned long t1;
unsigned long t2;

void setup()
{
  Serial.begin(9600);
  Serial.println("Starting...");
  wifi.begin();
  wifi.setAuthMode(WIFLY_AUTH_WPA2_PSK);
  wifi.setJoinMode(WIFLY_JOIN_AUTO);
  wifi.setDHCPMode(WIFLY_DHCP_ON);
  wifi.SendCommand("set u m 0x1", ">",buffer, BUFFER_SIZE);
  wifi.SendCommand("set comm remote 0", ">",buffer, BUFFER_SIZE);
  wifi.SendCommand("set comm match 0x9", ">",buffer, BUFFER_SIZE);
  wifi.setPassphrase(passphrase);
  wifi.join(ssid);
  delay(1000);
  Serial << F("NETWORK") << endl
    << F("---MAC: ") << wifi.getMAC(buffer, BUFFER_SIZE) << endl
    << F("---IP: ") << wifi.getIP(buffer, BUFFER_SIZE) << endl
    << F("---Netmask: ") << wifi.getNetMask(buffer, BUFFER_SIZE) << endl
    << F("---Gateway: ") << wifi.getGateway(buffer, BUFFER_SIZE) << endl
    << F("---DNS: ") << wifi.getDNS(buffer, BUFFER_SIZE) << endl
    << F("---RSSI: ") << wifi.getRSSI(buffer, BUFFER_SIZE) << endl
    << F("---battery: ") <<  wifi.getBattery(buffer, BUFFER_SIZE) << endl;
  Serial << "Ready." << endl << endl;
}

void loop()
{
  wifi.getDeviceStatus();
  if(wifi.serveConnection())
  {
    t1 = millis();
    Serial << t1 << ":" << "Connected" << endl;
    wifi.ScanForPattern(buffer, BUFFER_SIZE, " HTTP/1.1", 250);
    Serial << "GET request,  bytes: " << strlen(buffer) << " request: " << buffer << endl;
    wifi << "HTTP/1.1 200 OK \r Content-Type: text/html;charset=UTF-8\r Connection: close \r\n\r\n \r" << millis() << "\r\n\r\n" << "\t";
    wifi.closeConnection();
    t2 = millis();
    Serial << t2 << ":" << "Connection Closed, Duration: " << (t2 -t1) / 1000 << " seconds" << endl;

  }
}
Serial Monitor Output:
Code: Select all
Starting...
NETWORK
---MAC: ##:##:##:##:##:##
---IP: ###.###.###.###:2000
---Netmask: ###.###.###.###
---Gateway: ###.###.###.###
---DNS: ###.###.###.###
---RSSI: (-60) dBm
---battery: 3000
Ready.

60286:Connected
GET request,  bytes: 14 request: GET / HTTP/1.1
70853:Connection Closed, Duration: 10 seconds