Hi
This is a follow on from a previous thread here (http://arduino.cc/forum/index.php/topic,109308.0.html) as I'm still unable to get my wireless arduino up and running.
I'm using a:
- WiFly RN-XV (http://www.sparkfun.com/products/11047)
- xBee Pro Shield (Xbee_Shield_For_Arduino__no_Xbee___SKU_DFR0015_-DFRobot)
- Arduino Duemilanove
(images attached below) on Arduino 1.0 with WiFly Driver for 1.0 (Arduino WiFly Driver - Browse Files at SourceForge.net).
I'm also using softwareserial for debugging through pins 4 and 5.
I've managed to get my WiFly configured (directly from the computer), the green led blinks slowly and my router devices shows the WiFly is on the network. The reason I did it this way was so I could keep my arduino code to a minimum so I could understand how to just start the wiflyserial and send a GET request from the arduino to a php webpage (no dealing with network configuration, passwords etc.).
Below is my arduino and php code which I can't get to work. It stops as soon as it gets to wifi.begin();. Now I assume there is nothing wrong with the WiFlySerial library itself so the only thing I can see that could go wrong this early is a) I'm not including something I should be or b) I'm using the wrong RX/TX in WiFlySerial wifi(2, 3);?
I think that it's the later, that my arduino isn't communicating with the rn-xv. Is there a way to test this?
Thanks in advance
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 "http://www.mysite.com/"
#define MY_SERVER_GET_URL "in-progress/arduino-test/counter/index.php"
WiFlySerial wifi(2, 3);
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;
//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);
}
index.php
<?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);
}
?>