Go Down

Topic: WiFlySerial and WiFly RN-XV (Read 4 times) previous topic - next topic

garrettlynch

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 (http://www.dfrobot.com/wiki/index.php?title=Xbee_Shield_For_Arduino_%28no_Xbee%29_%28SKU:DFR0015%29)
- Arduino Duemilanove

(images attached below) on Arduino 1.0 with WiFly Driver for 1.0 (http://sourceforge.net/projects/arduinowifly/files/).

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


Code: [Select]
#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

Code: [Select]
<?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);
}

?>

pylon

Quote
b) I'm using the wrong RX/TX in WiFlySerial wifi(2, 3);?


Yes, you're using the pins 2 and 3 but your shield is connected to 0 and 1 (http://www.shieldlist.org/dfrobot/xbee). With this shield you should think about using another library that uses the hardware UART instead of the SoftwareSerial library. Because you are using the same library for debugging and only one instance can be actively receiving data.

garrettlynch


Yes, you're using the pins 2 and 3 but your shield is connected to 0 and 1 (http://www.shieldlist.org/dfrobot/xbee).


ok I did suspected that was the case and had tried 0, 1 but it didn't work for me (what I didn't know was that using softwareserial to debug was causing a conflict).  I've commented out all the software serial debugging lines for now and in serial monitor I now see the line:

open http://www.mysite.com/ 80

every three seconds so it looks like it's connecting and the loop is firing.  However when I check my php page (which saves to a txt counter file) it's not being called.  The full url is (I've changed the domain name here):

http://www.mysite.com/in-progress/arduino-test/counter/index.php?count=1

The php works fine and the txt has write permissions.  This is how my query string is being formed:

Code: [Select]
#define MY_SERVER_GET "http://www.mysite.com"
#define MY_SERVER_GET_URL "in-progress/arduino-test/counter/index.php"


Code: [Select]
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";


Is this being formed correctly?  What's the 80 in the serial monitor message, the port or an error number?

With this shield you should think about using another library that uses the hardware UART instead of the SoftwareSerial library. Because you are using the same library for debugging and only one instance can be actively receiving data.


I'm looking for an alternative.

Thanks.

Garrett

pylon

Code: [Select]
#define MY_SERVER_GET_URL "in-progress/arduino-test/counter/index.php"

should be

Code: [Select]
#define MY_SERVER_GET_URL "/in-progress/arduino-test/counter/index.php"

The leading slash is needed.

garrettlynch

ah sorry I mistyped it here when I changed the url, the slash is there on the MY_SERVER_GET

Code: [Select]
#define MY_SERVER_GET "http://www.mysite.com/"
#define MY_SERVER_GET_URL "in-progress/arduino-test/counter/index.php"

Go Up