New guy needs a little help, xport, serial comm.

I'm a bit new to the Arduino, I can read and understand the code, but I'm a little rusty on writing it.
I've been working on this for a week now, I've been searching everywhere but have not found any answers that help me. edit: I'M GOING CRAZY!!! :-?

>I'll explain what I'm attempting to do to give you a better idea of what I need.
If you don't want to read everything I typed, then just scroll to the bottom of my post.


Basic Project description:
I'm working on a project that needs to get data from a web page and store that data as a variable which I can call on later and display that on a set of 7-segment led displays. I am using a Duemilanove board with an adafruit xport shield and an xport direct (not a plus).

First thing's first:
I need the arduino to connect to a web server via the xport (telnet through port 80). The server uses some php code to get and process data from a MSSQL database. The only thing this page displays is 2 numeric characters and at times, 1 alpha character.

Therefore, using a simple "GET /whatever.php" command should work. (This works perfectly and only returns 2-3 characters when I telnet into the server from my pc.)

Once this command is issued, the server should send a couple numbers to the arduino. Eventually I will need those numbers to be displayed on a sign, but I'm not ready for that step.

I would rather just use the normal serial port (0,1) because I wont be using it for anything else in the final project and because my understanding is that it's more reliable than SoftSerial. Also, neither the AFSoftSerial, the AF_XPort, or the NewSoftSerial have worked so far (lack of documentation) so I'm down to my last resort of using the built-in standard serial pins. If any of these above mentioned libraries work, then I have no problem using them.

Here is what I have so far

#define rxPin 0
#define txPin 1
#define rsPin 4
int incomingtxt = 000;

void setup()
{
  Serial.begin(9600);
}
void loop()
{
  xportReset();
  httpRequest();
}
void xportReset()
{
  pinMode(rsPin, OUTPUT);
  digitalWrite(rsPin, LOW);
  delay(100);
  digitalWrite(rsPin, HIGH);
  delay(5000);
}
void httpRequest()
{
  Serial.println("GET /displayfiles/db.php");
  incomingtxt = Serial.read();
  Serial.println(incomingtxt, DEC);
}

I KNOW the code is wrong, trouble is, I don't know how to see what I'm receiving back other than to serial.print it. And I know that serial.read only reads 1 byte. So what I need is a way to read 2-3 characters. I have the xport set up to auto connect to an IP and port in order to slim down the code size.

XPort Setup:

Baudrate (9600) ? 
I/F Mode (4C) ? 
Flow (00) ? 
Port No (80) ? 
ConnectMode (05) ? 
Send '+++' in Modem Mode  (N) ? 
Show IP addr after 'RING'  (Y) ? 
Auto increment source port  (N) ? 
Remote IP Address : (172) .(030) .(231) .(068) 
Remote Port  (80) ? 
DisConnMode (00) ? 
FlushMode   (33) ? 
DisConnTime (00:00) ?:
SendChar 1  (00) ? 
SendChar 2  (00) ?

Bottom Line:
Any suggestions on how I can go about sending a "GET / " command and receive, store, and display a 2-3 character number?

THANK YOU!!!!! for any help you can give me.

Maybe you should do it the way shown in all the examples, and let the Arduino specify the IP address. If all you're going to do is read a value from a page and display a number, you're in no danger of running out of room.

I'll give that a shot, but I had it set up like that before and still got nothing usable back. I think that the problem I'm having is how do I read the serial data coming back in such a format that the number 32 would be displayed as 32 and not 51 50 (I'm not even getting that, just a -1 and sometimes random characters).

Something like

char rdata = 0;
char response[4] = {0,0,0,0};

int bytes_waiting = Serial.available();
for (int x = 0; x < bytes_waiting; x++)
{
rdata = Serial.read();
if (x <= 3) response[x] = rdata;
}

response should then have the full response, and any extra data is flushed from the incoming buffer. After that you're probably ready to send it to an external display (even if you don't think you are)

Cool, I'm recoding now, I'll work that into the code and let you know what happens. I appreciate all the help so far.

I have tried my best to understand and manipulate the examples found here Ethernet shield - Examples of use. Here's what I think the code should be, but it's not returning any data...

#include <avr/io.h>
#include <string.h>
#include <AFSoftSerial.h>
#include <AF_XPort.h>

#define HOSTNAME "mcwjisfiles"
#define IPADDR "172.30.231.68"  // twitter.com
#define PORT 80                   // HTTP
#define HTTPPATH "/displayfiles/db.php"      // the person we want to follow
char linebuffer[256];
#define XPORT_RXPIN 2
#define XPORT_TXPIN 3
#define XPORT_RESETPIN 4
#define XPORT_DTRPIN 5
#define XPORT_CTSPIN 6
#define XPORT_RTSPIN 7

AF_XPort xport = AF_XPort(XPORT_RXPIN, XPORT_TXPIN, XPORT_RESETPIN, XPORT_DTRPIN, XPORT_RTSPIN, XPORT_CTSPIN);
void setup()  {
  Serial.begin(57600);
  xport.begin(57600);
}
void loop()
{
  xport.reset();
  delay(5000);
  xport.connect(IPADDR, PORT);
  delay(1000);
  xport.print("GET ");
  xport.println(HTTPPATH);
  xport.serialavail_timeout(1000);
  xport.readline_timeout(linebuffer, 255, 3000);
  delay(1000);\
}

I'm just lost! I don't know what to learn, where to learn it, or what to read.

This is were I am at with this:

Arduino Code:

#include <NewSoftSerial.h>
#include <AF_XPort.h>
#include <stdio.h>

#define IPADDR "192.168.0.101"
#define HTTPPATH "/bit.txt"

//#define IPADDR "70.40.207.211"  //cnn.com
//#define HTTPPATH "/arduino/bit.txt"

#define PORT 80

#define XPORT_RESETPIN 2  //reset xport
#define XPORT_TXPIN  3    //serial tx
#define XPORT_RXPIN  4    //serial rx
#define XPORT_DTRPIN 5    //internet connection ended signal from xport
#define XPORT_CTSPIN 6    //used by arduino to stop xport overwhelming it with data
#define XPORT_RTSPIN 7    //signal for more data available... not used

char linebuffer[256]; // large buffer for storing data
   
AF_XPort xport = AF_XPort(XPORT_RXPIN, XPORT_TXPIN, XPORT_RESETPIN, XPORT_DTRPIN, XPORT_RTSPIN, XPORT_CTSPIN);

void setup()  
  {
    Serial.begin(19200);
    xport.begin(19200);
    xport.reset();
    delay(1000);
    Serial.println("QueueBot 5000"); 
    Serial.println("Finished Setup...");
  }

void loop()
{
fetchStuff();
}


char * fetchStuff(void) {
  uint8_t ret;
  char *found=0, *start=0, *end=0;
  

  ret = xport.reset();
  Serial.print("Ret: "); Serial.print(ret, HEX);
  switch (ret) {
   case  ERROR_TIMEDOUT: { 
      Serial.println("Timed out on reset!"); 
      return 0;
   }
   case ERROR_BADRESP:  { 
      Serial.println("Bad response on reset!");
      return 0;
   }
   case ERROR_NONE: { 
    Serial.println("Reset OK!");
    break;
   }
   default:
     Serial.println("Unknown error"); 
     return 0;
  }
  
  // time to connect...
 
  ret = xport.connect(IPADDR, PORT);
    switch (ret) {
   case  ERROR_TIMEDOUT: { 
      Serial.println("Timed out on connect"); 
      return 0;
   }
   case ERROR_BADRESP:  { 
      Serial.println("Failed to connect");
      return 0;
   }
   case ERROR_NONE: { 
     Serial.println("Connected..."); break;
   }
   default:
     Serial.println("Unknown error"); 
     return 0;
  }
  
  // send the HTTP command, ie "GET /username/"
  
  xport.print("GET "); xport.println(HTTPPATH);


    ret = xport.readline_timeout(linebuffer, 255, 3000); // 3s timeout
    // if we're using flow control, we can actually dump the line at the same time!
    Serial.print(linebuffer);

}

Xport Settings:

Baudrate (19200) ? 
I/F Mode (4C) ? 
Flow (02) ? 
Port No (10001) ? 
ConnectMode (D4) ? 
Send '+++' in Modem Mode  (Y) ? 
Show IP addr after 'RING'  (Y) ? 
Auto increment source port  (N) ? 
Remote IP Address : (000) .(000) .(000) .(000) 
Remote Port  (0) ? 
DisConnMode (00) ? 
FlushMode   (33) ? 
DisConnTime (00:00) ?:
SendChar 1  (00) ? 
SendChar 2  (00) ?

Serial Output / Error:

QueueBot 5000
Finished Setup...
Ret: 0Reset OK!
Connected...
<data>Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 0Reset OK!
Connected...
<data>Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 3Bad response on reset!
Ret: 0Reset OK!
Connected...
<data>Ret: 3Bad response on reset!
Ret: 3Bad response on reset!

Any ideas?

Thanks!

Update, I am pulling values!!

New Code

#include <NewSoftSerial.h>
#include <AF_XPort.h>
#include <stdio.h>

#define IPADDR "192.168.0.101"
#define HTTPPATH "/bit.txt"

//#define IPADDR "70.40.207.211"  //cnn.com
//#define HTTPPATH "/arduino/bit.txt"

#define PORT 80

#define XPORT_RESETPIN 2  //reset xport
#define XPORT_TXPIN  3    //serial tx
#define XPORT_RXPIN  4    //serial rx
#define XPORT_DTRPIN 5    //internet connection ended signal from xport
#define XPORT_CTSPIN 6    //used by arduino to stop xport overwhelming it with data
#define XPORT_RTSPIN 7    //signal for more data available... not used

char linebuffer[256]; // large buffer for storing data
   
AF_XPort xport = AF_XPort(XPORT_RXPIN, XPORT_TXPIN, XPORT_RESETPIN, XPORT_DTRPIN, XPORT_RTSPIN, XPORT_CTSPIN);

void setup()  
  {
    Serial.begin(19200);
    xport.begin(19200);
    xport.reset();
    delay(1000);
    Serial.println("QueueBot 5000"); 
    Serial.println("Finished Setup...");
  }

void loop()
{
fetchStuff();
}


char * fetchStuff() {
  uint8_t ret;

  ret = xport.reset();
  Serial.print("Ret: "); Serial.println(ret, HEX);
  switch (ret) {
   case  ERROR_TIMEDOUT: { 
      Serial.println("Timed out on reset!"); 
      return 0;
   }
   case ERROR_BADRESP:  { 
      Serial.println("Bad response on reset!");
      return 0;
   }
   case ERROR_NONE: { 
    Serial.println("Reset OK!");
    break;
   }
   default:
     Serial.println("Unknown error"); 
     return 0;
  }
  
  // time to connect...
 
  ret = xport.connect(IPADDR, PORT);
    switch (ret) {
   case  ERROR_TIMEDOUT: { 
      Serial.println("Timed out on connect"); 
      return 0;
   }
   case ERROR_BADRESP:  { 
      Serial.println("Failed to connect");
      return 0;
   }
   case ERROR_NONE: { 
     Serial.println("Connected..."); break;
   }
   default:
     Serial.println("Unknown error"); 
     return 0;
  }
  
  // send the HTTP command
 
    xport.print("GET "); xport.println(HTTPPATH);

    ret = xport.readline_timeout(linebuffer, 255, 3000); // 3s timeout
    // if we're using flow control, we can actually dump the line at the same time!
    // Serial.print(linebuffer);
 while(ret!=0)
  {
   Serial.println(linebuffer);  
   ret=xport.readline_timeout(linebuffer,255,1000);
  }
 //Serial.print("Readline returned: ");Serial.println(ret,HEX);
  xport.flush(1000);
}

New Serial Output

QueueBot 5000
Finished Setup...
Ret: 0
Reset OK!
Connected...
<data>
01000000
</data>
D
Ret: 0
Reset OK!
Failed to connect
Ret: 0
Reset OK!
Failed to connect
Ret: 0
Reset OK!
Failed to connect
Ret: 0
Reset OK!
Connected...
<data>
01000000
</data>
D
Ret: 0
Reset OK!
Failed to connect
Ret: 0
Reset OK!

bit.txt

<data>
01000000
</data>

Notice how every other fetch it fails to connect, any insight into this behavior?

krumpt, GREAT JOB!!! But I can't get your code to work for me. I get nothing but errors all over the place when I try to compile it. YES! I have the correct libraries installed.

I'm not sure I understand why most people use softserial. Is there any disadvantage to using built in serial? It seems to me that the code would be much easier to manage.

All that I need the code to do is just reset the xport and then send a get and then display what is received as plain text. The xport is configured to connect automatically. This is so much easier IMO. But I'm still not quite sure how to display the return data.

Can you post your code?

//                                                           xPort Setup
//       Here are the settings for the xPort, if you will always connect to the same server, then just program the xPort to connect
//    rather than including it in your code. I found it much easier to do it this way and if I ever need to change the IP address
//    of the server, all I'll have to do is just open up the config utility for the xPort and set it up no matter where it is on
//    the network.

//    * * * * * * * * * * * * * * * * * * * * * * * * * * *
//    Baudrate (9600)
//    I/F Mode (4C)
//    Flow (00)
//    Port No (10001)
//    ConnectMode (C5)
//    Send '+++' in Modem Mode  (Y)
//    Show IP addr after 'RING'  (Y)
//    Auto increment source port  (N
//    Remote IP Address : (172) .(030) .(231) .(068)
//    Remote Port  (80)
//    DisConnMode (00)
//    FlushMode   (33)
//    DisConnTime (00:00)
//    SendChar 1  (00)      
//    SendChar 2  (00)
//    * * * * * * * * * * * * * * * * * * * * * * * * * * *

#include <SoftwareSerial.h>

#define rxPin 2                                                // define the receive pin on the arduino (this pin should connect to the TX pin of the xPort)
#define txPin 3                                                // define the transmit pin on the arduino (this pin should connect to the RX pin of the xPort)
#define rstPin 4                                               // define the reset pin on the arduino (this pin should connect to the RST pin of the xPort)
#define GETCommand ("GET /displayfiles/da.php")                //This is the page that we want to connect to on the server (the server is defined in the xPort setup)

SoftwareSerial SoftxPort = SoftwareSerial(rxPin, txPin);       //define out softwareserial port as SoftxPort, it will use rxPin and txPin
byte pinState = 0;

void setup()   {
  
  pinMode(rxPin, INPUT);                                       //set the receive pin as an input
  pinMode(txPin, OUTPUT);                                      //set the transmit pin as an output
  pinMode(rstPin, OUTPUT);                                     //set the reset pin as an output
  
  SoftxPort.begin(9600);                                       //start the softserial port at 9600
  Serial.begin(9600);                                          //start the serial port at 9600
}  

void loop()   {
  
digitalWrite(rstPin, LOW);                                     //ground the reset of the xPort causing it to reset
delay(100);                                                    //wait for 100ms before releasing the reset pin
digitalWrite(rstPin, HIGH);                                    //release the reset pin from ground

delay(10000);                                                  //wait for 10 seconds before going any further, this allows the xPort time to reboot, and connect to the server

SoftxPort.print(GETCommand);                                   //send the GET command specified in the begining of the sketch
SoftxPort.print("\n");                                         //send a carriage return
SoftxPort.print("\n");                                         //send a carriage return (you need to send two carriage returns to actually send the command)

char rdata = 0;                                                //our variable, rdata should equal zero for now
char response[2] = {0,0};                                      //we want this variable to have two digits since the number returned from the server could be a two digit number


for (int x = 0; x < 2; x++)
 {
 rdata = SoftxPort.read();                                     //specify that rdata's value should be what the SoftxPort reads; what the xPort receives from the server
 response[x] = rdata;                                          //specify that response should equal the same as rdata
 }

for (int x = 0; x < 2; x++)                                    //this will just show us what we received
 {                                                             //we don't need this but it's a good way to make sure that everything is working
 Serial.print(response[x]);      
  }
  
Serial.println();

delay(5000);                                                   //wait 5 seconds before resetting the xPort

}

Works just fine, I was hung up on some of the code, but I finally got it. ;D

What hosting company are you guys using?

I've been trying to get my XPort Direct + to work for the past couple months. I've read through this and many other threads on these boards, but never seem to be taking steps forward.

I was using goDaddy.com, but gave up on them due to all the comments I've read about their firewalls. I also tried with Modwest.com, but haven't gotten it to work either.

My questions are:

-- Can I connect to a shared hosting account?

-- For anyone was has successfully connected their Arduino to a web service hosted on your own domain, what hosting company do you use?

Many thanks,
Wayne

Hi Wayne. We didn't use a hosting company, everything was on a local network including the xPort. It's been a while since I've messed with the settings but the problem could be that (and I'm not certain) your DNS settings are incorrect, OR, from what I see, there is no place to enter any DNS settings. So try going with a direct IP address.

Could you give me a little more detail on what you're attempting to do? If it's simple enough, it may be easier to run the server on your own, you can use any computer, you just need apache, and possibly some form of sql server (MySQL is very popular) then forward port 80 (or whatever protocol you're using) to the computer running the server, and access it by entering your cable (or other internet connection) modem IP address (google "what's my ip"). This should also be much cheaper.

If you absolutly need to have your site hosted, please PM me, I may be able to help you at least test it, though, I wont be able to provide long term hosting. :wink: