Problem with internet parser

Hello,

I am trying to make a program that can print from my website. (http://moomenu.com/api.php?unit=123)
However, there are few problems.

  1. How can I avoid printing HTML headers? I looked some comments on the forum that I should use client.find("\r\n\r\n"), but does not have enough details. Can anybody enlighten me?

  2. Somehow, I am getting junk code right before and after what should print out. (1c and 0) What causes this problem?

Thank you so much to take your time reading, and I appreciate it. Have a good Memorial day.

Result:

connecting...
HTTP/1.1 200 OK
Date: Sat, 26 May 2012 06:36:53 GMT
Server: Apache
Vary: Accept-Encoding
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8

1c
123: 2012-05-26 12:36:53 AM

0


disconnecting.

Source code:

#include <SPI.h>
#include <Ethernet.h>
#include <Adafruit_Thermal.h>
#include <SoftwareSerial.h>



int printer_RX_Pin = 5;  // this is the green wire
int printer_TX_Pin = 6;  // this is the yellow wire

Adafruit_Thermal printer(printer_RX_Pin, printer_TX_Pin);





// assign a MAC address for the ethernet controller.
// fill in your address here:
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
IPAddress ip(10,0,1,1);
EthernetClient client;
char server[] = "www.moomenu.com";

unsigned long lastConnectionTime = 0;          // last time you connected to the server, in milliseconds
boolean lastConnected = false;                 // state of the connection last time through the main loop
const unsigned long postingInterval = 10*1000;  // delay between updates, in milliseconds

void setup() {
  // start serial port:
  Serial.begin(57600);

/*
  printer.begin();
    
  printer.inverseOn();
  printer.setSize('L');
  printer.justify('C'); 
  printer.println("  TOGO ORDER  ");
  printer.justify('L'); 
  printer.setSize('S');
  printer.inverseOff();
*/

  // give the ethernet module time to boot up:
  delay(1000);
  // start the Ethernet connection using a fixed IP address and DNS server:
  Ethernet.begin(mac);
  

  // print the Ethernet board/shield's IP address:
  Serial.print("\n\nMooPrinter IP ADDR: ");
  Serial.println(Ethernet.localIP());
}

void loop() {
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
      char c = client.read();
      Serial.print(c);
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }

  // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    httpRequest();
  }
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
}

// this method makes a HTTP connection to the server:
void httpRequest() {
  // if there's a successful connection:
  if (client.connect(server, 80)) {

      Serial.println("connecting...");
      // send the HTTP PUT request:
      client.println("GET /api.php?unit=123 HTTP/1.1");
      client.println("Host: www.moomenu.com");
      client.println("User-Agent: moomenu-ethernet");
      client.println("Connection: close");
      client.println();
  
      // note the time that the connection was made:
      lastConnectionTime = millis();

  } else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    Serial.println("disconnecting.");
    client.stop();
  }
}

The response from the server contains some header lines. Each line ends with a carriage return and line feed (\r\n). After the header(s), there is a blank line, ending with a carriage return and line feed (\r\n). The data that the server sent follows the \r\n\r\n. That is, after the last header line and the blank line.

The "garbage" is being sent by the server. It is up to you to parse the data, and pick out the wheat from the chaff, or to fix the server so it sends only the stuff you want to get.

Some client test code from a previous IDE that counts line feeds to determine the line of data to capture. Then the desired data is parsed from the captured line and displayed in the serial monitor. You might try capturing the data on line 10 of your returned data returned from the server to see if that is what you want.

//zoomkat 12-22-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor to see what the arduino receives
//push the shield reset button to run client again

#include <SPI.h>
#include <Ethernet.h>
String readString, readString1;
int x=0;
char lf=10;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 };
byte server[] = { 140, 90, 238, 27 }; // NOAA

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  Serial.println("starting simple arduino client test");
  Serial.println();
  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /data/5day2/44013_5day.txt HTTP/1.0");
    client.println();
  } else {
    Serial.println("connection failed");
  }
}

void loop()
{
  if (client.available()) {
    char c = client.read();
    //Serial.print(c);  // uncomment to see raw feed
    if (c==lf) x=(x+1);
    if (x==14) readString += c;
    //readString += c;
  }

  if (!client.connected()) {
     client.stop();

    Serial.println("Current data row:" );
    Serial.print(readString);
    Serial.println();
    readString1 = (readString.substring(41,43));
    Serial.println();
    Serial.print("DPD sec: ");
    Serial.println(readString1);
    Serial.println("done");

    for(;;);

    }
 }