xport php link zoo animals

Hi… We have been working on an automated system that feeds animals… We’re at the last stage of getting the application up where we connect our devices via ethernet. Our mysql database and php pages have been written and they work fine.

Our problem is getting the xport to post a php page - the result is a signal to feed various animals. When we run the arduino program it looks like it connects, but the page doesn’t seem to be posted - if we submit the php page on a url, the post takes place - so we know it works. We have tested the xport using telnet and echoed responses back and forth…

So we are stumped. I’m including the program and wiring instructions and are hoping someone can help figure out the problem. We appreciate any help.


hardware setup


from xport pins to arduino:
rx > tx
tx > rx

other xport pins
3.3v > 5v
gnd > gnd

arduino pins
13 - led
14 - pot

*/

// define variables:
int adcVar = 0;
int inByte = 0;
int tcpPin = 13;
int connected = 0;
long measurementPeriod = 30000; //i.e.: ~30 seconds between measurements

void setup()
{
// start serial port at 9600 bps:
Serial.begin(9600);

// pause to let Xport boot up:
delay(2000);
}

void loop()
{
blinkie(7, 100);

// if you’re connected to the server, then
// make a HTTP call. If not, then connect
// to the server:

if (connected == 1)
{
// read sensors, convert to bytes:
adcVar = analogRead(0);
Serial.print(“connected”);

// submit page
http_request();

} else {

// attempt to connect to the server:
xport_connect();

}

digitalWrite(tcpPin, connected);
// pause so we’re not overwhelming the server:

delay(measurementPeriod/2);
//Serial.print(“After 3 second delay in main loop”);
}

void xport_connect()
{
// turn off LED to indicate HTTP GET is in progress:
digitalWrite(tcpPin, LOW);

//if (Serial.available() > 0) {
// get incoming byte:
inByte = Serial.read();
//Serial.print(inByte);

// wait for a “C” byte to come back:
while (inByte != 67)
{
//Serial.print(“Waiting for xport to send back C”);
Serial.print(“Cxx.xx.xx.xx/80”); // host server ip address
Serial.print(10, BYTE);
delay(100); // required delay, otherwise never gets to C
inByte = Serial.read();
}

connected = 1;

}

void http_request()
{
delay(200);
Serial.print(“GET /Feed.php?sensorValue=”);
Serial.print(adcVar,DEC);
Serial.print(" HTTP/1.1");
Serial.print(10, BYTE);
Serial.print(“HOST: xx.xx.xx.xx”); // host server ip address
Serial.print(10, BYTE);

delay(200);
//we should really be waiting for the return ‘0’ here
//from the script, but it just never seemed to come,
//hanging the program in a while loop like the one above
//so instead we just delay until the Xport lets go of it’s connection
//and then we try again

delay(measurementPeriod/2);
connected = 0;
}

void blinkie(int number, int speed)
{
int i;
for (i=0; i<number; i++)
{
digitalWrite(tcpPin, HIGH);
delay(speed);
digitalWrite(tcpPin, LOW);
delay(speed);

}
}

Some questions. Which Arduino are you using? The 3V3 connection on the Xport to the 5V pin on the Arduino might not be a good idea. Why not connect it to the 3V3 pin on the Arduino (assuming it has one).

Have you looked at the web logs on the server? Do they show that a GET request was made from the Xport?

Is the server running any kind of firewall software?

Have you tried accessing the URL from a machine on a different network?

Are the Serial.print debug statements interfering with the Serial.print statements to the Xport?

Maybe I'm missing something. You set connected to 0 when the sketch begins. Then, in loop, if connected is 1 (it's not), you make a GET request. Otherwise (as is true in your case), you call xport_connect. In that function, you begin reading from the Xport.

As I see it, there is no way that data can possibly be available to read.

It looks like your login in loop is faulty.

By the way, in the future, please use the # button to post code.

Hi... Sorry - I'm new at this - I'll remember to use the # next time.

I'm using a serial board that allows me to step down to 3.3v - so I changed the voltages to match...

I can't access the server logs - but I think the problem is on my end. Which Serial print do you think is the debug one?

P.S. I commented out the Serial.print ("connected")....

Why can't you access the server logs? You installed the php scripts on the server. The logs typically have global read permission.

Not that it matters, because I don't think your code is ever making a GET request.

Hi all… I reworked the code - based on some strange results. If it helps, the goal is to for this program to run a php program every 10 seconds or so… The php program will do a database insert.

I noticed that if the program will occasionally do the insert - so I know it is communicating… But I think the problem is that when a php page is run, the serial buffer will fill up with html header information.

I ran into this will a Processing Program… One way around it was to not read the html header return information.

Is there a way to restrict what is being loaded/emptied from the serial buffer?

Here is my code below…

I hope someone can help…

// define variables:
int adcVar = 0;
int inByte = 0;
int tcpPin = 13; 
 
char   val2;            // 
char   returncode[5];   // array to hold returned serial data info
  
// *******************************************************************************************************
void setup()
{
  // start serial port at 9600 bps:
  Serial.begin(9600); 
    
} 
// *******************************************************************************************************
void loop()
{
    blinkie(5, 100);   // indicate going into the serial read routine
 
    if (Serial.available() > 0) {      // check if there is any serial info hanging out
      for (int kj=0; kj<2; kj++){  
        
        val2 = Serial.read();          // read in the next value 
        returncode[kj] = val2;         // add the digit            
         
      }// end of for
      
       if (returncode[0] == 'C'){    
            http_request();   
       }// end of if
        
      finishUp();   // clear array
    }   
      
   
   // pause to let Xport boot up:
   delay(2000);
   
   xport_connect();  // reconnect to xport
   
   // reset device????       
   delay(10000);  // give pause before starting new serial read 
           
}  
// *******************************************************************************************************
void xport_connect()
{ 
        //Serial.print("Waiting for xport to send back C");
        Serial.print("Cxxx.xxx.xxx.xxx/80\n");    
        delay(1000); // give it some time to get back response
} 
// *******************************************************************************************************
void http_request()
{ 
    //    delay(2000);
    Serial.print("GET /Arduino/FeedAnimals.php HTTP/1.0\n"); 
    //Serial.print(adcVar,DEC); 
    //ial.print(" HTTP/1.1\n"); 
    Serial.print("HOST:xxx.net\n\n");  
    delay(100); 
 
} 
// *******************************************************************************************************
void finishUp(){
  
       //empty out array   
       for (int jj=0; jj<5; jj++){ 
        returncode[jj] = ' ';         // add the digit  
       }     
   
}  
// *******************************************************************************************************
void blinkie(int number, int speed)
{
  int i;
  for (i=0; i<number; i++)
  {
    digitalWrite(tcpPin, HIGH);
    delay(speed);
    digitalWrite(tcpPin, LOW);
    delay(speed);

  }
}

Hi all again...

Is it possible to define the serial string being returned by the http_request routine? I don't need the html header - I just need a 1 or 2 character response, e.g., OK...

Hi again...

For those who have gotten xport to work with Arduino, do you need to reset the xport after each request? In my case, that would be the http_request?

If so, what entails a reset... Do I set up a pin on the Arduino to the xport reset pin and after each http_request toggle the output pin on the arduino from high to low ?