Verify data is successfully POSTed in Ethernet client

I am using a Wiznet 5200 breakout board, and notice that it is quite unreliable, needing to be reset every so often. I am trying to debug the issue, but it may just be easier to prepare for it.

I would like to POST data to a PHP page (which then inserts it into MySQL), and then verify that this has happened with code. If it doesn’t, the Arduino will reset the module and try again.

Using the examples, I read data coming back from the server, but I am lost as to how to include a message that the Arduino could listen for telling it that the info was successfully transmitted.

Would I write this in the PHP page? How would I tell the Arduino to listen for this specific message which will be included with a bunch of other ‘noise’?

Thanks.

I would like to POST data to a PHP page

As opposed to a far simpler GET? Why?

but I am lost as to how to include a message that the Arduino could listen for telling it that the info was successfully transmitted.

echo "Hey dude, that worked";

How would I tell the Arduino to listen for this specific message which will be included with a bunch of other 'noise'?

echo "Non-noise: Hey dude, that worked";

Then, parse the data for the phrase "Non-noise:".

From what I read, the POST is more reliable than the GET.

How do I parse for “Hey dude, that worked” in the response?

From what I read, the POST is more reliable than the GET.

I don't believe that. There are reasons for using POST, but reliability is not one of them.

How do I parse for "Hey dude, that worked" in the response?

That would depend on how you collect and store the response from the server.

I am using the following code:

    unsigned long startMillis = millis();
    unsigned long endMillis = startMillis + timeout;
    while(client.connected() && (millis() < endMillis)) {
    while(client.available()) {
      char ch = client.read();
      Serial.write(ch);
    }
    wdt_reset();
    }
    Serial.println();
    client.stop();
    while(client.available()) {
      char ch = client.read();
      Serial.write(ch);
    }

It will be impossible to parse data you have not saved.

Should I save the entire response as one long string and search for the pattern? Wouldn't that eat up RAM?

What would a better way be?

What would a better way be?

Maybe below,

http://playground.arduino.cc/Code/TextFinder

I'll try that. Thanks!

Or, you might like to check out a neat little helper that Nick Gammon has put together.
I think it will do just what you are wanting. http://Tiny web server for Arduino or similar


Paul

Thanks for that link. Though in the examples, the Arduino is the server. In this case, my server is a LAMP that will send back a "got it" message that the arduino will listen for.

Basic client test code that captures what is sent from the server.

//zoomkat 11-04-13
//simple client test
//for use with IDE 1.0.1
//with DNS, DHCP, and Host
//open serial monitor and send an e to test client GET
//for use with W5100 based ethernet shields
//remove SD card if inserted
//data from myIP server captured in readString 

#include <SPI.h>
#include <Ethernet.h>
String readString;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address

char serverName[] = "checkip.dyndns.com"; // myIP server test web page server
EthernetClient client;

//////////////////////

void setup(){

  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }

  Serial.begin(9600); 
  Serial.println("client readString test 11/04/13"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
  Serial.println();
}

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
  {
    byte inChar; // sets inChar as a byte
    inChar = Serial.read(); //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    Serial.println("connected");
    client.println("GET / HTTP/1.1"); //download text
    client.println("Host: checkip.dyndns.com");
    client.println("Connection: close");  //close 1.1 persistent connection  
    client.println(); //end of get request
  } 
  else {
    Serial.println("connection failed"); //error message if no client connect
    Serial.println();
  }

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c = client.read(); //gets byte from ethernet buffer
    readString += c; //places captured byte in readString
  }

  //Serial.println();
  client.stop(); //stop client
  Serial.println("client disconnected.");
  Serial.println("Data from server captured in readString:");
  Serial.println();
  Serial.print(readString); //prints readString to serial monitor 
  Serial.println();  
  Serial.println();
  Serial.println("End of readString");
  Serial.println("==================");
  Serial.println();
  readString=""; //clear readString variable

}