Pages: [1] 2   Go Down
Author Topic: WiFlySerial and WiFly RN-XV  (Read 4656 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
<?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);
}

?>


* index.jpg (282.7 KB, 960x720 - viewed 48 times.)

* index-1.jpg (266.43 KB, 960x720 - viewed 47 times.)
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#define MY_SERVER_GET "http://www.mysite.com"
#define MY_SERVER_GET_URL "in-progress/arduino-test/counter/index.php"

Code:
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
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

should be

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

The leading slash is needed.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 631
Posts: 50086
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the slash is there on the MY_SERVER_GET
But that's not where it needs to be.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have tried

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

and this

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

Still no change, my php page doesnot get called.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This

Code:
#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:

Code:
$$$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

Code:
#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);
}
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This is not correct:

Code:
GET http://www.mysite.com/in-progress/arduino-test/counter/index.php?count=237 HTTP/1.1

On the GET line you must not supply a URL (with the http:// and the server) but the path (location) on the server. And use HTTP/1.0 as you don't use any HTTP 1.1 feature, some servers are a bit picky about that.

Have you checked if you WiFly gets an IP? And a DNS server? Does your www.mysite.com resolve on that DNS server?

Have tried doing the same request manually (using the telnet command on the command line)?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On the GET line you must not supply a URL (with the http:// and the server) but the path (location) on the server.

You mean path client side not server side right?


Have you checked if you WiFly gets an IP? And a DNS server? Does your www.mysite.com resolve on that DNS server?

Through my router configuration panel yes.  It has the ip 192.168.1.68.  A DNS server, for my WiFly or for www.mysite.com?  Mysite.com works, I can access it through a browser.  If I type it's ip address it also works.


Have tried doing the same request manually (using the telnet command on the command line)?

Yes and it works fine.

Code:
telnet mysite.com 80
Trying 62.81.51.152...
Connected to mysite.com.
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You mean path client side not server side right?

No, I mean server side. A web client requests a resource on the server. That resource has a path (better: location) on the server and that's what you have to supply on the GET line.

Quote
I can access it through a browser.

That doesn't mean it's available for the Arduino. Is that www.mysite.com a local or a remote site? Meaning, is it in your LAN or somewhere else in the Internet?
Your browser can also access the site if it's IP is registered in the hosts file or (if you're working on windows) if you gave it a local WINS name. Arduino is not Windows, it just asks the DNS server. I don't think this is a problem, I just wanna check it too.

Code:
telnet mysite.com 80
Trying 62.81.51.152...
Connected to mysite.com.

This is just a connection test, you haven't sent the request. After you have the connection send that line with hitting return twice at the end:

Code:
GET /in-progress/arduino-test/counter/index.php?count=237 HTTP/1.0

Post the result you get (you can change all IPs and domain names if your security imposes).
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

[No, I mean server side. A web client requests a resource on the server. That resource has a path (better: location) on the server and that's what you have to supply on the GET line.

I think we are talking at cross purposes though.  I'm used to programming in things like php and when I mean server-side path I don't mean the tail end of the url.

i.e. not /in-progress/arduino-test/counter/index.php from:
http://www.mysite.com/in-progress/arduino-test/counter/index.php

I mean the server path of that file which might be:
/www/html/in-progress/arduino-test/counter/index.php

You do mean the tail end of the url don't you, as it's visible on the web?


That doesn't mean it's available for the Arduino. Is that www.mysite.com a local or a remote site? Meaning, is it in your LAN or somewhere else in the Internet?

It's remote.


This is just a connection test, you haven't sent the request. After you have the connection send that line with hitting return twice at the end:

Code:
GET /in-progress/arduino-test/counter/index.php?count=237 HTTP/1.0

Post the result you get (you can change all IPs and domain names if your security imposes).

Here's the output, looks fine.

telnet mysite.com 80
Trying 62.81.51.152...
Connected to mysite.com.
Escape character is '^]'.
   
GET /in-progress/arduino-test/counter/index.php?count=237 HTTP/1.0

HTTP/1.1 200 OK
Date: Tue, 17 Jul 2012 12:40:48 GMT
Server: Apache/2.0.52 (Red Hat)
X-Powered-By: PHP/5.2.2
Content-Length: 0
Connection: close
Content-Type: text/html
Logged

Switzerland
Offline Offline
Faraday Member
**
Karma: 111
Posts: 5225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I guess your PC is in the same network as the Arduino is. Use WireShark to sniff that network, set the following filter:

Code:
host 192.168.1.68

(given the Arduino still has the same address). Then start the Arduino by resetting it or power it up. If you don't get output, there's probably still an error in the setup of the WiFi network. If you get packets, try to identify the HTTP connection, select one of the packets and select "Follow TCP stream" from the "Analyze" menu. Post the result if you don't get the failure reason yourself.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok, I couldn't filter the hosts, WireShark just kept telling me the syntax was wrong but I did a capture and located the following for UDP:

Code:
No.     Time           Source                Destination           Protocol Length Info
    345 5.138944000    192.168.1.68          255.255.255.255       UDP      152    Source port: cisco-sccp  Destination port: 55555

Frame 345: 152 bytes on wire (1216 bits), 152 bytes captured (1216 bits) on interface 0
    Interface id: 0
    WTAP_ENCAP: 1
    Arrival Time: Jul 17, 2012 18:01:55.419436000 BST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1342544515.419436000 seconds
    [Time delta from previous captured frame: 0.019490000 seconds]
    [Time delta from previous displayed frame: 0.019490000 seconds]
    [Time since reference or first frame: 5.138944000 seconds]
    Frame Number: 345
    Frame Length: 152 bytes (1216 bits)
    Capture Length: 152 bytes (1216 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ip:udp:data]
    [Coloring Rule Name: UDP]
    [Coloring Rule String: udp]
Ethernet II, Src: RovingNe_80:1f:f2 (00:06:66:80:1f:f2), Dst: Broadcast (ff:ff:ff:ff:ff:ff)
Internet Protocol Version 4, Src: 192.168.1.68 (192.168.1.68), Dst: 255.255.255.255 (255.255.255.255)
User Datagram Protocol, Src Port: cisco-sccp (2000), Dst Port: 55555 (55555)
Data (110 bytes)

0000  00 18 f6 93 6c cd 01 28 07 d0 00 00 01 42 0c 4a   ....l..(.....B.J
0010  0d 11 54 69 6d 65 20 4e 4f 54 20 53 45 54 00 00   ..Time NOT SET..
0020  57 69 46 6c 79 20 56 65 72 20 32 2e 33 32 2c 20   WiFly Ver 2.32,
0030  30 32 2d 31 33 2d 32 30 31 32 00 00 57 69 46 6c   02-13-2012..WiFl
0040  79 2d 45 5a 58 00 00 00 00 00 00 00 00 00 00 00   y-EZX...........
0050  00 00 00 00 00 00 00 00 00 00 00 00 b9 00 00 00   ................
0060  00 00 00 00 00 00 00 00 00 00 00 00 00 00         ..............

Follow UDP Stream of that was:

Code:
....l..(.....B.J
.Time NOT SET..WiFly Ver 2.32, 02-13-2012..WiFly-EZX.............................................l..(.....K.I
1Time NOT SET..WiFly Ver 2.32, 02-13-2012..WiFly-EZX.........................................

The TCP one is:

Code:
No.     Time           Source                Destination           Protocol Length Info
    396 5.855564000    62.81.51.152          192.168.1.68          TCP      54     http > 61394 [ACK] Seq=1 Ack=82 Win=5840 Len=0

Frame 396: 54 bytes on wire (432 bits), 54 bytes captured (432 bits) on interface 0
    Interface id: 0
    WTAP_ENCAP: 1
    Arrival Time: Jul 17, 2012 18:01:56.136056000 BST
    [Time shift for this packet: 0.000000000 seconds]
    Epoch Time: 1342544516.136056000 seconds
    [Time delta from previous captured frame: 0.000630000 seconds]
    [Time delta from previous displayed frame: 0.000630000 seconds]
    [Time since reference or first frame: 5.855564000 seconds]
    Frame Number: 396
    Frame Length: 54 bytes (432 bits)
    Capture Length: 54 bytes (432 bits)
    [Frame is marked: False]
    [Frame is ignored: False]
    [Protocols in frame: eth:ip:tcp]
    [Coloring Rule Name: HTTP]
    [Coloring Rule String: http || tcp.port == 80]
Ethernet II, Src: ThomsonT_93:6c:cc (00:18:f6:93:6c:cc), Dst: RovingNe_80:1f:f2 (00:06:66:80:1f:f2)
Internet Protocol Version 4, Src: 62.81.51.152 (62.81.51.152), Dst: 192.168.1.68 (192.168.1.68)
Transmission Control Protocol, Src Port: http (80), Dst Port: 61394 (61394), Seq: 1, Ack: 82, Len: 0

Follow TCP Stream of that was:

Code:
HTTP/1.1 200 OK
Date: Tue, 17 Jul 2012 17:01:56 GMT
Server: Apache/2.0.52 (Red Hat)
X-Powered-By: PHP/5.2.2
Content-Length: 0
Connection: close
Content-Type: text/html

There was also a HTTP stream:

Code:
No.     Time           Source                Destination           Protocol Length Info
    401 5.906948000    62.81.51.152          192.168.1.68          HTTP     231    HTTP/1.1 200 OK

Frame 401: 231 bytes on wire (1848 bits), 231 bytes captured (1848 bits) on interface 0
Ethernet II, Src: ThomsonT_93:6c:cc (00:18:f6:93:6c:cc), Dst: RovingNe_80:1f:f2 (00:06:66:80:1f:f2)
Internet Protocol Version 4, Src: 62.81.51.152 (62.81.51.152), Dst: 192.168.1.68 (192.168.1.68)
Transmission Control Protocol, Src Port: http (80), Dst Port: 61394 (61394), Seq: 1, Ack: 118, Len: 177
Hypertext Transfer Protocol

Both TCP and HTTP have my sites correct ip address.

I've gone back into CMD mode for the WiFly to check it's configuration and it looks fine:

Code:
show net

SSid=BTHomeHub-2BF6
Chan=1
Assoc=OK
Rate=12, 24Mb
Auth=OK
Mode=WEP
DHCP=OK,renew=64651
Boot=148
Time=FAIL
Links=1
<2.32>
« Last Edit: July 17, 2012, 12:27:42 pm by garrettlynch » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 39
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did a quick test this morning to test calling my php page from something other than the browser.  30 seconds to make in Max/MSP the equivalent of what I'm trying to do with the Arduino:

Code:
download http://www.mysite.com/in-progress/arduino-test/counter/index.php?count=2
|
jit.uldl

My computer is wirelessly on the same network as the WiFly and my txt counter on the remote server updates without any issues.  So the problem has to be with the Arduino or WiFly.
Logged

Pages: [1] 2   Go Up
Jump to: