This
#define MY_SERVER_GET "www.mysite.com"
#define MY_SERVER_GET_URL "http://www.mysite.com/in-progress/arduino-test/counter/index.php"
without the http:// seems to be doing something. In the Serial Monitor I'm now getting:
$$open www.mysite.com 80
GET http://www.mysite.com/in-progress/arduino-test/counter/index.php?count=237 HTTP/1.1
Host: www.mysite.com
Connection: close
with the count number incrementing up each time. My php counter however still doesn't seem to be called. The full code is below again.
thanks
Garrett
#include <Arduino.h>
#include <Time.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 "www.mysite.com"
#define MY_SERVER_GET_URL "http://www.mysite.com/in-progress/arduino-test/counter/index.php"
//xbee pro shiel uses pins 0, 1
WiFlySerial wifi(0, 1);
char bufRequest[REQUEST_BUFFER_SIZE];
char bufTemp[TEMP_BUFFER_SIZE];
//sotware serial pins for testing
//SoftwareSerial mySerial(4, 5);
//loop counter
int iLoopCounter = 0;
//start time
unsigned long startTime = 0;
void setup()
{
//set up serial
//Serial.begin(9600);
//set the data rate for the SoftwareSerial port and send a message to test
//mySerial.begin(9600);
//mySerial.println("Software serial working");
//start up WiFly
wifi.begin();
//mySerial.println("Joined");
}
void loop()
{
//calculate the time since last time the cycle was completed
unsigned long loopTime = millis() - startTime;
//to test
//mySerial.println("test 0");
//if the timer is greater than or equal to 5 seconds (5000 milliseconds)
if (loopTime >= 5000)
{
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
//to see what the GET request looks like
//mySerial << F("GET request:") << strRequest << endl;
//open connection, then send GET Request, and display response.
if (wifi.openConnection(MY_SERVER_GET))
{
wifi << (const char*) strRequest << endl;
//to test
//mySerial.println("test 2");
// Show server response
//how long to wait before timing out on the GET request
unsigned long TimeOut = millis() + 3000;
while (millis() < TimeOut && wifi.isConnectionOpen())
{
if (wifi.available() > 0)
{
wifi.read();
}
}
//force-close connection
wifi.closeConnection();
}
else
{
//failed to open
//mySerial.println("Failed to open connection");
}
//restart timer
startTime = millis();
}
//increment the loop counter
iLoopCounter++;
//to prevent spamming serial monitor too much
delay(250);
}