First steps with WiFly and Arduino

Hi

Trying to get a WiFly (this one RN-XV WiFly Module - RP-SMA Connector - WRL-11047 - SparkFun Electronics), xBee Pro Shield and Arduino Duemilanove to work together. Ultimately I want the arduino to pull data from the web but at the moment getting anything working and understanding it would be a start. I've started with the WiFly_Test sketch, entered my network details, uploaded it and watched the serial monitor but it gets no further than "Starting WiFly Tester. Free memory:1168". The red leds never stop flashing (im guessing a bad thing).

Can anyone recommend a tutorial that walks through the WiFly_Test sketch step by step or another very simple one? All the tutorials I'm finding are broken links. Or can you tell me if something needs to be done before I upload the sketch i.e. does the WiFly need to be pre-configured? What about the xBee/USB switch on the shield do I need to toggle that between positions? It seems you do if you have an xBee on the shield.

Thanks in advance.
Garrett

You didn't provide a link to the code your using. There are several libraries to be used with the WiFly Bees. Provide links to the one you used and post the full code of the sketch you're using.

My RN-XV works without any problem but I configured it manually and patched the library to be more predictable.

Hi

Thanks for your reply. Yes I didn't know there were several libraries for this when I posted and it's since added to my confusion even more. I'll try to be as descriptive as possible. I've attached photos of the arduino, wifly and xbee shield I'm using for reference.

So far I've been through the WiFly library (this one: https://github.com/jmr13031/WiFly-Shield) - but I believe that's pre-version 1 of Arduino?, the WiFlySerial library (this one: Arduino WiFly Driver - Browse Files at SourceForge.net) and WiFlyHQ (this one: https://github.com/harlequin-tech/WiFlyHQ). The last two compile and upload their examples fine and each starts, puts output in the serial monitor and then seems to go no further.

This is the WiFly_Test sketch I've mentioned which is an example that comes with WiFlySerial. I don't care which library or demo I get working, anything would be a start I could start working back from.

thanks
Garrett

WiFly_Test:

/*
 * WiFly_Device Test Platform
 * A simple tester for communicating with the WiFly GSx RN-131b/g series.
 * LGPL 2.0
 * Tom Waldock, 2011 
 */

#include <Arduino.h>
#include <Streaming.h>
#include <SoftwareSerial.h>
#include "WiFlySerial.h"
#include "MemoryFree.h"
#include "Credentials.h"


// Pins are 3 for INCOMING TO Arduino, 5 for OUTGOING TO Wifly
// Arduino       WiFly
//  2 - receive  TX   (Send from Wifly, Receive to Arduino)
//  3 - send     RX   (Send from Arduino, Receive to WiFly) 
WiFlySerial WiFly(2,3); 

#define REQUEST_BUFFER_SIZE 120
#define HEADER_BUFFER_SIZE 150 
#define BODY_BUFFER_SIZE 100

char bufRequest[REQUEST_BUFFER_SIZE];
char bufHeader[HEADER_BUFFER_SIZE];
char bufBody[BODY_BUFFER_SIZE];


void setup() {
  
  Serial.begin(9600);
  Serial.println(F("Starting WiFly Tester." ) );
  Serial << F("Free memory:") << freeMemory() << endl;  

  WiFly.begin();
  Serial << F("Starting WiFly...") <<  WiFly.getLibraryVersion(bufRequest, REQUEST_BUFFER_SIZE)
   << F(" Free memory:") << freeMemory() << endl;
  
  // get MAC
  Serial << F("MAC: ") << WiFly.getMAC(bufRequest, REQUEST_BUFFER_SIZE) << endl;
  // is connected ?
  
  // WiFly.setDebugChannel( (Print*) &Serial);
  
  WiFly.setAuthMode( WIFLY_AUTH_WPA2_PSK);
  WiFly.setJoinMode(  WIFLY_JOIN_AUTO );
  WiFly.setDHCPMode( WIFLY_DHCP_ON );

   
  // if not connected restart link
  WiFly.getDeviceStatus();
  if (! WiFly.isifUp() ) {
    Serial << "Leave:" <<  ssid << WiFly.leave() << endl;
    // join
    if (WiFly.setSSID(ssid) ) {    
      Serial << "SSID Set :" << ssid << endl;
    }
    if (WiFly.setPassphrase(passphrase)) {
      Serial << "Passphrase Set :" << endl;
    }
    Serial << "Joining... :"<< ssid << endl;

    if ( WiFly.join() ) {
      Serial << F("Joined ") << ssid << F(" successfully.") << endl;
      WiFly.setNTP( ntp_server ); // use your favorite NTP server
    } else {
      Serial << F("Join to ") << ssid << F(" failed.") << endl;
    }
  } // if not connected

  Serial << F("IP: ") << WiFly.getIP(bufRequest, REQUEST_BUFFER_SIZE) << endl <<
    F("Netmask: ") << WiFly.getNetMask(bufRequest, REQUEST_BUFFER_SIZE) << endl <<
    F("Gateway: ") << WiFly.getGateway(bufRequest, REQUEST_BUFFER_SIZE) << endl <<
    F("DNS: ") << WiFly.getDNS(bufRequest, REQUEST_BUFFER_SIZE) << endl 
    << F("WiFly Sensors: ") << bufBody <<  WiFly.SendCommand("show q 0x177 ",">", bufBody, BODY_BUFFER_SIZE) << endl
    << F("WiFly Temp: ") <<  WiFly.SendCommand("show q t ",">", bufBody, BODY_BUFFER_SIZE)
    << F("WiFly battery: ") << WiFly.getBattery(bufBody, BODY_BUFFER_SIZE) << endl;

  WiFly.SendCommand("set comm remote 0",">", bufBody, BODY_BUFFER_SIZE);
  memset (bufBody,'\0',BODY_BUFFER_SIZE);

  WiFly.closeConnection();
  Serial << F("After Setup mem:") << freeMemory() << endl ;
  
  Serial << F("WiFly now listening for commands.  Type 'exit' to listen for wifi traffic.  $$ (no CR) for command-mode.") << endl;


  // clear out prior requests.
  WiFly.flush();
  while (WiFly.available() )
    WiFly.read();
  
}

char chOut;
void loop() {
  // Terminal routine

  // Always display a response uninterrupted by typing
  // but note that this makes the terminal unresponsive
  // while a response is being received.
  
  while(WiFly.available() > 0) {
    Serial.write(WiFly.read());
  }
  
  if(Serial.available()) { // Outgoing data
    WiFly.write( (chOut = Serial.read()) );
    Serial.write (chOut);
  }

} //loop

In the Creditials.h below is SSID the network name and passphrase the WEP number? I've read that this needs to be 128 bit on my network and have set it as that.

Credentials.h:

#ifndef __CREDENTIALS_H__
#define __CREDENTIALS_H__

// Wifi parameters
char passphrase[] = "PassPhrase"; //"YourSecretPassPhrase123"
char ssid[] = "SSID"; //"YourSSID"
char ntp_server[] = "nist1-la.ustiming.org"; // or your favorite ntp server.

#endif

MemoryFree.cpp:

extern unsigned int __bss_end;
extern unsigned int __heap_start;
extern void *__brkval;


#include "MemoryFree.h"


int freeMemory() {
  int free_memory;

  if((int)__brkval == 0)
     free_memory = ((int)&free_memory) - ((int)&__bss_end);
  else
    free_memory = ((int)&free_memory) - ((int)__brkval);

  return free_memory;
}

MemoryFree.h:

// memoryFree header

#ifndef	MEMORY_FREE_H
#define MEMORY_FREE_H

#ifdef __cplusplus
extern "C" {
#endif

int freeMemory();

#ifdef  __cplusplus
}
#endif

#endif

First you have to know your network parameters (the WiFi). From what you write it seems you're using WEP (and not WPA or WPA2). In the example code a WPA2 passphrase is chosen, so for WEP you have to change

WiFly.setAuthMode( WIFLY_AUTH_WPA2_PSK);

to

WiFly.setAuthMode(WIFLY_AUTH_WEP);

and set the WEP keys accordingly. Unfortunately the library doesn't support that (setting the WEP key), so you have to do that manually, switching the Bee to USB and sending commands from your serial terminal. The command for setting the WEP key is

set wlan key <key-value>

This and other available commands are in the WiFly User Manual and Command Reference (WiFly-RN-UM). You probably should read in that document and should it be only for reference.

pylon:
Unfortunately the library doesn't support that (setting the WEP key), so you have to do that manually, switching the Bee to USB and sending commands from your serial terminal. The command for setting the WEP key is

set wlan key <key-value>

This and other available commands are in the WiFly User Manual and Command Reference (WiFly-RN-UM). You probably should read in that document and should it be only for reference.

Hi

Can't believe I didn't spot the WPA2 line. Anyway no change, it's this last bit I'm sure I doing wrong, I understand how to send the command from the serial monitor but am not sure what you mean by switching the bee to usb. Is the switch the part I've highlighted in the attached image? If so I permanently have the switch on the USB side as sketches don't send when they are on the xbee side.

Is there a better library to use for setting the WEP key in the sketch?

Thanks in advance.

Garrett

This switch has to be on the USB side when you're transferring sketches to the Arduino but on the Bee side when this sketch runs as otherwise your Arduino has no connection to the RN-XV.

You also have to remove all Serial code from your sketch as the Serial is used for communication with the RN-XV, you cannot use the serial connection for the Bee and for debugging at the same time.

Thanks for your patience on this, still no joy.

pylon:
This switch has to be on the USB side when you're transferring sketches to the Arduino but on the Bee side when this sketch runs as otherwise your Arduino has no connection to the RN-XV.

right I understand.

pylon:
You also have to remove all Serial code from your sketch as the Serial is used for communication with the RN-XV, you cannot use the serial connection for the Bee and for debugging at the same time.

So every line that has a call to serial needs to be commented out? That's nearly every second line in the example I have, if all of that is gone how do I know if it has successfully joined a network or not? At the moment my WiFly_Test sketch looks like this.

/*
 * WiFly_Device Test Platform
 * A simple tester for communicating with the WiFly GSx RN-131b/g series.
 * LGPL 2.0
 * Tom Waldock, 2011 
 */

#include <Arduino.h>
#include <Streaming.h>
#include <SoftwareSerial.h>
#include "WiFlySerial.h"
#include "MemoryFree.h"
#include "Credentials.h"


// Pins are 3 for INCOMING TO Arduino, 5 for OUTGOING TO Wifly
// Arduino       WiFly
//  2 - receive  TX   (Send from Wifly, Receive to Arduino)
//  3 - send     RX   (Send from Arduino, Receive to WiFly) 
WiFlySerial WiFly(2,3); 

#define REQUEST_BUFFER_SIZE 120
#define HEADER_BUFFER_SIZE 150 
#define BODY_BUFFER_SIZE 100

char bufRequest[REQUEST_BUFFER_SIZE];
char bufHeader[HEADER_BUFFER_SIZE];
char bufBody[BODY_BUFFER_SIZE];


void setup() {
  
  //Serial.begin(9600);
  //Serial.println(F("Starting WiFly Tester." ) );
  //Serial << F("Free memory:") << freeMemory() << endl;  

  WiFly.begin();
  //Serial << F("Starting WiFly...") <<  WiFly.getLibraryVersion(bufRequest, REQUEST_BUFFER_SIZE)
  // << F(" Free memory:") << freeMemory() << endl;
  
  // get MAC
  //Serial << F("MAC: ") << WiFly.getMAC(bufRequest, REQUEST_BUFFER_SIZE) << endl;
  // is connected ?
  
  WiFly.setDebugChannel( (Print*) &Serial);
  
  //WPA2 security
  //WiFly.setAuthMode( WIFLY_AUTH_WPA2_PSK);
  
  //WEP 128 bit security
  WiFly.setAuthMode(WIFLY_AUTH_WEP);
  
  WiFly.setJoinMode(  WIFLY_JOIN_AUTO );
  WiFly.setDHCPMode( WIFLY_DHCP_ON );

   
  // if not connected restart link
  WiFly.getDeviceStatus();
  if (! WiFly.isifUp() ) {
    //Serial << "Leave:" <<  ssid << WiFly.leave() << endl;
    // join
    if (WiFly.setSSID(ssid) ) {    
      //Serial << "SSID Set :" << ssid << endl;
    }
    if (WiFly.setPassphrase(passphrase)) {
      //Serial << "Passphrase Set :" << endl;
    }
    //Serial << "Joining... :"<< ssid << endl;

    if ( WiFly.join() ) {
      //Serial << F("Joined ") << ssid << F(" successfully.") << endl;
      WiFly.setNTP( ntp_server ); // use your favorite NTP server
    } else {
      //Serial << F("Join to ") << ssid << F(" failed.") << endl;
    }
  } // if not connected

  Serial << F("IP: ") << WiFly.getIP(bufRequest, REQUEST_BUFFER_SIZE) << endl <<
    F("Netmask: ") << WiFly.getNetMask(bufRequest, REQUEST_BUFFER_SIZE) << endl <<
    F("Gateway: ") << WiFly.getGateway(bufRequest, REQUEST_BUFFER_SIZE) << endl <<
    F("DNS: ") << WiFly.getDNS(bufRequest, REQUEST_BUFFER_SIZE) << endl 
    << F("WiFly Sensors: ") << bufBody <<  WiFly.SendCommand("show q 0x177 ",">", bufBody, BODY_BUFFER_SIZE) << endl
    << F("WiFly Temp: ") <<  WiFly.SendCommand("show q t ",">", bufBody, BODY_BUFFER_SIZE)
    << F("WiFly battery: ") << WiFly.getBattery(bufBody, BODY_BUFFER_SIZE) << endl;

  WiFly.SendCommand("set comm remote 0",">", bufBody, BODY_BUFFER_SIZE);
  memset (bufBody,'\0',BODY_BUFFER_SIZE);

  WiFly.closeConnection();
  //Serial << F("After Setup mem:") << freeMemory() << endl ;
  
  //Serial << F("WiFly now listening for commands.  Type 'exit' to listen for wifi traffic.  $$ (no CR) for command-mode.") << endl;


  // clear out prior requests.
  WiFly.flush();
  while (WiFly.available() )
    WiFly.read();
  
}

char chOut;
void loop() {
  // Terminal routine

  // Always display a response uninterrupted by typing
  // but note that this makes the terminal unresponsive
  // while a response is being received.
  
  while(WiFly.available() > 0) {
    //Serial.write(WiFly.read());
  }
  
  //if(Serial.available()) { // Outgoing data
  //  WiFly.write( (chOut = Serial.read()) );
  //  Serial.write (chOut);
  //}

} //loop

There are several possibilities to debug if the serial is used for device communication. The cheapest and fastest to realise is using one ore more LEDs to show some states. An easy one from the programmers view is using SoftwareSerial to establish a serial interface on two (one is sufficient for debugging) digital pins. You then need a USB2Serial adapter (available from Arduino or other suppliers) to connect that serial to your PC. The third option is an LCD display to show the messages. There different versions available, from 4-bit to 8-bit parallel and almost any serial connection (UART is not feasible in your situation, but I2C or SPI will do).

I think your stock of devices and/or budget will decide. :slight_smile:

pylon:
There are several possibilities to debug if the serial is used for device communication. The cheapest and fastest to realise is using one ore more LEDs to show some states. An easy one from the programmers view is using SoftwareSerial to establish a serial interface on two (one is sufficient for debugging) digital pins. You then need a USB2Serial adapter (available from Arduino or other suppliers) to connect that serial to your PC. The third option is an LCD display to show the messages. There different versions available, from 4-bit to 8-bit parallel and almost any serial connection (UART is not feasible in your situation, but I2C or SPI will do).

I think your stock of devices and/or budget will decide. :slight_smile:

Yes I've seen somebody testing with LEDs, different LEDs, flashing rates etc. I'd much rather debug with messages back to Serial Monitor but I don't understand how a usb2serial is needed. My arduino is USB and I have no serial ports on my mac, I thought the USB on the arduino doubled up as serial and power? Also the three LEDs on the WiFly, aren't they LEDs showing the WiFly's state?

I've now tried turning off all security (wep) on my network and still no change, the red led on the WiFly never stops flashing rapidly.

Yes, your Arduino has a USB connection that doubles as power source and serial connection. The problem is that the Arduino has only one serial port (in hardware) and that one is used for the USB connection when uploading sketches. Because XBees usually also communicate using the serial, there is a conflict which is usually solved by disconnecting (in your case toggling the switch) the XBee shield when uploading the sketches and using the serial connection the rest of the time.
It's a bit like your phone at home. You can phone different people without any problem but only one at a time. The phone company has some switching circuitry to switch you through to the different people. A standard Arduino (without additional electronics) does not have such a switching logic, so you have to do this manually.

You're right, that the LEDs on the shield change their state when you are successfully connected to the network.

Have you removed all the serial stuff from the sketch with the exception I mentioned in a earlier post? Because else you won't ever connect to your network because the RN-XV will be confused with the debugging stuff your sending to it.

Yes I think I have removed all the serial code. Below is my sketch. I've also tried changing my network to WPA-PSK Encryption (WPA2) and used WiFly.setAuthMode( WIFLY_AUTH_WPA2_PSK); in the sketch but nothing changes.

/*
 * WiFly_Device Test Platform
 * A simple tester for communicating with the WiFly GSx RN-131b/g series.
 * LGPL 2.0
 * Tom Waldock, 2011 
 */

#include <Arduino.h>
#include <Streaming.h>
#include <SoftwareSerial.h>
#include "WiFlySerial.h"
#include "MemoryFree.h"
#include "Credentials.h"


// Pins are 3 for INCOMING TO Arduino, 5 for OUTGOING TO Wifly
// Arduino       WiFly
//  2 - receive  TX   (Send from Wifly, Receive to Arduino)
//  3 - send     RX   (Send from Arduino, Receive to WiFly) 
WiFlySerial WiFly(2,3); 

#define REQUEST_BUFFER_SIZE 120
#define HEADER_BUFFER_SIZE 150 
#define BODY_BUFFER_SIZE 100

char bufRequest[REQUEST_BUFFER_SIZE];
char bufHeader[HEADER_BUFFER_SIZE];
char bufBody[BODY_BUFFER_SIZE];


void setup() {
  
  WiFly.begin();
  
  WiFly.setDebugChannel( (Print*) &Serial);
  
  //WEP 128 bit security
  WiFly.setAuthMode(WIFLY_AUTH_WEP);
  
  //WPA2 security
  //WiFly.setAuthMode( WIFLY_AUTH_WPA2_PSK);
  
  WiFly.setJoinMode(  WIFLY_JOIN_AUTO );
  WiFly.setDHCPMode( WIFLY_DHCP_ON );

  // if not connected restart link
  WiFly.getDeviceStatus();
  if (! WiFly.isifUp() ) {

    // join
    if (WiFly.setSSID(ssid) ) {    
      //Serial << "SSID Set :" << ssid << endl;
    }
    
    if (WiFly.setPassphrase(passphrase)) {

    }

    if ( WiFly.join() ) {
      WiFly.setNTP( ntp_server ); // use your favorite NTP server
    } else {

    }
  } // if not connected

  WiFly.SendCommand("set comm remote 0",">", bufBody, BODY_BUFFER_SIZE);
  memset (bufBody,'\0',BODY_BUFFER_SIZE);

  WiFly.closeConnection();

  // clear out prior requests.
  WiFly.flush();
  while (WiFly.available() )
    WiFly.read();
  
}

char chOut;
void loop() {
  // Terminal routine

  // Always display a response uninterrupted by typing
  // but note that this makes the terminal unresponsive
  // while a response is being received.
  
  while(WiFly.available() > 0) {
 
  }

} //loop

If you remove your WEP authentication you don't have any encryption. Or was that a misunderstanding and you changed your encryption to WPA2 (PSK)?

I tried last night with out any encryption so my network was open and I removed the line WiFly.setAuthMode(WIFLY_AUTH_WEP);. Today I tried WPA2 (just in case as every example I'm finding on the web is for WPA2) and used the line WiFly.setAuthMode( WIFLY_AUTH_WPA2_PSK);. Nether of these tests have changed anything.

If you disabled the encryption you cannot just remove a line and expect the configuration to be also removed. The library does configure the RN-XV by sending serial commands. Although the library looks like that these configuration has to be made at every startup, this is not true. The RN-XV stores it's configuration in EEPROM. So if the last configuration was WPA2 and you remove the configuration line, it stays WPA2 and is not changing to any default value.
To have no encryption the value has to be changed to WIFLY_AUTH_OPEN.

I configured my RN-XV by connecting it directly (better by the use of a Foca) to my notebook and sending the serial commands myself. So I have immediate feedback from the device and if I was successful, I simply disconnect the Bee from the notebook and connect it to the Arduino. After powerup it reconnects to the WiFi network and shows success by it's status LED.

pylon:
If you disabled the encryption you cannot just remove a line and expect the configuration to be also removed. The library does configure the RN-XV by sending serial commands. Although the library looks like that these configuration has to be made at every startup, this is not true. The RN-XV stores it's configuration in EEPROM. So if the last configuration was WPA2 and you remove the configuration line, it stays WPA2 and is not changing to any default value.
To have no encryption the value has to be changed to WIFLY_AUTH_OPEN.

I configured my RN-XV by connecting it directly (better by the use of a Foca) to my notebook and sending the serial commands myself. So I have immediate feedback from the device and if I was successful, I simply disconnect the Bee from the notebook and connect it to the Arduino. After powerup it reconnects to the WiFi network and shows success by it's status LED.

Hi

Ok I've just tied it with my network open and using the line WiFly.setAuthMode( WIFLY_AUTH_OPEN ); - still no change, doesn't connect. Not sure what a Foca is? I'm happy to try and configure it directly, I've seen this mentioned in the WiFly userguide, using $$$ and changing modes etc. but what do I do this through on osx? Can it be done in osx terminal?

You need a serial terminal or the serial monitor of the Arduino IDE, so no problem, it works with your OS X box. The Foca is one of many available USB2Serial adapters. USB2Serial Light is one from the original Arduino manufacturers which also is a possibility but more difficult to wire. Another possibility might be to use your XBee shield and switch the serial selector to the position where the sketch transfer does not work (I think you called it Bee position). Then you should be able to communicate to the Bee directly, at least on my shield this works.

ok some progress, I abandoned doing it in the sketch and searched around for a way to talk to the WiFly from osx, this pdf: ww1.microchip.com/downloads/en/.../rn-wifly-eval-um-ver1.0r.pdf

was a god send and recommended CoolTerm. Followed the steps in the pdf to configure it for a WEP secured network and it looks like it has connected. No flashing red light and now I have a slow pulsing green light so I think that means it has an ip and is connected. I can also see the device in my network now.

Since testing seems to be quite difficult I want to make a slow looping sketching which passes a number (a counter) to a php file online which in turn will write it to a text file. Php side is easy and I think I can conceptualise the loop in arduino. I've spotted this in an example:

  // Open connection, then sent GET Request, and display response.
  if (wifi.openConnection( MY_SERVER_POST ) ) {
    
    wifi <<  (const char*) strRequest ; 
    
    // Show server response

    unsigned long TimeOut = millis() + 3000;

    while ( millis()  < TimeOut && wifi.isConnectionOpen() ) {
      if (  wifi.available() > 0 ) {
        Serial <<  (char) wifi.read();
      }
    }
    
    // Force-close connection

    wifi.closeConnection();
 
  } else {
    // Failed to open
    Serial << GetBuffer_P(IDX_WT_MSG_FAIL_OPEN,bufTemp,TEMP_BUFFER_SIZE) << MY_SERVER_POST << endl;
  }

Which I think gives me the actual GET calls. If you have advice on this last part I'd appreciate it. Once I get this working I'm going to post it all to this thread because this was far more difficult than it should be.

Garrett

This will probably not work for you as it uses the Serial for debugging:

Serial <<  (char) wifi.read();

You have to redirect somewhere else like I wrote to a SoftwareSerial or ignore the read value completely (not recommended).

Hi

Yes I know I'm not retrieving the data arduino side I want to send it and I'll check it php/txt side. So essentially I want to send a GET to:

mypage.php?count=1

And the php will write it to a file. It's the openconnection, while loop and closeconnection in that code which I think will help me.

Hi

On the final bit now I think but I'm confused on what I hope is just one last detail. I'm unsure what line is the actual GET request being made in my arduino code. I copied mine from a demo that came with WiFlySerial library that does both GET and POST requests and I can see where the request line is built - just not where it's executed.

Anyway in the demo below the loop I've made should work every five second (it was working without all the WiFly code). I've highlighted where I'm stuck inside the "if (WiFly.openConnection(MY_SERVER_GET))" section which is not working (the counter.txt file online isn't updating). What should I be doing here?

Thanks in advance
Garrett

#include <Arduino.h>
#include <SoftwareSerial.h>
#include <Streaming.h>
#include <PString.h>
#include "WiFlySerial.h"


//various buffer sizes
#define REQUEST_BUFFER_SIZE 180
#define TEMP_BUFFER_SIZE 60

//server hosting GET example php script
#define MY_SERVER_GET "http://www.mysite.com/"
#define MY_SERVER_GET_URL "pathway/to/index.php"


//WiFly pins
#define ARDUINO_RX_PIN  2
#define ARDUINO_TX_PIN  3

WiFlySerial WiFly(ARDUINO_RX_PIN ,ARDUINO_TX_PIN);
char bufRequest[REQUEST_BUFFER_SIZE];
char bufTemp[TEMP_BUFFER_SIZE];




//loop counter
int iLoopCounter = 0;

//start time
unsigned long startTime = 0;


void setup()
{
  //set up serial
  //Serial.begin(9600);
  
  //start up WiFly
  WiFly.begin();
}


void loop()
{
  //calculate the time since last time the cycle was completed
  unsigned long loopTime = millis() - startTime;

  //if the timer is greater than or equal to 5 seconds (5000 milliseconds)
  if (loopTime >= 5000)
  {
    //trigger
    //Serial.println("Loop");
    
    char bufRequest[REQUEST_BUFFER_SIZE];
    PString strRequest(bufRequest, REQUEST_BUFFER_SIZE);
      
    // Build GET expression
    strRequest << F("GET ") << MY_SERVER_GET_URL << F("?count=") << iLoopCounter 
    << F(" HTTP/1.1") << "\n"
    << F("Host: ") << MY_SERVER_GET << "\n"
    << F("Connection: close") << "\n"
    << "\n\n";
    // send data via request
    // close connection
  
    //open connection, then send GET Request, and display response.
    if (WiFly.openConnection(MY_SERVER_GET))
    {
      
      
      //***
      //I'm confused about this bit, what's actually doing the GET request here?
      //I don't think I need the wjile at the moment - that's testing the request has happened right?

      WiFly <<  (const char*) strRequest; 
    
      // Show server response

      //how long to wait before timing out on the GET request
      unsigned long TimeOut = millis() + 3000;

      while (millis()  < TimeOut && WiFly.isConnectionOpen())
      {
        if (WiFly.available() > 0)
        {
            WiFly.read();
        }
      }

      //I'm confused about this bit, what's actually doing the GET request here?
      //***
      
      

      //force-close connection
      WiFly.closeConnection();
    }
    else
    {
      //failed to open
    }
  
    //restart timer
    startTime = millis();
  }

  //increment the loop counter
  iLoopCounter++;

  //to prevent spamming serial monitor too much
  delay(250);
}

This is the php counter if you need to see it, this works fine.

<?php

//error_reporting(E_ALL ^ E_NOTICE);

//if their is a GET request
if ($_SERVER['REQUEST_METHOD'] == 'GET') 
{
	//for debugging
	//print_r($_GET);

	//if count number in url
	if ($_REQUEST['count'])
	{
		//get count number in url
		$count = $_REQUEST['count'];
	}
	else
	{
		//error no count number in url
		$error = "No count passed in url.";
	}

	//name of the counter database file
	$logfile = "counter.txt";

	//open the counter file
	$handle = fopen($logfile, "r+") or die("Can't write to log file! Please Change the file permissions (CHMOD to 666 on UNIX machines!)");

	//write the passed count to the file
	fwrite($handle, $count);

	//close file
	fclose($handle);
}

?>